From 4b76e4e03120ff7d57ef669858f831546a4403d1 Mon Sep 17 00:00:00 2001 From: Martin Grandrath Date: Thu, 27 Nov 2014 21:16:48 +0100 Subject: [PATCH 1/3] Get rid of timeout in smoke test for font loading --- src/_phantomjs.js | 45 ++++++++++++++++++++++++++++++------------- src/client/index.html | 20 +++++-------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/_phantomjs.js b/src/_phantomjs.js index eee56bfd7..1609255ee 100644 --- a/src/_phantomjs.js +++ b/src/_phantomjs.js @@ -14,6 +14,34 @@ console.log("CONSOLE: " + message); }; + page.onInitialized = function () { + page.evaluate(function () { + var fonts = window.__loadedFonts = []; + + window.__fontactive = function (family, variant) { + fonts.push({ + family: family, + variant: variant + }); + }; + + window.__done = function () { + window.callPhantom(fonts); + }; + }); + }; + + page.onCallback = function (arg) { + var error = page.evaluate(checkFonts); + if (error) { + console.log("error", error); + phantom.exit(1); + } + else { + phantom.exit(0); + } + }; + page.open("http://localhost:5000", function(success) { try { var error = page.evaluate(inBrowser); @@ -21,16 +49,6 @@ console.log(error); phantom.exit(1); } - else { - setTimeout(function() { - error = page.evaluate(checkFonts); - if (error) { - console.log("error", error); - phantom.exit(1); - } - phantom.exit(0); - }, 10000); - } } catch(err) { console.log("Exception in PhantomJS code", err); @@ -42,17 +60,18 @@ try { checkFont("alwyn-new-rounded-web", "n3"); checkFont("alwyn-new-rounded-web", "n4"); - checkFont("alwyn-new-rounded-web", "n7"); + checkFont("alwyn-new-rounded-web", "n6"); } catch (err) { return "checkFonts() failed: " + err.stack; } function checkFont(family, variant) { - var hasFont = window.wwp_loadedFonts.some(function(loadedFont) { + var hasFont = window.__loadedFonts.some(function(loadedFont) { return (loadedFont.family === family) && (loadedFont.variant === variant); }); if (!hasFont) throw new Error("font not loaded: " + family + " " + variant); + else console.log("font loaded: " + family + " " + variant); } } @@ -77,4 +96,4 @@ } } -}()); \ No newline at end of file +}()); diff --git a/src/client/index.html b/src/client/index.html index 4b40241ac..8c9d544d6 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -11,23 +11,13 @@ - \ No newline at end of file + From 782a485facb05aac35c8fc5d7fad320ab0b84b9b Mon Sep 17 00:00:00 2001 From: Martin Grandrath Date: Thu, 27 Nov 2014 21:21:46 +0100 Subject: [PATCH 2/3] Remove global variable '__loadedFonts' --- src/_phantomjs.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/_phantomjs.js b/src/_phantomjs.js index 1609255ee..5a220d4bd 100644 --- a/src/_phantomjs.js +++ b/src/_phantomjs.js @@ -16,7 +16,7 @@ page.onInitialized = function () { page.evaluate(function () { - var fonts = window.__loadedFonts = []; + var fonts = []; window.__fontactive = function (family, variant) { fonts.push({ @@ -31,8 +31,8 @@ }); }; - page.onCallback = function (arg) { - var error = page.evaluate(checkFonts); + page.onCallback = function (loadedFonts) { + var error = page.evaluate(checkFonts, loadedFonts); if (error) { console.log("error", error); phantom.exit(1); @@ -56,18 +56,18 @@ } }); - function checkFonts() { + function checkFonts(loadedFonts) { try { - checkFont("alwyn-new-rounded-web", "n3"); - checkFont("alwyn-new-rounded-web", "n4"); - checkFont("alwyn-new-rounded-web", "n6"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n3"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n4"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n6"); } catch (err) { return "checkFonts() failed: " + err.stack; } - function checkFont(family, variant) { - var hasFont = window.__loadedFonts.some(function(loadedFont) { + function checkFont(loadedFonts, family, variant) { + var hasFont = loadedFonts.some(function(loadedFont) { return (loadedFont.family === family) && (loadedFont.variant === variant); }); if (!hasFont) throw new Error("font not loaded: " + family + " " + variant); From 97a460853d74198e05d9e29ca0d148e1bfea37d1 Mon Sep 17 00:00:00 2001 From: Martin Grandrath Date: Sun, 7 Dec 2014 11:28:57 +0100 Subject: [PATCH 3/3] Less invasive code for testing typekit integration --- src/_phantomjs.js | 5 +++-- src/client/index.html | 15 ++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/_phantomjs.js b/src/_phantomjs.js index 5a220d4bd..d9fb90366 100644 --- a/src/_phantomjs.js +++ b/src/_phantomjs.js @@ -16,16 +16,17 @@ page.onInitialized = function () { page.evaluate(function () { + var typekitConfig = window.__typekitConfig = {}; var fonts = []; - window.__fontactive = function (family, variant) { + typekitConfig.fontactive = function fontactive(family, variant) { fonts.push({ family: family, variant: variant }); }; - window.__done = function () { + typekitConfig.active = typekitConfig.inactive = function done() { window.callPhantom(fonts); }; }); diff --git a/src/client/index.html b/src/client/index.html index 8c9d544d6..37a089131 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -11,17 +11,14 @@