@@ -19,6 +19,9 @@ FontWatchRunnerTest.prototype.setUp = function() {
19
19
self . fontInactive_ [ fontFamily + ' ' + fontDescription ] = true ;
20
20
} ;
21
21
22
+ this . fakeFirefoxUserAgent_ = new webfont . UserAgent ( 'Firefox' , '3.6' , 'Gecko' ,
23
+ '1.9.2' , 'Macintosh' , '10.6' , undefined , true ) ;
24
+
22
25
this . createElementCalled_ = 0 ;
23
26
this . createdElements_ = [ ] ;
24
27
this . insertIntoCalled_ = 0 ;
@@ -45,6 +48,8 @@ FontWatchRunnerTest.prototype.setUp = function() {
45
48
} ,
46
49
removeElement : function ( el ) {
47
50
self . removeElementCalled_ ++ ;
51
+ } ,
52
+ setStyle : function ( e , styleString ) {
48
53
}
49
54
} ;
50
55
@@ -84,17 +89,17 @@ FontWatchRunnerTest.prototype.setUp = function() {
84
89
self . asyncCount_ ++ ;
85
90
func ( ) ;
86
91
} ;
87
-
88
92
} ;
89
93
90
94
FontWatchRunnerTest . prototype . testWatchFontAlreadyLoaded = function ( ) {
91
- this . timesToCheckWidthsBeforeChange_ = 0 ;
95
+ this . timesToCheckWidthsBeforeChange_ = 1 ;
92
96
this . timesToReportChangedWidth_ = 2 ;
93
97
this . timesToGetTimeBeforeTimeout_ = 10 ;
94
98
95
99
new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
96
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
97
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ ) ;
100
+ this . fakeFirefoxUserAgent_ , this . fakeDomHelper_ , this . fakeFontSizer_ ,
101
+ this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
102
+ this . fontDescription_ ) ;
98
103
99
104
assertEquals ( 1 , this . asyncCount_ ) ;
100
105
@@ -104,15 +109,16 @@ FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
104
109
} ;
105
110
106
111
FontWatchRunnerTest . prototype . testWatchFontWaitForLoadActive = function ( ) {
107
- this . timesToCheckWidthsBeforeChange_ = 3 ;
112
+ this . timesToCheckWidthsBeforeChange_ = 2 ;
108
113
this . timesToReportChangedWidth_ = 2 ;
109
114
this . timesToGetTimeBeforeTimeout_ = 10 ;
110
115
111
116
new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
112
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
113
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ ) ;
117
+ this . fakeFirefoxUserAgent_ , this . fakeDomHelper_ , this . fakeFontSizer_ ,
118
+ this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
119
+ this . fontDescription_ ) ;
114
120
115
- assertEquals ( 4 , this . asyncCount_ ) ;
121
+ assertEquals ( 2 , this . asyncCount_ ) ;
116
122
117
123
assertEquals ( 1 , this . fontActiveCalled_ ) ;
118
124
assertEquals ( true , this . fontActive_ [ 'fontFamily1 n4' ] ) ;
@@ -125,8 +131,9 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
125
131
this . timesToGetTimeBeforeTimeout_ = 5 ;
126
132
127
133
new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
128
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
129
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ ) ;
134
+ this . fakeFirefoxUserAgent_ , this . fakeDomHelper_ , this . fakeFontSizer_ ,
135
+ this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
136
+ this . fontDescription_ ) ;
130
137
131
138
assertEquals ( 4 , this . asyncCount_ ) ;
132
139
@@ -135,38 +142,15 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
135
142
assertEquals ( true , this . fontInactive_ [ 'fontFamily1 n4' ] ) ;
136
143
} ;
137
144
138
- /**
139
- * This test ensures that even if the fonts change width for one cycle and
140
- * then change back, active won't be fired. This works around an issue in Webkit
141
- * browsers, where an inactive webfont will briefly change widths for one cycle
142
- * and then change back to fallback widths on the next cycle. This is apparently
143
- * due to some quirk in the way that web fonts are rendered.
144
- */
145
- FontWatchRunnerTest . prototype . testWatchFontWithInconsistentWidthIsStillInactive = function ( ) {
146
- this . timesToCheckWidthsBeforeChange_ = 3 ;
147
- // Only report a new width for one cycle, then switch back to original fallback width
148
- this . timesToReportChangedWidth_ = 1 ;
149
- this . timesToGetTimeBeforeTimeout_ = 10 ;
150
-
151
- new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
152
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
153
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ ) ;
154
-
155
- assertEquals ( 9 , this . asyncCount_ ) ;
156
-
157
- assertEquals ( 0 , this . fontActiveCalled_ ) ;
158
- assertEquals ( 1 , this . fontInactiveCalled_ ) ;
159
- assertEquals ( true , this . fontInactive_ [ 'fontFamily1 n4' ] ) ;
160
- } ;
161
-
162
145
FontWatchRunnerTest . prototype . testDomWithDefaultTestString = function ( ) {
163
146
this . timesToCheckWidthsBeforeChange_ = 3 ;
164
147
this . timesToReportChangedWidth_ = 2 ;
165
148
this . timesToGetTimeBeforeTimeout_ = 10 ;
166
149
167
150
new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
168
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
169
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ ) ;
151
+ this . fakeFirefoxUserAgent_ , this . fakeDomHelper_ , this . fakeFontSizer_ ,
152
+ this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
153
+ this . fontDescription_ ) ;
170
154
171
155
assertEquals ( 4 , this . createElementCalled_ ) ;
172
156
assertEquals ( 'span' , this . createdElements_ [ 0 ] [ 'name' ] ) ;
@@ -196,8 +180,9 @@ FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
196
180
this . timesToGetTimeBeforeTimeout_ = 10 ;
197
181
198
182
new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
199
- this . fakeDomHelper_ , this . fakeFontSizer_ , this . fakeAsyncCall_ ,
200
- this . fakeGetTime_ , this . fontFamily_ , this . fontDescription_ , 'testString' ) ;
183
+ this . fakeFirefoxUserAgent_ , this . fakeDomHelper_ , this . fakeFontSizer_ ,
184
+ this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
185
+ this . fontDescription_ , 'testString' ) ;
201
186
202
187
assertEquals ( 4 , this . createElementCalled_ ) ;
203
188
assertEquals ( 'span' , this . createdElements_ [ 0 ] [ 'name' ] ) ;
@@ -218,5 +203,80 @@ FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
218
203
assertEquals ( 'testString' , this . createdElements_ [ 3 ] [ 'innerHtml' ] ) ;
219
204
assertEquals ( 4 , this . insertIntoCalled_ ) ;
220
205
assertEquals ( 4 , this . removeElementCalled_ ) ;
206
+ } ;
207
+
208
+ FontWatchRunnerTest . prototype . testWatchFontWebKitBrowserIgnoreLastResort = function ( ) {
209
+ var userAgent = new webfont . UserAgent ( 'Chrome' , '16.0.912.36' , 'AppleWebKit' ,
210
+ '531.9' , 'Macintosh' , '10.6' , undefined , true ) ;
211
+ var lastResortFontsCount = 12 ;
212
+ var originalSizeCount = 2 ;
213
+ var firstSize = 2 ;
214
+ var secondSize = 2 ;
215
+ var thirdSize = 3 ;
216
+
217
+ new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
218
+ userAgent , this . fakeDomHelper_ , { getWidth : function ( ) {
219
+ if ( lastResortFontsCount -- > 0 ) {
220
+ return 2 ;
221
+ }
222
+ if ( originalSizeCount -- > 0 ) {
223
+ return 1 ;
224
+ }
225
+ if ( firstSize -- > 0 ) {
226
+ return 1 ;
227
+ }
228
+ if ( secondSize -- > 0 ) {
229
+
230
+ return 2 ;
231
+ }
232
+ if ( thirdSize -- > 0 ) {
233
+ return 3 ;
234
+ }
235
+ } } , this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
236
+ this . fontDescription_ ) ;
237
+
238
+ assertEquals ( 2 , this . asyncCount_ ) ;
221
239
240
+ assertEquals ( 1 , this . fontActiveCalled_ ) ;
241
+ assertEquals ( 0 , this . fontInactiveCalled_ ) ;
242
+ assertEquals ( true , this . fontActive_ [ 'fontFamily1 n4' ] ) ;
243
+ } ;
244
+
245
+ FontWatchRunnerTest . prototype . testWatchFontWebKitBrowserIgnoreLastResort = function ( ) {
246
+ this . timesToGetTimeBeforeTimeout_ = 3 ;
247
+ var userAgent = new webfont . UserAgent ( 'Chrome' , '16.0.912.36' , 'AppleWebKit' ,
248
+ '531.9' , 'Macintosh' , '10.6' , undefined , true ) ;
249
+ var lastResortFontsCount = 12 ;
250
+ var originalSizeCount = 2 ;
251
+ var firstSize = 2 ;
252
+ var secondSize = 2 ;
253
+ var thirdSize = 3 ;
254
+
255
+ new webfont . FontWatchRunner ( this . activeCallback_ , this . inactiveCallback_ ,
256
+ userAgent , this . fakeDomHelper_ , { getWidth : function ( ) {
257
+ if ( lastResortFontsCount -- > 0 ) {
258
+ return 2 ;
259
+ }
260
+ if ( originalSizeCount -- > 0 ) {
261
+ return 1 ;
262
+ }
263
+ if ( firstSize -- > 0 ) {
264
+ return 1 ;
265
+ }
266
+ if ( secondSize -- > 0 ) {
267
+
268
+ return 2 ;
269
+ }
270
+ if ( thirdSize -- > 0 ) {
271
+ return 3 ;
272
+ }
273
+ } } , this . fakeAsyncCall_ , this . fakeGetTime_ , this . fontFamily_ ,
274
+ this . fontDescription_ ) ;
275
+
276
+ assertEquals ( 2 , this . asyncCount_ ) ;
277
+
278
+ // When on webkit time out ends up activating the font.
279
+ assertEquals ( 1 , this . fontActiveCalled_ ) ;
280
+ assertEquals ( 0 , this . fontInactiveCalled_ ) ;
281
+ assertEquals ( true , this . fontActive_ [ 'fontFamily1 n4' ] ) ;
222
282
} ;
0 commit comments