webfontloader 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -0
- data/README.md +13 -2
- data/docs/MODULES.md +15 -2
- data/lib/webfontloader.rb +1 -1
- data/src/ascender/ascender_script.js +1 -1
- data/src/core/browserinfo.js +23 -0
- data/src/core/font.js +4 -4
- data/src/core/fontruler.js +61 -0
- data/src/core/fontwatcher.js +7 -4
- data/src/core/fontwatchrunner.js +144 -92
- data/src/core/initialize.js +3 -1
- data/src/core/size.js +19 -0
- data/src/core/useragent.js +6 -6
- data/src/core/useragentparser.js +62 -59
- data/src/custom/customcss.js +21 -4
- data/src/google/googlefontapi.js +1 -1
- data/src/google/lastresortwebkitfontwatchrunner.js +26 -22
- data/src/modules.yml +3 -0
- data/src/monotype/monotype_script.js +1 -1
- data/src-test/core/fonttest.js +6 -4
- data/src-test/core/fontwatchertest.js +47 -11
- data/src-test/core/fontwatchrunnertest.js +289 -74
- data/src-test/core/useragenttest.js +65 -45
- data/src-test/custom/customcsstest.js +7 -2
- data/src-test/google/lastresortwebkitfontwatchrunnertest.js +23 -23
- data/src-test/monotype/monotype_script_test.js +5 -5
- data/webfontloader.gemspec +5 -2
- metadata +16 -13
@@ -26,14 +26,14 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
26
26
|
this.fakeDomHelper_ = {
|
27
27
|
createElement: function(name, attrs, innerHtml) {
|
28
28
|
self.createElementCalled_++;
|
29
|
+
var element = document.createElement(name);
|
29
30
|
self.createdElements_.push({
|
30
31
|
'name': name,
|
31
32
|
'attrs': attrs,
|
32
|
-
'innerHtml': innerHtml
|
33
|
+
'innerHtml': innerHtml,
|
34
|
+
'element': element
|
33
35
|
});
|
34
36
|
|
35
|
-
var element = document.createElement(name);
|
36
|
-
|
37
37
|
for (var attr in attrs) {
|
38
38
|
element.setAttribute(attr, attrs[attr]);
|
39
39
|
}
|
@@ -45,26 +45,155 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
45
45
|
},
|
46
46
|
removeElement: function(el) {
|
47
47
|
self.removeElementCalled_++;
|
48
|
+
},
|
49
|
+
setStyle: function(el, style) {
|
50
|
+
el.setAttribute('style', style);
|
51
|
+
for (var i = 0; i < self.createdElements_.length; i += 1) {
|
52
|
+
if (self.createdElements_[i].element === el) {
|
53
|
+
if (!self.createdElements_[i].attrs) {
|
54
|
+
self.createdElements_[i].attrs = {};
|
55
|
+
}
|
56
|
+
self.createdElements_[i].attrs.style = style;
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
}
|
48
60
|
}
|
49
61
|
};
|
50
62
|
|
51
|
-
this.
|
52
|
-
this.timesToReportChangedWidth_ = 2;
|
63
|
+
this.timesToCheckSizesBeforeChange_ = 0;
|
53
64
|
this.fakeFontSizer_ = {
|
54
|
-
|
65
|
+
getSize: function(el) {
|
55
66
|
if (el.style.fontFamily.indexOf(self.fontFamily_) != -1) {
|
56
67
|
// This is a font stack with fontFamily included (not just fallbacks)
|
57
|
-
if (self.
|
68
|
+
if (self.timesToCheckSizesBeforeChange_ <= 0) {
|
58
69
|
// Decrement by 0.5 because we're checking two separate font stacks each iteration
|
59
|
-
self.
|
60
|
-
return 2;
|
70
|
+
self.timesToCheckSizesBeforeChange_ -= 0.5;
|
71
|
+
return new webfont.Size(2, 2);
|
61
72
|
} else {
|
62
73
|
// Decrement by 0.5 because we're checking two separate font stacks each iteration
|
63
|
-
self.
|
64
|
-
return 1;
|
74
|
+
self.timesToCheckSizesBeforeChange_ -= 0.5;
|
75
|
+
return new webfont.Size(1, 1);
|
76
|
+
}
|
77
|
+
} else {
|
78
|
+
return new webfont.Size(1, 1);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
this.fakeFontSizerWithDifferentHeight_ = {
|
84
|
+
getSize: function(el) {
|
85
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) != -1) {
|
86
|
+
if (self.timesToCheckSizesBeforeChange_ <= 0) {
|
87
|
+
self.timesToCheckSizesBeforeChange_ -= 0.5;
|
88
|
+
return new webfont.Size(1, 2);
|
89
|
+
} else {
|
90
|
+
self.timesToCheckSizesBeforeChange_ -= 0.5;
|
91
|
+
return new webfont.Size(1, 1);
|
92
|
+
}
|
93
|
+
} else {
|
94
|
+
return new webfont.Size(1, 1);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
/**
|
100
|
+
* This accurately models the way webkit used to handle
|
101
|
+
* fallback fonts while loading web fonts. Even though
|
102
|
+
* this Webkit bug is now patched, we still have a large
|
103
|
+
* portion of our users using old webkit builds.
|
104
|
+
*
|
105
|
+
* See: https://bugs.webkit.org/show_bug.cgi?id=76684
|
106
|
+
*/
|
107
|
+
this.timesToDelayChangedSizeWebkit_ = 1;
|
108
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
109
|
+
this.fakeWebkitFontSizer_ = {
|
110
|
+
getSize: function(el) {
|
111
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) !== -1) {
|
112
|
+
if (self.timesToDelayChangedSizeWebkit_ > 0) {
|
113
|
+
self.timesToDelayChangedSizeWebkit_ -= 0.5;
|
114
|
+
// Return the incorrect width for a certain number of cycles.
|
115
|
+
// The actual number depends on how fast or how slow the font
|
116
|
+
// is parsed and applied.
|
117
|
+
return new webfont.Size(2, 2);
|
118
|
+
} else {
|
119
|
+
// Return the correct width
|
120
|
+
return new webfont.Size(3, 3);
|
121
|
+
}
|
122
|
+
} else {
|
123
|
+
if (self.firstCallToRetrieveSizeWebkit_) {
|
124
|
+
self.firstCallToRetrieveSizeWebkit_ = false;
|
125
|
+
return new webfont.Size(2, 2);
|
126
|
+
} else {
|
127
|
+
// Return the default width
|
128
|
+
return new webfont.Size(1, 1);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
this.fakeWebkitFontSizerFailedLoad_ = {
|
135
|
+
getSize: function(el) {
|
136
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) !== -1) {
|
137
|
+
if (self.timesToDelayChangedSizeWebkit_ > 0) {
|
138
|
+
self.timesToDelayChangedSizeWebkit_ -= 0.5;
|
139
|
+
return new webfont.Size(2, 2);
|
140
|
+
} else {
|
141
|
+
// Return the original width, indicating the font
|
142
|
+
// failed to load. This should incorrectly trigger `inactive`.
|
143
|
+
return new webfont.Size(1, 1);
|
144
|
+
}
|
145
|
+
} else {
|
146
|
+
if (self.firstCallToRetrieveSizeWebkit_) {
|
147
|
+
self.firstCallToRetrieveSizeWebkit_ = false;
|
148
|
+
return new webfont.Size(2, 2);
|
149
|
+
} else {
|
150
|
+
return new webfont.Size(1, 1);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
155
|
+
|
156
|
+
this.fakeWebkitFontSizerWithEqualMetrics_ = {
|
157
|
+
getSize: function(el) {
|
158
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) !== -1) {
|
159
|
+
if (self.timesToDelayChangedSizeWebkit_ > 0) {
|
160
|
+
self.timesToDelayChangedSizeWebkit_ -= 0.5;
|
161
|
+
return new webfont.Size(2, 2);
|
162
|
+
} else {
|
163
|
+
// This time the fallback font picked by Webkit has the
|
164
|
+
// same metrics as the font being loaded. This is a rare
|
165
|
+
// case but we should be able to handle it.
|
166
|
+
return new webfont.Size(2, 2);
|
65
167
|
}
|
66
168
|
} else {
|
67
|
-
|
169
|
+
if (self.firstCallToRetrieveSizeWebkit_) {
|
170
|
+
self.firstCallToRetrieveSizeWebkit_ = false;
|
171
|
+
return new webfont.Size(2, 2);
|
172
|
+
} else {
|
173
|
+
return new webfont.Size(1, 1);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
};
|
178
|
+
|
179
|
+
this.fakeWebkitFontSizeWithDifferentMetrics_ = {
|
180
|
+
getSize: function(el) {
|
181
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) !== -1) {
|
182
|
+
if (self.timesToDelayChangedSizeWebkit_ > 0) {
|
183
|
+
self.timesToDelayChangedSizeWebkit_ -= 0.5;
|
184
|
+
return new webfont.Size(2, 2);
|
185
|
+
} else {
|
186
|
+
// Even though the width is the same, the height
|
187
|
+
// is different, so this should trigger the active event.
|
188
|
+
return new webfont.Size(2, 3);
|
189
|
+
}
|
190
|
+
} else {
|
191
|
+
if (self.firstCallToRetrieveSizeWebkit_) {
|
192
|
+
self.firstCallToRetrieveSizeWebkit_ = false;
|
193
|
+
return new webfont.Size(2, 2);
|
194
|
+
} else {
|
195
|
+
return new webfont.Size(1, 1);
|
196
|
+
}
|
68
197
|
}
|
69
198
|
}
|
70
199
|
};
|
@@ -88,18 +217,17 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
88
217
|
};
|
89
218
|
|
90
219
|
FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
|
91
|
-
this.
|
92
|
-
this.timesToReportChangedWidth_ = 2;
|
220
|
+
this.timesToCheckSizesBeforeChange_ = 0;
|
93
221
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
94
222
|
|
95
223
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
96
224
|
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
|
97
225
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
98
|
-
this.fontDescription_);
|
226
|
+
this.fontDescription_, false);
|
99
227
|
|
100
228
|
fontWatchRunner.start();
|
101
229
|
|
102
|
-
assertEquals(
|
230
|
+
assertEquals(0, this.asyncCount_);
|
103
231
|
|
104
232
|
assertEquals(1, this.fontActiveCalled_);
|
105
233
|
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
@@ -107,18 +235,35 @@ FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
|
|
107
235
|
};
|
108
236
|
|
109
237
|
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
|
110
|
-
this.
|
111
|
-
this.timesToReportChangedWidth_ = 2;
|
238
|
+
this.timesToCheckSizesBeforeChange_ = 3;
|
112
239
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
113
240
|
|
114
241
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
115
242
|
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
|
116
243
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
117
|
-
this.fontDescription_);
|
244
|
+
this.fontDescription_, false);
|
118
245
|
|
119
246
|
fontWatchRunner.start();
|
120
247
|
|
121
|
-
assertEquals(
|
248
|
+
assertEquals(3, this.asyncCount_);
|
249
|
+
|
250
|
+
assertEquals(1, this.fontActiveCalled_);
|
251
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
252
|
+
assertEquals(0, this.fontInactiveCalled_);
|
253
|
+
};
|
254
|
+
|
255
|
+
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActiveWithDifferentHeight = function() {
|
256
|
+
this.timesToCheckSizesBeforeChange_ = 3;
|
257
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
258
|
+
|
259
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
260
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizerWithDifferentHeight_,
|
261
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
262
|
+
this.fontDescription_, false);
|
263
|
+
|
264
|
+
fontWatchRunner.start();
|
265
|
+
|
266
|
+
assertEquals(3, this.asyncCount_);
|
122
267
|
|
123
268
|
assertEquals(1, this.fontActiveCalled_);
|
124
269
|
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
@@ -126,14 +271,13 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
|
|
126
271
|
};
|
127
272
|
|
128
273
|
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
|
129
|
-
this.
|
130
|
-
this.timesToReportChangedWidth_ = 2;
|
274
|
+
this.timesToCheckSizesBeforeChange_ = 10;
|
131
275
|
this.timesToGetTimeBeforeTimeout_ = 5;
|
132
276
|
|
133
277
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
134
278
|
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
|
135
279
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
136
|
-
this.fontDescription_);
|
280
|
+
this.fontDescription_, false);
|
137
281
|
|
138
282
|
fontWatchRunner.start();
|
139
283
|
|
@@ -144,96 +288,167 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
|
|
144
288
|
assertEquals(true, this.fontInactive_['fontFamily1 n4']);
|
145
289
|
};
|
146
290
|
|
147
|
-
|
148
|
-
* This test ensures that even if the fonts change width for one cycle and
|
149
|
-
* then change back, active won't be fired. This works around an issue in Webkit
|
150
|
-
* browsers, where an inactive webfont will briefly change widths for one cycle
|
151
|
-
* and then change back to fallback widths on the next cycle. This is apparently
|
152
|
-
* due to some quirk in the way that web fonts are rendered.
|
153
|
-
*/
|
154
|
-
FontWatchRunnerTest.prototype.testWatchFontWithInconsistentWidthIsStillInactive = function() {
|
155
|
-
this.timesToCheckWidthsBeforeChange_ = 3;
|
156
|
-
// Only report a new width for one cycle, then switch back to original fallback width
|
157
|
-
this.timesToReportChangedWidth_ = 1;
|
291
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithFastFont = function() {
|
158
292
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
293
|
+
this.timesToDelayChangedSizeWebkit_ = 1;
|
294
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
159
295
|
|
160
296
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
161
|
-
this.inactiveCallback_, this.fakeDomHelper_, this.
|
297
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizer_,
|
162
298
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
163
|
-
this.fontDescription_);
|
299
|
+
this.fontDescription_, true);
|
164
300
|
|
165
301
|
fontWatchRunner.start();
|
302
|
+
assertEquals(1, this.asyncCount_);
|
303
|
+
assertEquals(1, this.fontActiveCalled_);
|
304
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
305
|
+
};
|
306
|
+
|
307
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithSlowFont = function() {
|
308
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
309
|
+
this.timesToDelayChangedSizeWebkit_ = 2;
|
310
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
311
|
+
|
312
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
313
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizer_,
|
314
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
315
|
+
this.fontDescription_, true);
|
316
|
+
|
317
|
+
fontWatchRunner.start();
|
318
|
+
assertEquals(2, this.asyncCount_);
|
319
|
+
assertEquals(1, this.fontActiveCalled_);
|
320
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
321
|
+
};
|
322
|
+
|
323
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithEqualMetrics = function() {
|
324
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
325
|
+
this.timesToDelayChangedSizeWebkit_ = 2;
|
326
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
327
|
+
|
328
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
329
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizerWithEqualMetrics_,
|
330
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
331
|
+
this.fontDescription_, true);
|
166
332
|
|
333
|
+
fontWatchRunner.start();
|
167
334
|
assertEquals(9, this.asyncCount_);
|
335
|
+
assertEquals(1, this.fontActiveCalled_);
|
336
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
337
|
+
};
|
168
338
|
|
169
|
-
|
339
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithDifferentMetrics = function() {
|
340
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
341
|
+
this.timesToDelayChangedSizeWebkit_ = 2;
|
342
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
343
|
+
|
344
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
345
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizeWithDifferentMetrics_,
|
346
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
347
|
+
this.fontDescription_, true);
|
348
|
+
|
349
|
+
fontWatchRunner.start();
|
350
|
+
assertEquals(2, this.asyncCount_);
|
351
|
+
assertEquals(1, this.fontActiveCalled_);
|
352
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
353
|
+
};
|
354
|
+
|
355
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitFailedLoad = function() {
|
356
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
357
|
+
this.timesToDelayChangedSizeWebkit_ = 5;
|
358
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
359
|
+
|
360
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
361
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizerFailedLoad_,
|
362
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
363
|
+
this.fontDescription_, true);
|
364
|
+
|
365
|
+
fontWatchRunner.start();
|
366
|
+
assertEquals(9, this.asyncCount_);
|
367
|
+
assertEquals(1, this.fontActiveCalled_);
|
368
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
369
|
+
};
|
370
|
+
|
371
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithEqualMetricsIncompatibleFont = function() {
|
372
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
373
|
+
this.timesToDelayChangedSizeWebkit_ = 2;
|
374
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
375
|
+
|
376
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
377
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizerWithEqualMetrics_,
|
378
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
379
|
+
this.fontDescription_, true, { 'fontFamily2': true });
|
380
|
+
|
381
|
+
fontWatchRunner.start();
|
382
|
+
assertEquals(9, this.asyncCount_);
|
170
383
|
assertEquals(1, this.fontInactiveCalled_);
|
171
384
|
assertEquals(true, this.fontInactive_['fontFamily1 n4']);
|
172
385
|
};
|
173
386
|
|
387
|
+
FontWatchRunnerTest.prototype.testWatchFontWebkitWithEqualMetricsCompatibleFont = function() {
|
388
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
389
|
+
this.timesToDelayChangedSizeWebkit_ = 2;
|
390
|
+
this.firstCallToRetrieveSizeWebkit_ = true;
|
391
|
+
|
392
|
+
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
393
|
+
this.inactiveCallback_, this.fakeDomHelper_, this.fakeWebkitFontSizerWithEqualMetrics_,
|
394
|
+
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
395
|
+
this.fontDescription_, true, { 'fontFamily1': true });
|
396
|
+
|
397
|
+
fontWatchRunner.start();
|
398
|
+
assertEquals(9, this.asyncCount_);
|
399
|
+
assertEquals(1, this.fontActiveCalled_);
|
400
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
401
|
+
};
|
402
|
+
|
403
|
+
|
174
404
|
FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
|
175
|
-
this.
|
176
|
-
this.timesToReportChangedWidth_ = 2;
|
405
|
+
this.timesToCheckSizesBeforeChange_ = 3;
|
177
406
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
178
407
|
|
179
408
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
180
409
|
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
|
181
410
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
182
|
-
this.fontDescription_);
|
411
|
+
this.fontDescription_, false);
|
183
412
|
|
184
413
|
fontWatchRunner.start();
|
185
|
-
|
186
|
-
assertEquals(4, this.createElementCalled_);
|
414
|
+
assertEquals(3, this.createElementCalled_);
|
187
415
|
assertEquals('span', this.createdElements_[0]['name']);
|
188
|
-
|
189
|
-
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.
|
416
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf('fontFamily1'));
|
417
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.LastResortFonts.SERIF));
|
190
418
|
assertEquals('BESbswy', this.createdElements_[0]['innerHtml']);
|
419
|
+
|
191
420
|
assertEquals('span', this.createdElements_[1]['name']);
|
192
|
-
|
193
|
-
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.
|
421
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf('fontFamily1'));
|
422
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.LastResortFonts.SANS_SERIF));
|
194
423
|
assertEquals('BESbswy', this.createdElements_[1]['innerHtml']);
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
assertEquals('BESbswy', this.createdElements_[2]['innerHtml']);
|
199
|
-
assertEquals('span', this.createdElements_[3]['name']);
|
200
|
-
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf('fontFamily1'));
|
201
|
-
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
202
|
-
assertEquals('BESbswy', this.createdElements_[3]['innerHtml']);
|
203
|
-
assertEquals(4, this.insertIntoCalled_);
|
204
|
-
assertEquals(4, this.removeElementCalled_);
|
424
|
+
|
425
|
+
assertEquals(3, this.insertIntoCalled_);
|
426
|
+
assertEquals(3, this.removeElementCalled_);
|
205
427
|
};
|
206
428
|
|
207
429
|
FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
|
208
|
-
this.
|
209
|
-
this.timesToReportChangedWidth_ = 2;
|
430
|
+
this.timesToCheckSizesBeforeChange_ = 3;
|
210
431
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
211
432
|
|
212
433
|
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
|
213
434
|
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
|
214
435
|
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
|
215
|
-
this.fontDescription_, 'testString');
|
436
|
+
this.fontDescription_, false, null, 'testString');
|
216
437
|
|
217
438
|
fontWatchRunner.start();
|
218
439
|
|
219
|
-
assertEquals(
|
440
|
+
assertEquals(3, this.createElementCalled_);
|
220
441
|
assertEquals('span', this.createdElements_[0]['name']);
|
221
|
-
|
222
|
-
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.
|
442
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf('fontFamily1'));
|
443
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.LastResortFonts.SERIF));
|
223
444
|
assertEquals('testString', this.createdElements_[0]['innerHtml']);
|
445
|
+
|
224
446
|
assertEquals('span', this.createdElements_[1]['name']);
|
225
|
-
|
226
|
-
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.
|
447
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf('fontFamily1'));
|
448
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.LastResortFonts.SANS_SERIF));
|
227
449
|
assertEquals('testString', this.createdElements_[1]['innerHtml']);
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
assertEquals('testString', this.createdElements_[2]['innerHtml']);
|
232
|
-
assertEquals('span', this.createdElements_[3]['name']);
|
233
|
-
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf('fontFamily1'));
|
234
|
-
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
235
|
-
assertEquals('testString', this.createdElements_[3]['innerHtml']);
|
236
|
-
assertEquals(4, this.insertIntoCalled_);
|
237
|
-
assertEquals(4, this.removeElementCalled_);
|
450
|
+
|
451
|
+
assertEquals(3, this.insertIntoCalled_);
|
452
|
+
assertEquals(3, this.removeElementCalled_);
|
238
453
|
|
239
454
|
};
|