webfontloader 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/src/core/useragentparser.js
CHANGED
@@ -35,7 +35,7 @@ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
|
|
35
35
|
webfont.UserAgentParser.UNKNOWN,
|
36
36
|
webfont.UserAgentParser.UNKNOWN,
|
37
37
|
undefined,
|
38
|
-
false);
|
38
|
+
new webfont.BrowserInfo(false, false));
|
39
39
|
|
40
40
|
/**
|
41
41
|
* Parses the user agent string and returns an object.
|
@@ -128,7 +128,7 @@ webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
|
|
128
128
|
// instead of the specific Trident engine name and version
|
129
129
|
|
130
130
|
var platform = this.getPlatform_();
|
131
|
-
var
|
131
|
+
var platformVersionString = this.getPlatformVersion_();
|
132
132
|
|
133
133
|
var browser = this.getMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/, 1);
|
134
134
|
|
@@ -136,20 +136,18 @@ webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
|
|
136
136
|
var pair = browser.split(' ');
|
137
137
|
var name = pair[0];
|
138
138
|
var version = pair[1];
|
139
|
-
var
|
140
|
-
var
|
141
|
-
|
142
|
-
|
143
|
-
(platform == "Windows Phone" && majorPlatformVersion >= 8);
|
139
|
+
var browserVersion = this.parseVersion_(version);
|
140
|
+
var platformVersion = this.parseVersion_(platformVersionString);
|
141
|
+
var supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
|
142
|
+
(platform == "Windows Phone" && platformVersion.major >= 8);
|
144
143
|
|
145
144
|
return new webfont.UserAgent(name, version, name, version,
|
146
|
-
platform,
|
147
|
-
supportWebFont);
|
145
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(supportWebFont, false));
|
148
146
|
}
|
149
147
|
|
150
148
|
return new webfont.UserAgent("MSIE", webfont.UserAgentParser.UNKNOWN,
|
151
149
|
"MSIE", webfont.UserAgentParser.UNKNOWN,
|
152
|
-
platform,
|
150
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(false, false));
|
153
151
|
};
|
154
152
|
|
155
153
|
/**
|
@@ -194,29 +192,31 @@ webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
|
|
194
192
|
|
195
193
|
return new webfont.UserAgent("OperaMini", version, engineName,
|
196
194
|
engineVersion, this.getPlatform_(), this.getPlatformVersion_(),
|
197
|
-
this.getDocumentMode_(this.doc_), false);
|
195
|
+
this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(false, false));
|
198
196
|
}
|
199
197
|
|
200
198
|
// Otherwise, find version information for normal Opera or Opera Mobile
|
201
199
|
if (this.userAgent_.indexOf("Version/") != -1) {
|
202
|
-
var
|
200
|
+
var versionString = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);
|
203
201
|
|
204
|
-
if (
|
205
|
-
|
202
|
+
if (versionString != "") {
|
203
|
+
var version = this.parseVersion_(versionString);
|
204
|
+
return new webfont.UserAgent("Opera", versionString, engineName, engineVersion,
|
206
205
|
this.getPlatform_(), this.getPlatformVersion_(),
|
207
|
-
this.getDocumentMode_(this.doc_),
|
206
|
+
this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(version.major >= 10, false));
|
208
207
|
}
|
209
208
|
}
|
210
|
-
var
|
209
|
+
var versionString = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
|
211
210
|
|
212
|
-
if (
|
213
|
-
|
211
|
+
if (versionString != "") {
|
212
|
+
var version = this.parseVersion_(versionString);
|
213
|
+
return new webfont.UserAgent("Opera", versionString, engineName, engineVersion,
|
214
214
|
this.getPlatform_(), this.getPlatformVersion_(),
|
215
|
-
this.getDocumentMode_(this.doc_),
|
215
|
+
this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(version.major >= 10, false));
|
216
216
|
}
|
217
217
|
return new webfont.UserAgent("Opera", webfont.UserAgentParser.UNKNOWN,
|
218
218
|
engineName, engineVersion, this.getPlatform_(),
|
219
|
-
this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), false);
|
219
|
+
this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(false, false));
|
220
220
|
};
|
221
221
|
|
222
222
|
/**
|
@@ -231,13 +231,18 @@ webfont.UserAgentParser.prototype.isWebKit_ = function() {
|
|
231
231
|
*/
|
232
232
|
webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
233
233
|
var platform = this.getPlatform_();
|
234
|
-
var
|
235
|
-
var
|
234
|
+
var platformVersionString = this.getPlatformVersion_();
|
235
|
+
var webKitVersionString = this.getMatchingGroup_(this.userAgent_,
|
236
236
|
/AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1);
|
237
|
+
var supportWebFont = false;
|
237
238
|
|
238
|
-
if (
|
239
|
-
|
239
|
+
if (webKitVersionString == "") {
|
240
|
+
webKitVersionString = webfont.UserAgentParser.UNKNOWN;
|
240
241
|
}
|
242
|
+
|
243
|
+
var webKitVersion = this.parseVersion_(webKitVersionString);
|
244
|
+
var platformVersion = this.parseVersion_(platformVersionString);
|
245
|
+
|
241
246
|
var name = webfont.UserAgentParser.UNKNOWN;
|
242
247
|
|
243
248
|
if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
|
@@ -263,23 +268,21 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
|
263
268
|
version = this.getMatchingGroup_(this.userAgent_,
|
264
269
|
/AdobeAIR\/([\d\.]+)/, 1);
|
265
270
|
}
|
266
|
-
var supportWebFont = false;
|
267
271
|
if (name == "AdobeAIR") {
|
268
|
-
var
|
269
|
-
supportWebFont =
|
270
|
-
this.getMajorVersion_(version) == 2 && parseInt(minor, 10) >= 5;
|
272
|
+
var browserVersion = this.parseVersion_(version);
|
273
|
+
supportWebFont = browserVersion.major > 2 || browserVersion.major == 2 && browserVersion.minor >= 5;
|
271
274
|
} else if (platform == "BlackBerry") {
|
272
|
-
supportWebFont =
|
275
|
+
supportWebFont = platformVersion.major >= 10;
|
273
276
|
} else if (platform == "Android") {
|
274
|
-
supportWebFont =
|
277
|
+
supportWebFont = platformVersion.major > 2 || (platformVersion.major == 2 && platformVersion.minor > 1);
|
275
278
|
} else {
|
276
|
-
|
277
|
-
supportWebFont = this.getMajorVersion_(webKitVersion) >= 526 ||
|
278
|
-
this.getMajorVersion_(webKitVersion) >= 525 && parseInt(minor, 10) >= 13;
|
279
|
+
supportWebFont = webKitVersion.major >= 526 || webKitVersion.major >= 525 && webKitVersion.minor >= 13;
|
279
280
|
}
|
280
281
|
|
281
|
-
|
282
|
-
|
282
|
+
var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11);
|
283
|
+
|
284
|
+
return new webfont.UserAgent(name, version, "AppleWebKit", webKitVersionString,
|
285
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(supportWebFont, hasWebKitFallbackBug));
|
283
286
|
};
|
284
287
|
|
285
288
|
/**
|
@@ -303,47 +306,47 @@ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
|
|
303
306
|
/Firefox\/([\d\w\.]+)/, 1);
|
304
307
|
|
305
308
|
if (versionNum != "") {
|
306
|
-
var
|
309
|
+
var firefoxVersion = this.parseVersion_(versionNum);
|
307
310
|
|
308
311
|
version = versionNum;
|
309
|
-
supportWebFont =
|
310
|
-
|
312
|
+
supportWebFont = firefoxVersion.major >= 3 &&
|
313
|
+
firefoxVersion.minor >= 5;
|
311
314
|
}
|
312
315
|
} else if (this.userAgent_.indexOf("Mozilla") != -1) {
|
313
316
|
name = "Mozilla";
|
314
317
|
}
|
315
|
-
var
|
318
|
+
var geckoVersionString = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
|
316
319
|
|
317
|
-
if (
|
318
|
-
|
320
|
+
if (geckoVersionString == "") {
|
321
|
+
geckoVersionString = webfont.UserAgentParser.UNKNOWN;
|
319
322
|
} else {
|
320
323
|
if (!supportWebFont) {
|
321
|
-
var
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
geckoVersion.match(/1\.9\.1b[123]/) != null ||
|
329
|
-
geckoVersion.match(/1\.9\.1\.[\d\.]+/) != null;
|
324
|
+
var geckoVersion = this.parseVersion_(geckoVersionString);
|
325
|
+
|
326
|
+
supportWebFont = geckoVersion.major > 1 ||
|
327
|
+
geckoVersion.major == 1 && geckoVersion.minor > 9 ||
|
328
|
+
geckoVersion.major == 1 && geckoVersion.minor == 9 && geckoVersion.patch >= 2 ||
|
329
|
+
geckoVersionString.match(/1\.9\.1b[123]/) != null ||
|
330
|
+
geckoVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
|
330
331
|
}
|
331
332
|
}
|
332
|
-
return new webfont.UserAgent(name, version, "Gecko",
|
333
|
-
this.getPlatform_(), this.getPlatformVersion_(), this.getDocumentMode_(this.doc_),
|
334
|
-
supportWebFont);
|
333
|
+
return new webfont.UserAgent(name, version, "Gecko", geckoVersionString,
|
334
|
+
this.getPlatform_(), this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(supportWebFont, false));
|
335
335
|
};
|
336
336
|
|
337
337
|
/**
|
338
338
|
* @private
|
339
339
|
*/
|
340
|
-
webfont.UserAgentParser.prototype.
|
341
|
-
var
|
342
|
-
|
343
|
-
|
344
|
-
|
340
|
+
webfont.UserAgentParser.prototype.parseVersion_ = function(version) {
|
341
|
+
var m = /([0-9]+)(?:\.([0-9]+)(?:\.([0-9]+)?)?)?/.exec(version),
|
342
|
+
result = {};
|
343
|
+
|
344
|
+
if (m) {
|
345
|
+
result.major = parseInt(m[1] || -1, 10);
|
346
|
+
result.minor = parseInt(m[2] || -1, 10);
|
347
|
+
result.patch = parseInt(m[3] || -1, 10);
|
345
348
|
}
|
346
|
-
return
|
349
|
+
return result;
|
347
350
|
};
|
348
351
|
|
349
352
|
/**
|
data/src/custom/customcss.js
CHANGED
@@ -16,19 +16,36 @@ webfont.CustomCss = function(domHelper, configuration) {
|
|
16
16
|
webfont.CustomCss.NAME = 'custom';
|
17
17
|
|
18
18
|
webfont.CustomCss.prototype.load = function(onReady) {
|
19
|
+
var i, len;
|
19
20
|
var urls = this.configuration_['urls'] || [];
|
20
|
-
var
|
21
|
+
var familiesConfiguration = this.configuration_['families'] || [];
|
21
22
|
|
22
|
-
for (
|
23
|
+
for (i = 0, len = urls.length; i < len; i++) {
|
23
24
|
var url = urls[i];
|
24
25
|
|
25
26
|
this.domHelper_.insertInto('head', this.domHelper_.createCssLink(url));
|
26
27
|
}
|
27
|
-
|
28
|
+
|
29
|
+
var families = [];
|
30
|
+
var variations = {};
|
31
|
+
for (i = 0, len = familiesConfiguration.length; i < len; i++) {
|
32
|
+
var components = familiesConfiguration[i].split(":");
|
33
|
+
var family = components[0];
|
34
|
+
var familyVariations = components[1];
|
35
|
+
|
36
|
+
families.push(family);
|
37
|
+
|
38
|
+
if (familyVariations) {
|
39
|
+
var newVariations = familyVariations.split(",");
|
40
|
+
variations[family] = (variations[family] || []).concat(newVariations);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
onReady(families, variations);
|
28
45
|
};
|
29
46
|
|
30
47
|
webfont.CustomCss.prototype.supportUserAgent = function(userAgent, support) {
|
31
|
-
return support(userAgent.
|
48
|
+
return support(userAgent.getBrowserInfo().hasWebFontSupport());
|
32
49
|
};
|
33
50
|
|
34
51
|
globalNamespaceObject.addModule(webfont.CustomCss.NAME, function(configuration, domHelper) {
|
data/src/google/googlefontapi.js
CHANGED
@@ -10,7 +10,7 @@ webfont.GoogleFontApi = function(userAgent, domHelper, configuration) {
|
|
10
10
|
webfont.GoogleFontApi.NAME = 'google';
|
11
11
|
|
12
12
|
webfont.GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
|
13
|
-
support(userAgent.
|
13
|
+
support(userAgent.getBrowserInfo().hasWebFontSupport());
|
14
14
|
};
|
15
15
|
|
16
16
|
webfont.GoogleFontApi.prototype.getFontWatchRunnerCtor = function() {
|
@@ -3,22 +3,25 @@
|
|
3
3
|
* @param {function(string, string)} activeCallback
|
4
4
|
* @param {function(string, string)} inactiveCallback
|
5
5
|
* @param {webfont.DomHelper} domHelper
|
6
|
-
* @param {Object.<string, function(Object):
|
6
|
+
* @param {Object.<string, function(Object): webfont.Size>} fontSizer
|
7
7
|
* @param {function(function(), number=)} asyncCall
|
8
8
|
* @param {function(): number} getTime
|
9
9
|
* @param {string} fontFamily
|
10
10
|
* @param {string} fontDescription
|
11
|
+
* @param {boolean} hasWebkitFallbackBug
|
11
12
|
* @param {string=} opt_fontTestString
|
12
13
|
* @extends webfont.FontWatchRunner
|
13
14
|
*/
|
14
15
|
webfont.LastResortWebKitFontWatchRunner = function(activeCallback,
|
15
16
|
inactiveCallback, domHelper, fontSizer, asyncCall, getTime, fontFamily,
|
16
|
-
fontDescription, opt_fontTestString) {
|
17
|
+
fontDescription, hasWebkitFallbackBug, opt_fontTestString) {
|
17
18
|
webfont.LastResortWebKitFontWatchRunner.superCtor_.call(this,
|
18
19
|
activeCallback, inactiveCallback, domHelper, fontSizer, asyncCall,
|
19
|
-
getTime, fontFamily, fontDescription, opt_fontTestString);
|
20
|
+
getTime, fontFamily, fontDescription, hasWebkitFallbackBug, opt_fontTestString);
|
20
21
|
this.webKitLastResortFontSizes_ = this.setUpWebKitLastResortFontSizes_();
|
21
22
|
this.webKitLastResortSizeChange_ = false;
|
23
|
+
this.lastObservedSizeA_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SERIF];
|
24
|
+
this.lastObservedSizeB_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
|
22
25
|
};
|
23
26
|
webfont.extendsClass(webfont.FontWatchRunner, webfont.LastResortWebKitFontWatchRunner);
|
24
27
|
|
@@ -41,40 +44,41 @@ webfont.LastResortWebKitFontWatchRunner.prototype
|
|
41
44
|
var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
|
42
45
|
var lastResortFontSizes = lastResortFonts.length;
|
43
46
|
var webKitLastResortFontSizes = {};
|
44
|
-
var
|
47
|
+
var fontRuler = new webfont.FontRuler(this.domHelper_, this.fontSizer_, this.fontTestString_);
|
45
48
|
|
46
|
-
|
49
|
+
fontRuler.insert();
|
50
|
+
fontRuler.setFont(lastResortFonts[0], this.fontDescription_);
|
51
|
+
|
52
|
+
webKitLastResortFontSizes[fontRuler.getSize().width] = true;
|
47
53
|
for (var i = 1; i < lastResortFontSizes; i++) {
|
48
54
|
var font = lastResortFonts[i];
|
49
|
-
|
50
|
-
|
51
|
-
webKitLastResortFontSizes[this.fontSizer_.getWidth(element)] = true;
|
55
|
+
fontRuler.setFont(font, this.fontDescription_);
|
56
|
+
webKitLastResortFontSizes[fontRuler.getSize().width] = true;
|
52
57
|
|
53
58
|
// Another WebKit quirk if the normal weight/style is loaded first,
|
54
59
|
// the size of the normal weight is returned when loading another weight.
|
55
60
|
if (this.fontDescription_[1] != '4') {
|
56
|
-
|
57
|
-
|
58
|
-
webKitLastResortFontSizes[this.fontSizer_.getWidth(element)] = true;
|
61
|
+
fontRuler.setFont(font, this.fontDescription_[0] + '4');
|
62
|
+
webKitLastResortFontSizes[fontRuler.getSize().width] = true;
|
59
63
|
}
|
60
64
|
}
|
61
|
-
|
65
|
+
fontRuler.remove();
|
62
66
|
return webKitLastResortFontSizes;
|
63
67
|
};
|
64
68
|
|
65
69
|
webfont.LastResortWebKitFontWatchRunner.prototype.check_ = function() {
|
66
|
-
var sizeA = this.
|
67
|
-
var sizeB = this.
|
70
|
+
var sizeA = this.fontRulerA_.getSize();
|
71
|
+
var sizeB = this.fontRulerB_.getSize();
|
68
72
|
|
69
|
-
if (!this.webKitLastResortSizeChange_ && sizeA == sizeB &&
|
70
|
-
this.webKitLastResortFontSizes_[sizeA]) {
|
73
|
+
if (!this.webKitLastResortSizeChange_ && sizeA.width == sizeB.width &&
|
74
|
+
this.webKitLastResortFontSizes_[sizeA.width]) {
|
71
75
|
this.webKitLastResortFontSizes_ = {};
|
72
|
-
this.webKitLastResortFontSizes_[sizeA] = true;
|
76
|
+
this.webKitLastResortFontSizes_[sizeA.width] = true;
|
73
77
|
this.webKitLastResortSizeChange_ = true;
|
74
78
|
}
|
75
|
-
if ((this.
|
76
|
-
(!this.webKitLastResortFontSizes_[sizeA] &&
|
77
|
-
!this.webKitLastResortFontSizes_[sizeB])) {
|
79
|
+
if ((this.lastObservedSizeA_.width != sizeA.width || this.lastObservedSizeB_.width != sizeB.width) &&
|
80
|
+
(!this.webKitLastResortFontSizes_[sizeA.width] &&
|
81
|
+
!this.webKitLastResortFontSizes_[sizeB.width])) {
|
78
82
|
this.finish_(this.activeCallback_);
|
79
83
|
} else if (this.getTime_() - this.started_ >= 5000) {
|
80
84
|
|
@@ -82,8 +86,8 @@ webfont.LastResortWebKitFontWatchRunner.prototype.check_ = function() {
|
|
82
86
|
// default browser font on a webkit browser, mark the font as active
|
83
87
|
// after 5 seconds if the latest 2 sizes are in webKitLastResortFontSizes_
|
84
88
|
// and the font name is known to be metrics compatible.
|
85
|
-
if (this.webKitLastResortFontSizes_[sizeA]
|
86
|
-
&& this.webKitLastResortFontSizes_[sizeB] &&
|
89
|
+
if (this.webKitLastResortFontSizes_[sizeA.width]
|
90
|
+
&& this.webKitLastResortFontSizes_[sizeB.width] &&
|
87
91
|
webfont.LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
|
88
92
|
this.fontFamily_]) {
|
89
93
|
this.finish_(this.activeCallback_);
|
data/src/modules.yml
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
core:
|
2
2
|
- core/namespace.js
|
3
3
|
- core/domhelper.js
|
4
|
+
- core/browserinfo.js
|
4
5
|
- core/useragent.js
|
5
6
|
- core/useragentparser.js
|
6
7
|
- core/eventdispatcher.js
|
7
8
|
- core/fontmoduleloader.js
|
9
|
+
- core/size.js
|
8
10
|
- core/fontwatcher.js
|
9
11
|
- core/fontwatchrunner.js
|
12
|
+
- core/fontruler.js
|
10
13
|
- core/font.js
|
11
14
|
- core/cssclassname.js
|
12
15
|
- core/cssfontfamilyname.js
|
data/src-test/core/fonttest.js
CHANGED
@@ -5,8 +5,9 @@ FontTest.prototype.setUp = function() {
|
|
5
5
|
};
|
6
6
|
|
7
7
|
FontTest.prototype.testFontLoad = function() {
|
8
|
+
var browserInfo = new webfont.BrowserInfo(true, false);
|
8
9
|
var userAgent = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2',
|
9
|
-
'Macintosh', '10.6', undefined,
|
10
|
+
'Macintosh', '10.6', undefined, browserInfo);
|
10
11
|
var font = new webfont.WebFont(window, this.fontModuleLoader_,
|
11
12
|
function(func, timeout) { func(); }, userAgent);
|
12
13
|
var testModule = null;
|
@@ -59,9 +60,9 @@ FontTest.prototype.testFontLoad = function() {
|
|
59
60
|
|
60
61
|
FontTest.prototype.testFontLoadWithContext = function() {
|
61
62
|
var fakeMainWindow = {};
|
62
|
-
|
63
|
+
var browserInfo = new webfont.BrowserInfo(true, false);
|
63
64
|
var userAgent = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2',
|
64
|
-
'Macintosh', '10.6', undefined,
|
65
|
+
'Macintosh', '10.6', undefined, browserInfo);
|
65
66
|
var font = new webfont.WebFont(fakeMainWindow, this.fontModuleLoader_,
|
66
67
|
function(func, timeout) { func(); }, userAgent);
|
67
68
|
var testModule = null;
|
@@ -91,7 +92,8 @@ FontTest.prototype.testFontLoadWithContext = function() {
|
|
91
92
|
};
|
92
93
|
|
93
94
|
FontTest.prototype.testFontInactive = function() {
|
94
|
-
var userAgent = new webfont.UserAgent('Firefox', '3.0',
|
95
|
+
var userAgent = new webfont.UserAgent('Firefox', '3.0', 'Gecko', '1.9.2',
|
96
|
+
'Macintosh', '10.6', undefined, new webfont.BrowserInfo(false, false));
|
95
97
|
var font = new webfont.WebFont(window, this.fontModuleLoader_,
|
96
98
|
function(func, timeout) { func(); }, userAgent);
|
97
99
|
var testModule;
|
@@ -35,9 +35,21 @@ FontWatcherTest.prototype.setUp = function() {
|
|
35
35
|
}
|
36
36
|
};
|
37
37
|
|
38
|
+
this.fakeDomHelper_ = {
|
39
|
+
createElement: function(name, attrs, innerHtml) {
|
40
|
+
var element = document.createElement(name);
|
41
|
+
return element;
|
42
|
+
},
|
43
|
+
insertInto: function() {},
|
44
|
+
removeElement: function() {},
|
45
|
+
setStyle: function() {}
|
46
|
+
};
|
47
|
+
|
48
|
+
this.userAgent_ = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new webfont.BrowserInfo(false, false));
|
49
|
+
|
38
50
|
this.fakeFontSizer_ = {
|
39
|
-
|
40
|
-
fail('Fake
|
51
|
+
getSize: function() {
|
52
|
+
fail('Fake getSize should not be called.');
|
41
53
|
}
|
42
54
|
};
|
43
55
|
|
@@ -55,7 +67,7 @@ FontWatcherTest.prototype.setUp = function() {
|
|
55
67
|
this.testStringCount_ = 0;
|
56
68
|
this.testStrings_ = {};
|
57
69
|
webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
|
58
|
-
fontSizer, asyncCall, getTime, fontFamily, fontDescription, opt_fontTestString) {
|
70
|
+
fontSizer, asyncCall, getTime, fontFamily, fontDescription, hasWebkitFallbackBug, opt_metricCompatibleFonts, opt_fontTestString) {
|
59
71
|
if (opt_fontTestString) {
|
60
72
|
self.testStringCount_++;
|
61
73
|
self.testStrings_[fontFamily] = opt_fontTestString;
|
@@ -84,7 +96,7 @@ FontWatcherTest.prototype.testWatchOneFontNotLast = function() {
|
|
84
96
|
var fontFamilies = [ 'fontFamily1' ];
|
85
97
|
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1' ];
|
86
98
|
|
87
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
99
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
88
100
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
89
101
|
|
90
102
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, false);
|
@@ -98,7 +110,7 @@ FontWatcherTest.prototype.testWatchOneFontActive = function() {
|
|
98
110
|
var fontFamilies = [ 'fontFamily1' ];
|
99
111
|
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1' ];
|
100
112
|
|
101
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
113
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
102
114
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
103
115
|
|
104
116
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
|
@@ -116,7 +128,7 @@ FontWatcherTest.prototype.testWatchOneFontInactive = function() {
|
|
116
128
|
var fontFamilies = [ 'fontFamily1' ];
|
117
129
|
this.fontWatchRunnerActiveFamilies_ = [];
|
118
130
|
|
119
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
131
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
120
132
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
121
133
|
|
122
134
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
|
@@ -134,7 +146,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsActive = function() {
|
|
134
146
|
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
|
135
147
|
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
|
136
148
|
|
137
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
149
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
138
150
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
139
151
|
|
140
152
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
|
@@ -156,7 +168,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsInactive = function() {
|
|
156
168
|
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
|
157
169
|
this.fontWatchRunnerActiveFamilies_ = [];
|
158
170
|
|
159
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
171
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
160
172
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
161
173
|
|
162
174
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
|
@@ -178,7 +190,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsMixed = function() {
|
|
178
190
|
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
|
179
191
|
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1', 'fontFamily3' ];
|
180
192
|
|
181
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
193
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
182
194
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
183
195
|
|
184
196
|
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
|
@@ -206,7 +218,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithDescriptions = function() {
|
|
206
218
|
'fontFamily3': ['n4', 'i4', 'n7']
|
207
219
|
};
|
208
220
|
|
209
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
221
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
210
222
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
211
223
|
|
212
224
|
fontWatcher.watch(fontFamilies, fontDescriptions, {}, webfont.FontWatchRunner, true);
|
@@ -239,7 +251,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithTestStrings = function() {
|
|
239
251
|
'fontFamily4': null
|
240
252
|
};
|
241
253
|
|
242
|
-
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
|
254
|
+
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
243
255
|
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
244
256
|
|
245
257
|
fontWatcher.watch(fontFamilies, {}, fontTestStrings, webfont.FontWatchRunner,
|
@@ -249,3 +261,27 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithTestStrings = function() {
|
|
249
261
|
assertEquals('testString1', this.testStrings_['fontFamily1']);
|
250
262
|
assertEquals('testString3', this.testStrings_['fontFamily3']);
|
251
263
|
};
|
264
|
+
|
265
|
+
FontWatcherTest.prototype.testNoWebkitBugDetectionOnNonWebkit = function() {
|
266
|
+
var ua = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new webfont.BrowserInfo(true, false));
|
267
|
+
var fontWatcher = new webfont.FontWatcher(ua, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
268
|
+
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
269
|
+
|
270
|
+
assertEquals(false, fontWatcher.hasWebKitFallbackBug_);
|
271
|
+
};
|
272
|
+
|
273
|
+
FontWatcherTest.prototype.testNoWebkitBugDetectionOnNewWebkit = function() {
|
274
|
+
var ua = new webfont.UserAgent('Safari', '6.0.2', 'AppleWebKit', '537.6.17', 'Macintosh', '10_7_5', undefined, new webfont.BrowserInfo(true, false));
|
275
|
+
var fontWatcher = new webfont.FontWatcher(ua, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
276
|
+
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
277
|
+
|
278
|
+
assertEquals(false, fontWatcher.hasWebKitFallbackBug_);
|
279
|
+
};
|
280
|
+
|
281
|
+
FontWatcherTest.prototype.testYesWebkitBugDetectionOnOlderWebkit = function() {
|
282
|
+
var ua = new webfont.UserAgent('Chrome', '16.0.912.75', 'AppleWebKit', '535.7', 'Android', '4.0.3', undefined, new webfont.BrowserInfo(true, true));
|
283
|
+
var fontWatcher = new webfont.FontWatcher(ua, this.fakeDomHelper_, this.fakeEventDispatcher_,
|
284
|
+
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);
|
285
|
+
|
286
|
+
assertEquals(true, fontWatcher.hasWebKitFallbackBug_);
|
287
|
+
};
|