Permalink
Browse files

Added getConfigWindow and getProtocol to domHelper

Can now distinguish between window fonts will load
in and window webfontloaded loaded in. Having two
windows meant that determining the protocol was
no longer a oneliner, so moved into a function.
  • Loading branch information...
1 parent ade5e25 commit 1e7293b145a0391948b1af8516b01c037bdef8d9 @ryanwolf ryanwolf committed Dec 4, 2012
@@ -14,6 +14,9 @@ AscenderScriptTest.prototype.testLoadAndFamilyVariations = function(){
createCssLink: function(cssLink) {
css = cssLink;
return '<link href="' + css + '" type="text/css" />';
+ },
+ getProtocol: function() {
+ return 'http:';
}
};
@@ -1,7 +1,7 @@
var DomHelperTest = TestCase('DomHelperTest');
DomHelperTest.prototype.setUp = function() {
- this.domHelper_ = new webfont.DomHelper(document);
+ this.domHelper_ = new webfont.DomHelper(window, window);
};
DomHelperTest.prototype.testCreateElementNoAttr = function() {
@@ -106,3 +106,38 @@ DomHelperTest.prototype.testHasSupportForStyle = function() {
this.domHelper_.supportForStyle_ = true;
assertTrue(this.domHelper_.hasSupportForStyle_());
};
+
+DomHelperTest.prototype.testGetProtocol = function() {
+ var fakeWindow = {
+ location: {
+ protocol: 'https:'
+ }
+ };
+ var domHelper = new webfont.DomHelper(fakeWindow, fakeWindow);
+ assertEquals('https:', domHelper.getProtocol());
+};
+
+DomHelperTest.prototype.testGetProtocolHttpDefault = function() {
+ var fakeWindow = {
+ location: {
+ protocol: 'file:'
+ }
+ };
+ var domHelper = new webfont.DomHelper(fakeWindow, fakeWindow);
+ assertEquals('http:', domHelper.getProtocol());
+};
+
+DomHelperTest.prototype.testGetProtocolIframeFallback = function() {
+ var fakeWindow = {
+ location: {
+ protocol: 'about:'
+ }
+ };
+ var fakeConfigWindow = {
+ location: {
+ protocol: 'https:'
+ }
+ };
+ var domHelper = new webfont.DomHelper(fakeWindow, fakeConfigWindow);
+ assertEquals('https:', domHelper.getProtocol());
+};
@@ -41,17 +41,11 @@ FontdeckScriptTest.prototype.testSupportAndLoadLifecycle = function() {
]
};
var insert = '';
- var src = '';
+ // No hostname to verify fallback behavior for empty iframe.
var global = {
- location: {
- protocol: 'https:'
- },
- document: {
- location: {
- hostname: 'test-host-name'
- }
- }
+ location: {}
};
+ var src = '';
var fakeDomHelper = {
insertInto: function(tag, e) {
insert = tag;
@@ -61,6 +55,16 @@ FontdeckScriptTest.prototype.testSupportAndLoadLifecycle = function() {
},
getWindow: function() {
return global;
+ },
+ getConfigWindow: function() {
+ return {
+ location: {
+ hostname: 'test-host-name'
+ }
+ };
+ },
+ getProtocol: function() {
+ return 'https:';
}
};
var fontdeck = new webfont.FontdeckScript(fakeDomHelper, configuration);
@@ -2,7 +2,7 @@ var FontApiUrlBuilderTest = TestCase('FontApiUrlBuilderTest');
FontApiUrlBuilderTest.prototype.testThrowsExceptionIfNoFontFamilies =
function() {
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder("http://moo");
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder("http://moo", "http:");
try {
fontApiUrlBuilder.build();
@@ -13,14 +13,14 @@ FontApiUrlBuilderTest.prototype.testThrowsExceptionIfNoFontFamilies =
};
FontApiUrlBuilderTest.prototype.testBuildProperUrl = function() {
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder("http://moo");
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder("http://moo", "http:");
fontApiUrlBuilder.setFontFamilies([ 'Font1', 'Font2' ]);
assertEquals('http://moo?family=Font1%7CFont2', fontApiUrlBuilder.build());
};
FontApiUrlBuilderTest.prototype.testBuildProperDefaultUrl = function() {
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder();
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(undefined, "http:");
fontApiUrlBuilder.setFontFamilies([ 'Font1', 'Font2' ]);
assertEquals("http:" + webfont.FontApiUrlBuilder.DEFAULT_API_URL +
@@ -29,7 +29,7 @@ FontApiUrlBuilderTest.prototype.testBuildProperDefaultUrl = function() {
FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsets = function() {
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder();
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(undefined, "http:");
fontApiUrlBuilder.setFontFamilies([ 'Font1:bold:greek,cyrillic',
'Font2:italic', 'Font3' ]);
@@ -40,7 +40,7 @@ FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsets = function() {
FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsetsNoVariations =
function() {
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder();
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(undefined, "http:");
fontApiUrlBuilder.setFontFamilies([ 'Font1:bold,italic:greek,cyrillic',
'Font2:italic', 'Font3::latin' ]);
@@ -9,6 +9,9 @@ GoogleFontApiTest.prototype.testCallOnReadyWithFontFamilyLoading = function() {
},
createCssLink: function(csslink) {
link = csslink;
+ },
+ getProtocol: function() {
+ return 'http:';
}
};
var userAgent = new webfont.UserAgent("Test", "1.0", true);
@@ -53,6 +56,9 @@ GoogleFontApiTest.prototype.testCallOnReadyWithFontFamilyLoadingApiUrlChanged =
},
createCssLink: function(csslink) {
link = csslink;
+ },
+ getProtocol: function() {
+ return 'http:';
}
};
var userAgent = new webfont.UserAgent("Test", "1.0", true);
@@ -95,6 +101,9 @@ GoogleFontApiTest.prototype.testSpacesReplacedByPlus = function() {
},
createCssLink: function(csslink) {
link = csslink;
+ },
+ getProtocol: function() {
+ return 'http:';
}
};
var userAgent = new webfont.UserAgent("Test", "1.0", true);
@@ -137,6 +146,9 @@ GoogleFontApiTest.prototype.testLoadWithVariations = function() {
},
createCssLink: function(csslink) {
link = csslink;
+ },
+ getProtocol: function() {
+ return 'http:';
}
};
var userAgent = new webfont.UserAgent("Test", "1.0", true);
@@ -1,49 +1,7 @@
var MonotypeScriptTest = TestCase('MonotypeScriptTest');
-MonotypeScriptTest.prototype.testIfProtocolMethodIsReturningProperly = function () {
- var fakeDocument = {
- location: { protocol: "https:" }
- };
- var script = null;
- var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
- var fakedom = [];
- var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
- return script;
- },
- insertInto: function (tag, elem) {
- fakedom[tag].push(elem);
- global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
- return ["aachen bold", "kid print regualr"];
- };
- if (script.onload) {
- script.onload();
- }
- },
- getWindow: function () {
- // should be window in actual situation.
- return {};
- }
- };
-
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument, config);
- assertEquals("https:", monotypeScript.protocol());
-
- fakeDocument = {
- location: { protocol: "http:" }
- };
-
- monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument, config);
- assertEquals("http:", monotypeScript.protocol());
-};
-
MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
var fakedom = { 'head': [], 'body': [] };
- var fakeDocument = {
- location: { protocol: "http:" }
- };
var script = null;
var global = {}; // should be window in actual situation.
var families = null;
@@ -65,6 +23,9 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
},
getWindow: function () {
return global;
+ },
+ getProtocol: function () {
+ return "http:";
}
};
@@ -83,7 +44,7 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
}
var isSupport = null;
var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument, config);
+ var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript.load(function (fontFamilies) {
families = fontFamilies;
@@ -99,12 +60,7 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
//If current page is browsed using https protocol, the added script should be requested with SSL.
MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
var fakedom = { 'head': [], 'body': [] };
- var fakeDocument1 = {
- location: { protocol: "https:" }
- };
- var fakeDocument2 = {
- location: { protocol: "http:" }
- };
+ var fakeProtocol = "https:";
var script = null;
var global = {}; // should be window in actual situation.
var families = null;
@@ -126,6 +82,9 @@ MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
},
getWindow: function () {
return global;
+ },
+ getProtocol: function () {
+ return fakeProtocol;
}
};
@@ -145,7 +104,7 @@ MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
}
var isSupport = null;
var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument1, config);
+ var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript.load(function (fontFamilies) {
families = fontFamilies;
@@ -159,7 +118,8 @@ MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
//one page can have multiple projects, but not 2 projects with same projectId.
config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7c1', api: "http://fast.fonts.com/jsapidev" };
- var monotypeScript2 = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument2, config);
+ fakeProtocol = "http:";
+ var monotypeScript2 = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript2.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript2.load(function (fontFamilies) {
families = fontFamilies;
@@ -194,11 +154,8 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
},
getWindow: function () {
return global;
- }
- };
-
- var fakeDocHelper = {
- protocol: function () {
+ },
+ getProtocol: function () {
return "http:";
}
};
@@ -219,7 +176,7 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
var isSupport = null;
var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocHelper, config);
+ var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript.load(function (fontFamilies) {
@@ -236,7 +193,6 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
//If current page is browsed using https protocol, the added script should be requested with SSL.
MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlHasCorrectSSL = function () {
var fakedom = { 'head': [], 'body': [] };
- var fakeDocument = { location: { protocol: "https:"} };
var global = {}; // should be window in actual situation.
var script = null;
var families = null;
@@ -258,6 +214,9 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlH
},
getWindow: function () {
return global;
+ },
+ getProtocol: function () {
+ return "https:";
}
};
@@ -277,7 +236,7 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlH
var isSupport = null;
var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocument, config);
+ var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript.load(function (fontFamilies) {
@@ -315,18 +274,15 @@ MonotypeScriptTest.prototype.testWithoutProjectId = function () {
},
getWindow: function () {
return global;
- }
- };
-
- var fakeDocHelper = {
- protocol: function () {
+ },
+ getProtocol: function () {
return "http:";
}
};
var isSupport = null;
var userAgent = new webfont.UserAgent("Test", "1.0", true);
- var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, fakeDocHelper, config);
+ var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
monotypeScript.load(function (fontFamilies) {
Oops, something went wrong.

0 comments on commit 1e7293b

Please sign in to comment.