webfontloader 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/Gemfile +2 -8
- data/README.md +31 -32
- data/Rakefile +2 -33
- data/docs/EVENTS.md +10 -1
- data/docs/MODULES.md +4 -3
- data/lib/webfontloader.rb +1 -1
- data/spec/ascender/ascenderscript_spec.js +43 -0
- data/spec/core/cssclassname_spec.js +42 -0
- data/spec/core/cssfontfamilyname_spec.js +38 -0
- data/spec/core/domhelper_spec.js +158 -0
- data/spec/core/eventdispatcher_spec.js +209 -0
- data/spec/core/font_spec.js +218 -0
- data/spec/core/fontmoduleloader_spec.js +55 -0
- data/spec/core/fontruler_spec.js +33 -0
- data/spec/core/fontvariationdescription_spec.js +67 -0
- data/spec/core/fontwatcher_spec.js +204 -0
- data/spec/core/fontwatchrunner_spec.js +398 -0
- data/spec/core/size_spec.js +17 -0
- data/spec/core/useragentparser_spec.js +921 -0
- data/spec/custom/customcss_spec.js +36 -0
- data/spec/fontdeck/fontdeckscript_spec.js +111 -0
- data/spec/fonts/LICENSE.txt +93 -0
- data/spec/fonts/nullfont.css +1 -0
- data/spec/fonts/nullfont1.css +1 -0
- data/spec/fonts/nullfont2.css +1 -0
- data/spec/fonts/nullfont3.css +1 -0
- data/spec/fonts/sourcesans.eot +0 -0
- data/spec/fonts/sourcesans.otf +0 -0
- data/spec/fonts/sourcesans.svg +2523 -0
- data/spec/fonts/sourcesans.ttf +0 -0
- data/spec/fonts/sourcesans.woff +0 -0
- data/spec/fonts/sourcesansa.css +1 -0
- data/spec/fonts/sourcesansb.css +1 -0
- data/spec/google/fontapiparser_spec.js +348 -0
- data/spec/google/fontapiurlbuilder_spec.js +40 -0
- data/spec/google/googlefontapi_spec.js +123 -0
- data/spec/google/lastresortwebkitfontwatchrunner_spec.js +145 -0
- data/spec/index.html +95 -0
- data/spec/monotype/monotypescript_spec.js +49 -0
- data/spec/typekit/typekitscript_spec.js +93 -0
- data/src/core/domhelper.js +6 -3
- data/src/core/fontruler.js +1 -1
- data/src/core/fontwatcher.js +5 -0
- data/src/core/fontwatchrunner.js +7 -4
- data/src/monotype/monotype_script.js +4 -3
- data/tools/jasmine-phantomjs/jasmine-phantomjs.js +26 -0
- data/tools/jasmine-phantomjs/terminal-reporter.js +177 -0
- data/tools/jasmine/MIT.LICENSE +20 -0
- data/tools/jasmine/jasmine-html.js +681 -0
- data/tools/jasmine/jasmine.css +82 -0
- data/tools/jasmine/jasmine.js +2600 -0
- data/webfontloader.gemspec +46 -25
- metadata +77 -42
- data/src-test/ascender/ascender_script_test.js +0 -51
- data/src-test/core/cssclassnametest.js +0 -42
- data/src-test/core/cssfontfamilynametest.js +0 -54
- data/src-test/core/domhelpertest.js +0 -151
- data/src-test/core/eventdispatchertest.js +0 -275
- data/src-test/core/fontmoduleloadertest.js +0 -30
- data/src-test/core/fonttest.js +0 -121
- data/src-test/core/fontvariationdescriptiontest.js +0 -76
- data/src-test/core/fontwatchertest.js +0 -287
- data/src-test/core/fontwatchrunnertest.js +0 -454
- data/src-test/core/useragenttest.js +0 -755
- data/src-test/custom/customcsstest.js +0 -35
- data/src-test/fontdeck/fontdeck_script_test.js +0 -116
- data/src-test/google/fontapiparsertest.js +0 -252
- data/src-test/google/fontapiurlbuildertest.js +0 -71
- data/src-test/google/googlefontapitest.js +0 -185
- data/src-test/google/lastresortwebkitfontwatchrunnertest.js +0 -204
- data/src-test/monotype/monotype_script_test.js +0 -304
- data/src-test/typekit/typekit_script_test.js +0 -195
- data/tools/jstestdriver/JsTestDriver-1.2.1.jar +0 -0
@@ -1,185 +0,0 @@
|
|
1
|
-
var GoogleFontApiTest = TestCase('GoogleFontApiTest');
|
2
|
-
|
3
|
-
GoogleFontApiTest.prototype.testCallOnReadyWithFontFamilyLoading = function() {
|
4
|
-
var insert = '';
|
5
|
-
var link = '';
|
6
|
-
var fakeDomHelper = {
|
7
|
-
insertInto: function(tag, e) {
|
8
|
-
insert = tag;
|
9
|
-
},
|
10
|
-
createCssLink: function(csslink) {
|
11
|
-
link = csslink;
|
12
|
-
},
|
13
|
-
getProtocol: function() {
|
14
|
-
return 'http:';
|
15
|
-
}
|
16
|
-
};
|
17
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
18
|
-
var googleFontApi = new webfont.GoogleFontApi(userAgent, fakeDomHelper,
|
19
|
-
{ families: [ 'Font1', 'Font2' ] });
|
20
|
-
|
21
|
-
var families = null;
|
22
|
-
var descriptions = null;
|
23
|
-
|
24
|
-
googleFontApi.load(function(fontFamilies, fontDescriptions) {
|
25
|
-
families = fontFamilies;
|
26
|
-
descriptions = fontDescriptions;
|
27
|
-
});
|
28
|
-
|
29
|
-
assertEquals('head', insert);
|
30
|
-
assertEquals('http://fonts.googleapis.com/css?family=' +
|
31
|
-
'Font1%7CFont2', link);
|
32
|
-
|
33
|
-
assertNotNull(families);
|
34
|
-
assertEquals(2, families.length);
|
35
|
-
assertEquals('Font1', families[0]);
|
36
|
-
assertEquals('Font2', families[1]);
|
37
|
-
|
38
|
-
var font1Descriptions = descriptions['Font1'];
|
39
|
-
assertNotNull(font1Descriptions);
|
40
|
-
assertEquals(1, font1Descriptions.length);
|
41
|
-
assertEquals('n4', font1Descriptions[0]);
|
42
|
-
|
43
|
-
var font2Descriptions = descriptions['Font2'];
|
44
|
-
assertNotNull(font2Descriptions);
|
45
|
-
assertEquals(1, font2Descriptions.length);
|
46
|
-
assertEquals('n4', font2Descriptions[0]);
|
47
|
-
};
|
48
|
-
|
49
|
-
GoogleFontApiTest.prototype.testCallOnReadyWithFontFamilyLoadingApiUrlChanged =
|
50
|
-
function() {
|
51
|
-
var insert = '';
|
52
|
-
var link = '';
|
53
|
-
var fakeDomHelper = {
|
54
|
-
insertInto: function(tag, e) {
|
55
|
-
insert = tag;
|
56
|
-
},
|
57
|
-
createCssLink: function(csslink) {
|
58
|
-
link = csslink;
|
59
|
-
},
|
60
|
-
getProtocol: function() {
|
61
|
-
return 'http:';
|
62
|
-
}
|
63
|
-
};
|
64
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
65
|
-
var googleFontApi = new webfont.GoogleFontApi(userAgent, fakeDomHelper,
|
66
|
-
{ api: 'http://moo', families: [ 'Font1', 'Font2' ] });
|
67
|
-
|
68
|
-
var families = null;
|
69
|
-
var descriptions = null;
|
70
|
-
|
71
|
-
googleFontApi.load(function(fontFamilies, fontDescriptions) {
|
72
|
-
families = fontFamilies;
|
73
|
-
descriptions = fontDescriptions;
|
74
|
-
});
|
75
|
-
|
76
|
-
assertEquals('head', insert);
|
77
|
-
assertEquals('http://moo?family=Font1%7CFont2', link);
|
78
|
-
|
79
|
-
assertNotNull(families);
|
80
|
-
assertEquals(2, families.length);
|
81
|
-
assertEquals('Font1', families[0]);
|
82
|
-
assertEquals('Font2', families[1]);
|
83
|
-
|
84
|
-
var font1Descriptions = descriptions['Font1'];
|
85
|
-
assertNotNull(font1Descriptions);
|
86
|
-
assertEquals(1, font1Descriptions.length);
|
87
|
-
assertEquals('n4', font1Descriptions[0]);
|
88
|
-
|
89
|
-
var font2Descriptions = descriptions['Font2'];
|
90
|
-
assertNotNull(font2Descriptions);
|
91
|
-
assertEquals(1, font2Descriptions.length);
|
92
|
-
assertEquals('n4', font2Descriptions[0]);
|
93
|
-
};
|
94
|
-
|
95
|
-
GoogleFontApiTest.prototype.testSpacesReplacedByPlus = function() {
|
96
|
-
var insert = '';
|
97
|
-
var link = '';
|
98
|
-
var fakeDomHelper = {
|
99
|
-
insertInto: function(tag, e) {
|
100
|
-
insert = tag;
|
101
|
-
},
|
102
|
-
createCssLink: function(csslink) {
|
103
|
-
link = csslink;
|
104
|
-
},
|
105
|
-
getProtocol: function() {
|
106
|
-
return 'http:';
|
107
|
-
}
|
108
|
-
};
|
109
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
110
|
-
var googleFontApi = new webfont.GoogleFontApi(userAgent, fakeDomHelper,
|
111
|
-
{ families: [ 'Font1 WithSpace', 'Font2 WithSpaceToo' ] });
|
112
|
-
|
113
|
-
var families = null;
|
114
|
-
var descriptions = null;
|
115
|
-
|
116
|
-
googleFontApi.load(function(fontFamilies, fontDescriptions) {
|
117
|
-
families = fontFamilies;
|
118
|
-
descriptions = fontDescriptions;
|
119
|
-
});
|
120
|
-
|
121
|
-
assertEquals('head', insert);
|
122
|
-
assertEquals('http://fonts.googleapis.com/css?family=Font1+WithSpace%7CFont2+WithSpaceToo', link);
|
123
|
-
|
124
|
-
assertNotNull(families);
|
125
|
-
assertEquals(2, families.length);
|
126
|
-
assertEquals('Font1 WithSpace', families[0]);
|
127
|
-
assertEquals('Font2 WithSpaceToo', families[1]);
|
128
|
-
|
129
|
-
var font1Descriptions = descriptions['Font1 WithSpace'];
|
130
|
-
assertNotNull(font1Descriptions);
|
131
|
-
assertEquals(1, font1Descriptions.length);
|
132
|
-
assertEquals('n4', font1Descriptions[0]);
|
133
|
-
|
134
|
-
var font2Descriptions = descriptions['Font2 WithSpaceToo'];
|
135
|
-
assertNotNull(font2Descriptions);
|
136
|
-
assertEquals(1, font2Descriptions.length);
|
137
|
-
assertEquals('n4', font2Descriptions[0]);
|
138
|
-
};
|
139
|
-
|
140
|
-
GoogleFontApiTest.prototype.testLoadWithVariations = function() {
|
141
|
-
var insert = '';
|
142
|
-
var link = '';
|
143
|
-
var fakeDomHelper = {
|
144
|
-
insertInto: function(tag, e) {
|
145
|
-
insert = tag;
|
146
|
-
},
|
147
|
-
createCssLink: function(csslink) {
|
148
|
-
link = csslink;
|
149
|
-
},
|
150
|
-
getProtocol: function() {
|
151
|
-
return 'http:';
|
152
|
-
}
|
153
|
-
};
|
154
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
155
|
-
var googleFontApi = new webfont.GoogleFontApi(userAgent, fakeDomHelper,
|
156
|
-
{ families: [ 'Font1 WithSpace:bi', 'Font2 WithSpaceToo:b,r' ] });
|
157
|
-
|
158
|
-
var families = null;
|
159
|
-
var descriptions = null;
|
160
|
-
|
161
|
-
googleFontApi.load(function(fontFamilies, fontDescriptions) {
|
162
|
-
families = fontFamilies;
|
163
|
-
descriptions = fontDescriptions;
|
164
|
-
});
|
165
|
-
|
166
|
-
assertEquals('head', insert);
|
167
|
-
assertEquals('http://fonts.googleapis.com/css?family=Font1+WithSpace:bi%7CFont2+WithSpaceToo:b,r', link);
|
168
|
-
|
169
|
-
assertNotNull(families);
|
170
|
-
assertEquals(2, families.length);
|
171
|
-
assertEquals('Font1 WithSpace', families[0]);
|
172
|
-
assertEquals('Font2 WithSpaceToo', families[1]);
|
173
|
-
assertNotNull(descriptions);
|
174
|
-
|
175
|
-
var font1Descriptions = descriptions['Font1 WithSpace'];
|
176
|
-
assertNotNull(font1Descriptions);
|
177
|
-
assertEquals(1, font1Descriptions.length);
|
178
|
-
assertEquals('i7', font1Descriptions[0]);
|
179
|
-
|
180
|
-
var font2Descriptions = descriptions['Font2 WithSpaceToo'];
|
181
|
-
assertNotNull(font2Descriptions);
|
182
|
-
assertEquals(2, font2Descriptions.length);
|
183
|
-
assertEquals('n7', font2Descriptions[0]);
|
184
|
-
assertEquals('n4', font2Descriptions[1]);
|
185
|
-
};
|
@@ -1,204 +0,0 @@
|
|
1
|
-
var LastResortWebKitFontWatchRunnerTest =
|
2
|
-
TestCase('LastResortWebKitFontWatchRunnerTest');
|
3
|
-
|
4
|
-
LastResortWebKitFontWatchRunnerTest.prototype.setUp = function() {
|
5
|
-
var self = this;
|
6
|
-
|
7
|
-
this.fontFamily_ = 'fontFamily1';
|
8
|
-
this.fontDescription_ = 'n4';
|
9
|
-
|
10
|
-
this.fontActiveCalled_ = 0;
|
11
|
-
this.fontActive_ = {};
|
12
|
-
this.fontInactiveCalled_ = 0;
|
13
|
-
this.fontInactive_ = {};
|
14
|
-
this.activeCallback_ = function(fontFamily, fontDescription) {
|
15
|
-
self.fontActiveCalled_++;
|
16
|
-
self.fontActive_[fontFamily + ' ' + fontDescription] = true;
|
17
|
-
};
|
18
|
-
this.inactiveCallback_ = function(fontFamily, fontDescription) {
|
19
|
-
self.fontInactiveCalled_++;
|
20
|
-
self.fontInactive_[fontFamily + ' ' + fontDescription] = true;
|
21
|
-
};
|
22
|
-
|
23
|
-
this.createElementCalled_ = 0;
|
24
|
-
this.createdElements_ = [];
|
25
|
-
this.insertIntoCalled_ = 0;
|
26
|
-
this.removeElementCalled_ = 0;
|
27
|
-
this.setStyleCalled_ = 0;
|
28
|
-
this.fakeDomHelper_ = {
|
29
|
-
createElement: function(name, attrs, innerHtml) {
|
30
|
-
self.createElementCalled_++;
|
31
|
-
self.createdElements_.push({
|
32
|
-
'name': name,
|
33
|
-
'attrs': attrs,
|
34
|
-
'innerHtml': innerHtml
|
35
|
-
});
|
36
|
-
|
37
|
-
var element = document.createElement(name);
|
38
|
-
|
39
|
-
for (var attr in attrs) {
|
40
|
-
element.setAttribute(attr, attrs[attr]);
|
41
|
-
}
|
42
|
-
element.innerHTML = innerHtml;
|
43
|
-
return element;
|
44
|
-
},
|
45
|
-
insertInto: function(name, el) {
|
46
|
-
self.insertIntoCalled_++;
|
47
|
-
},
|
48
|
-
removeElement: function(el) {
|
49
|
-
self.removeElementCalled_++;
|
50
|
-
},
|
51
|
-
setStyle: function(e, s) {
|
52
|
-
self.setStyleCalled_++;
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
this.timesToGetTimeBeforeTimeout_ = 10;
|
57
|
-
this.fakeGetTime_ = function() {
|
58
|
-
if (self.timesToGetTimeBeforeTimeout_ <= 0) {
|
59
|
-
return 6000;
|
60
|
-
} else {
|
61
|
-
self.timesToGetTimeBeforeTimeout_--;
|
62
|
-
return 1;
|
63
|
-
}
|
64
|
-
};
|
65
|
-
|
66
|
-
this.asyncCount_ = 0;
|
67
|
-
this.fakeAsyncCall_ = function(func, timeout) {
|
68
|
-
self.asyncCount_++;
|
69
|
-
func();
|
70
|
-
};
|
71
|
-
};
|
72
|
-
|
73
|
-
LastResortWebKitFontWatchRunnerTest.prototype.testLastResortFontIgnored =
|
74
|
-
function() {
|
75
|
-
var originalSizeCount = 2;
|
76
|
-
var lastResortFontsCount = 5;
|
77
|
-
var firstSize = 2;
|
78
|
-
var secondSize = 2;
|
79
|
-
var thirdSize = 2;
|
80
|
-
|
81
|
-
var fontWatchRunner = new webfont.LastResortWebKitFontWatchRunner(
|
82
|
-
this.activeCallback_,
|
83
|
-
this.inactiveCallback_,
|
84
|
-
this.fakeDomHelper_, {getSize: function() {
|
85
|
-
if (originalSizeCount > 0) {
|
86
|
-
originalSizeCount--;
|
87
|
-
return new webfont.Size(1, 1);
|
88
|
-
}
|
89
|
-
if (lastResortFontsCount > 0) {
|
90
|
-
lastResortFontsCount--;
|
91
|
-
return new webfont.Size(2, 2);
|
92
|
-
}
|
93
|
-
if (firstSize > 0) {
|
94
|
-
firstSize--;
|
95
|
-
return new webfont.Size(1, 1);
|
96
|
-
}
|
97
|
-
if (secondSize > 0) {
|
98
|
-
secondSize--;
|
99
|
-
return new webfont.Size(2, 2);
|
100
|
-
}
|
101
|
-
if (thirdSize > 0) {
|
102
|
-
thirdSize--;
|
103
|
-
return new webfont.Size(3, 3);
|
104
|
-
}
|
105
|
-
}}, this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
106
|
-
this.fontDescription_, false);
|
107
|
-
|
108
|
-
fontWatchRunner.start();
|
109
|
-
assertEquals(1, this.asyncCount_);
|
110
|
-
|
111
|
-
// When on webkit time out ends up activating the font.
|
112
|
-
assertEquals(1, this.fontActiveCalled_);
|
113
|
-
assertEquals(0, this.fontInactiveCalled_);
|
114
|
-
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
115
|
-
};
|
116
|
-
|
117
|
-
LastResortWebKitFontWatchRunnerTest.prototype.testLastResortFontActiveWhenSizeMatch
|
118
|
-
= function() {
|
119
|
-
this.timesToGetTimeBeforeTimeout_ = 3;
|
120
|
-
var originalSizeCount = 2;
|
121
|
-
var lastResortFontsCount = 5;
|
122
|
-
var firstSize = 2;
|
123
|
-
|
124
|
-
this.fontFamily_ = "Arimo";
|
125
|
-
|
126
|
-
var fontWatchRunner = new webfont.LastResortWebKitFontWatchRunner(
|
127
|
-
this.activeCallback_,
|
128
|
-
this.inactiveCallback_,
|
129
|
-
this.fakeDomHelper_, {getSize: function() {
|
130
|
-
if (originalSizeCount > 0) {
|
131
|
-
originalSizeCount--;
|
132
|
-
return new webfont.Size(1, 1);
|
133
|
-
}
|
134
|
-
if (lastResortFontsCount > 0) {
|
135
|
-
lastResortFontsCount--;
|
136
|
-
return new webfont.Size(2, 2);
|
137
|
-
}
|
138
|
-
if (firstSize > 0) {
|
139
|
-
firstSize--;
|
140
|
-
return new webfont.Size(1, 1);
|
141
|
-
}
|
142
|
-
return new webfont.Size(2, 2);
|
143
|
-
}}, this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
144
|
-
this.fontDescription_, false);
|
145
|
-
|
146
|
-
fontWatchRunner.start();
|
147
|
-
|
148
|
-
assertEquals(2, this.asyncCount_);
|
149
|
-
|
150
|
-
assertEquals(1, this.fontActiveCalled_);
|
151
|
-
assertEquals(0, this.fontInactiveCalled_);
|
152
|
-
assertEquals(true, this.fontActive_['Arimo n4']);
|
153
|
-
};
|
154
|
-
|
155
|
-
LastResortWebKitFontWatchRunnerTest.prototype.testLastResortFontInactiveWhenSizeNoMatch
|
156
|
-
= function() {
|
157
|
-
this.timesToGetTimeBeforeTimeout_ = 3;
|
158
|
-
var originalSizeCount = 2;
|
159
|
-
var lastResortFontsCount = 5;
|
160
|
-
var firstSize = 2;
|
161
|
-
var secondSize = 2;
|
162
|
-
var thirdSize = 2;
|
163
|
-
|
164
|
-
var fontWatchRunner = new webfont.LastResortWebKitFontWatchRunner(
|
165
|
-
this.activeCallback_,
|
166
|
-
this.inactiveCallback_,
|
167
|
-
this.fakeDomHelper_, {getSize: function(elem) {
|
168
|
-
if (originalSizeCount > 0) {
|
169
|
-
originalSizeCount--;
|
170
|
-
return new webfont.Size(1, 1);
|
171
|
-
}
|
172
|
-
if (lastResortFontsCount > 0) {
|
173
|
-
lastResortFontsCount--;
|
174
|
-
return new webfont.Size(2, 2);
|
175
|
-
}
|
176
|
-
if (firstSize > 0) {
|
177
|
-
firstSize--;
|
178
|
-
return new webfont.Size(1, 1)
|
179
|
-
}
|
180
|
-
if (secondSize > 0) {
|
181
|
-
secondSize--;
|
182
|
-
return new webfont.Size(2, 2)
|
183
|
-
}
|
184
|
-
if (thirdSize == 2) {
|
185
|
-
thirdSize--;
|
186
|
-
return new webfont.Size(2, 2);
|
187
|
-
}
|
188
|
-
if (thirdSize == 1) {
|
189
|
-
thirdSize--;
|
190
|
-
return new webfont.Size(4, 4);
|
191
|
-
}
|
192
|
-
return new webfont.Size(2, 2);
|
193
|
-
}}, this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
194
|
-
this.fontDescription_, false);
|
195
|
-
|
196
|
-
fontWatchRunner.start();
|
197
|
-
|
198
|
-
assertEquals(2, this.asyncCount_);
|
199
|
-
|
200
|
-
// When on webkit time out ends up activating the font.
|
201
|
-
assertEquals(0, this.fontActiveCalled_);
|
202
|
-
assertEquals(1, this.fontInactiveCalled_);
|
203
|
-
assertEquals(true, this.fontInactive_['fontFamily1 n4']);
|
204
|
-
};
|
@@ -1,304 +0,0 @@
|
|
1
|
-
var MonotypeScriptTest = TestCase('MonotypeScriptTest');
|
2
|
-
|
3
|
-
MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
|
4
|
-
var fakedom = { 'head': [], 'body': [] };
|
5
|
-
var script = null;
|
6
|
-
var global = {}; // should be window in actual situation.
|
7
|
-
var families = null;
|
8
|
-
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
9
|
-
|
10
|
-
var fakeDomHelper = {
|
11
|
-
createElement: function () {
|
12
|
-
script = {
|
13
|
-
addEventListener: function () {}
|
14
|
-
};
|
15
|
-
return script;
|
16
|
-
},
|
17
|
-
insertInto: function (tag, elem) {
|
18
|
-
fakedom[tag].push(elem);
|
19
|
-
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
20
|
-
return ["aachen bold", "kid print regualr"];
|
21
|
-
};
|
22
|
-
if (script.onload) {
|
23
|
-
script.onload();
|
24
|
-
}
|
25
|
-
},
|
26
|
-
getLoadWindow: function () {
|
27
|
-
return global;
|
28
|
-
},
|
29
|
-
getProtocol: function () {
|
30
|
-
return "http:";
|
31
|
-
}
|
32
|
-
};
|
33
|
-
|
34
|
-
function getElementById(Id) {
|
35
|
-
var p;
|
36
|
-
for (p in fakedom) {
|
37
|
-
if (fakedom[p].length > 0) {
|
38
|
-
for (i = 0; i < fakedom[p].length; i++) {
|
39
|
-
if (fakedom[p][i].id === Id) {
|
40
|
-
return fakedom[p][i];
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
return null;
|
46
|
-
}
|
47
|
-
var isSupport = null;
|
48
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", "TestEngine", "2.0", "TestPlatform", "3.0", undefined, new webfont.BrowserInfo(false, false));
|
49
|
-
var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
50
|
-
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
51
|
-
monotypeScript.load(function (fontFamilies) {
|
52
|
-
families = fontFamilies;
|
53
|
-
});
|
54
|
-
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
55
|
-
|
56
|
-
assertEquals(null, isSupport);
|
57
|
-
assertNotNull(script);
|
58
|
-
assertEquals("http://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
59
|
-
assertEquals(2, families.length);
|
60
|
-
};
|
61
|
-
|
62
|
-
//If current page is browsed using https protocol, the added script should be requested with SSL.
|
63
|
-
MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
|
64
|
-
var fakedom = { 'head': [], 'body': [] };
|
65
|
-
var fakeProtocol = "https:";
|
66
|
-
var script = null;
|
67
|
-
var global = {}; // should be window in actual situation.
|
68
|
-
var families = null;
|
69
|
-
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
70
|
-
|
71
|
-
var fakeDomHelper = {
|
72
|
-
createElement: function () {
|
73
|
-
script = {
|
74
|
-
addEventListener: function () {}
|
75
|
-
};
|
76
|
-
return script;
|
77
|
-
},
|
78
|
-
insertInto: function (tag, elem) {
|
79
|
-
fakedom[tag].push(elem);
|
80
|
-
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
81
|
-
return ["aachen bold", "kid print regualr"];
|
82
|
-
};
|
83
|
-
if (script.onload) {
|
84
|
-
script.onload();
|
85
|
-
}
|
86
|
-
},
|
87
|
-
getLoadWindow: function () {
|
88
|
-
return global;
|
89
|
-
},
|
90
|
-
getProtocol: function () {
|
91
|
-
return fakeProtocol;
|
92
|
-
}
|
93
|
-
};
|
94
|
-
|
95
|
-
//trys to simulates exactly the getElementById behaviour, by returning the first found element.
|
96
|
-
function getElementById(Id) {
|
97
|
-
var p;
|
98
|
-
for (p in fakedom) {
|
99
|
-
if (fakedom[p].length > 0) {
|
100
|
-
for (i = 0; i < fakedom[p].length; i++) {
|
101
|
-
if (fakedom[p][i].id === Id) {
|
102
|
-
return fakedom[p][i];
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
return null;
|
108
|
-
}
|
109
|
-
var isSupport = null;
|
110
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", "TestEngine", "2.0", "TestPlatform", "3.0", undefined, new webfont.BrowserInfo(false, false));
|
111
|
-
var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
112
|
-
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
113
|
-
monotypeScript.load(function (fontFamilies) {
|
114
|
-
families = fontFamilies;
|
115
|
-
});
|
116
|
-
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
117
|
-
|
118
|
-
assertEquals(null, isSupport);
|
119
|
-
assertNotNull(script);
|
120
|
-
assertEquals("https://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
121
|
-
assertEquals(2, families.length);
|
122
|
-
|
123
|
-
//one page can have multiple projects, but not 2 projects with same projectId.
|
124
|
-
config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7c1', api: "http://fast.fonts.com/jsapidev" };
|
125
|
-
fakeProtocol = "http:";
|
126
|
-
var monotypeScript2 = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
127
|
-
monotypeScript2.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
128
|
-
monotypeScript2.load(function (fontFamilies) {
|
129
|
-
families = fontFamilies;
|
130
|
-
});
|
131
|
-
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
132
|
-
assertEquals(null, isSupport);
|
133
|
-
assertNotNull(script);
|
134
|
-
assertEquals("http://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7c1.js", script.src);
|
135
|
-
assertEquals(2, families.length);
|
136
|
-
};
|
137
|
-
|
138
|
-
MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
|
139
|
-
var fakedom = { 'head': [], 'body': [] };
|
140
|
-
var global = {}; // should be window in actual situation.
|
141
|
-
var script = null;
|
142
|
-
var families = null;
|
143
|
-
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
144
|
-
|
145
|
-
var fakeDomHelper = {
|
146
|
-
createElement: function () {
|
147
|
-
script = {
|
148
|
-
addEventListener: function () {}
|
149
|
-
};
|
150
|
-
return script;
|
151
|
-
},
|
152
|
-
insertInto: function (tag, elem) {
|
153
|
-
fakedom[tag].push(elem);
|
154
|
-
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
155
|
-
return ["aachen bold", "kid print regualr"];
|
156
|
-
};
|
157
|
-
if (script.onload) {
|
158
|
-
script.onload();
|
159
|
-
}
|
160
|
-
},
|
161
|
-
getLoadWindow: function () {
|
162
|
-
return global;
|
163
|
-
},
|
164
|
-
getProtocol: function () {
|
165
|
-
return "http:";
|
166
|
-
}
|
167
|
-
};
|
168
|
-
|
169
|
-
function getElementById(Id) {
|
170
|
-
var p;
|
171
|
-
for (p in fakedom) {
|
172
|
-
if (fakedom[p].length > 0) {
|
173
|
-
for (i = 0; i < fakedom[p].length; i++) {
|
174
|
-
if (fakedom[p][i].id === Id) {
|
175
|
-
return fakedom[p][i];
|
176
|
-
}
|
177
|
-
}
|
178
|
-
}
|
179
|
-
}
|
180
|
-
return null;
|
181
|
-
}
|
182
|
-
|
183
|
-
var isSupport = null;
|
184
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", "TestEngine", "2.0", "TestPlatform", "3.0", undefined, new webfont.BrowserInfo(false, false));
|
185
|
-
var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
186
|
-
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
187
|
-
|
188
|
-
monotypeScript.load(function (fontFamilies) {
|
189
|
-
families = fontFamilies;
|
190
|
-
});
|
191
|
-
//just for testing purpose
|
192
|
-
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
193
|
-
|
194
|
-
assertNotNull(script);
|
195
|
-
assertEquals("http://fast.fonts.com/jsapi/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
196
|
-
assertEquals(2, families.length);
|
197
|
-
};
|
198
|
-
|
199
|
-
//If current page is browsed using https protocol, the added script should be requested with SSL.
|
200
|
-
MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlHasCorrectSSL = function () {
|
201
|
-
var fakedom = { 'head': [], 'body': [] };
|
202
|
-
var global = {}; // should be window in actual situation.
|
203
|
-
var script = null;
|
204
|
-
var families = null;
|
205
|
-
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
206
|
-
|
207
|
-
var fakeDomHelper = {
|
208
|
-
createElement: function () {
|
209
|
-
script = {
|
210
|
-
addEventListener: function () {}
|
211
|
-
};
|
212
|
-
return script;
|
213
|
-
},
|
214
|
-
insertInto: function (tag, elem) {
|
215
|
-
fakedom[tag].push(elem);
|
216
|
-
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
217
|
-
return ["aachen bold", "kid print regualr"];
|
218
|
-
};
|
219
|
-
if (script.onload) {
|
220
|
-
script.onload();
|
221
|
-
}
|
222
|
-
},
|
223
|
-
getLoadWindow: function () {
|
224
|
-
return global;
|
225
|
-
},
|
226
|
-
getProtocol: function () {
|
227
|
-
return "https:";
|
228
|
-
}
|
229
|
-
};
|
230
|
-
|
231
|
-
function getElementById(Id) {
|
232
|
-
var p;
|
233
|
-
for (p in fakedom) {
|
234
|
-
if (fakedom[p].length > 0) {
|
235
|
-
for (i = 0; i < fakedom[p].length; i++) {
|
236
|
-
if (fakedom[p][i].id === Id) {
|
237
|
-
return fakedom[p][i];
|
238
|
-
}
|
239
|
-
}
|
240
|
-
}
|
241
|
-
}
|
242
|
-
return null;
|
243
|
-
}
|
244
|
-
|
245
|
-
var isSupport = null;
|
246
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", "TestEngine", "2.0", "TestPlatform", "3.0", undefined, new webfont.BrowserInfo(false, false));
|
247
|
-
var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
248
|
-
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
249
|
-
|
250
|
-
monotypeScript.load(function (fontFamilies) {
|
251
|
-
families = fontFamilies;
|
252
|
-
});
|
253
|
-
//just for testing purpose
|
254
|
-
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
255
|
-
|
256
|
-
assertNotNull(script);
|
257
|
-
assertEquals("https://fast.fonts.com/jsapi/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
258
|
-
assertEquals(2, families.length);
|
259
|
-
};
|
260
|
-
|
261
|
-
//if no projectId is provided in config, the script should not be added.
|
262
|
-
MonotypeScriptTest.prototype.testWithoutProjectId = function () {
|
263
|
-
var fakedom = { 'head': [], 'body': [] };
|
264
|
-
var global = {}; // should be window in actual situation.
|
265
|
-
var script = null;
|
266
|
-
var families = null;
|
267
|
-
var config = {};
|
268
|
-
|
269
|
-
var fakeDomHelper = {
|
270
|
-
createElement: function () {
|
271
|
-
script = {
|
272
|
-
addEventListener: function () {}
|
273
|
-
};
|
274
|
-
return script;
|
275
|
-
},
|
276
|
-
insertInto: function (tag, elem) {
|
277
|
-
fakedom[tag].push(elem);
|
278
|
-
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
279
|
-
return ["aachen bold", "kid print regualr"];
|
280
|
-
};
|
281
|
-
if (script.onload) {
|
282
|
-
script.onload();
|
283
|
-
}
|
284
|
-
},
|
285
|
-
getLoadWindow: function () {
|
286
|
-
return global;
|
287
|
-
},
|
288
|
-
getProtocol: function () {
|
289
|
-
return "http:";
|
290
|
-
}
|
291
|
-
};
|
292
|
-
|
293
|
-
var isSupport = null;
|
294
|
-
var userAgent = new webfont.UserAgent("Test", "1.0", "TestEngine", "2.0", "TestPlatform", "3.0", undefined, new webfont.BrowserInfo(false, false));
|
295
|
-
var monotypeScript = new webfont.MonotypeScript(userAgent, fakeDomHelper, config);
|
296
|
-
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
297
|
-
|
298
|
-
monotypeScript.load(function (fontFamilies) {
|
299
|
-
families = fontFamilies;
|
300
|
-
});
|
301
|
-
assertNull(script);
|
302
|
-
assertEquals(0, families.length);
|
303
|
-
|
304
|
-
};
|