webfontloader 1.4.0 → 1.4.1
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 +4 -0
- data/lib/webfontloader.rb +1 -1
- data/spec/ascender/ascenderscript_spec.js +24 -1
- data/spec/core/eventdispatcher_spec.js +15 -11
- data/spec/core/font_spec.js +83 -192
- data/spec/core/fontruler_spec.js +7 -4
- data/spec/core/fontwatcher_spec.js +78 -61
- data/spec/core/fontwatchrunner_spec.js +85 -33
- data/spec/core/webfont_spec.js +224 -0
- data/spec/custom/customcss_spec.js +5 -2
- data/spec/deps.js +13 -13
- data/spec/fontdeck/fontdeckscript_spec.js +4 -6
- data/spec/fonts/sourcesansc.css +1 -0
- data/spec/fonts/sourcesanscbold.css +1 -0
- data/spec/fonts/sourcesanscbold.otf +0 -0
- data/spec/google/fontapiparser_spec.js +58 -178
- data/spec/google/googlefontapi_spec.js +14 -42
- data/spec/google/lastresortwebkitfontwatchrunner_spec.js +12 -10
- data/spec/index.html +5 -3
- data/spec/monotype/monotypescript_spec.js +3 -2
- data/spec/typekit/typekitscript_spec.js +9 -4
- data/src/ascender/ascender_script.js +43 -26
- data/src/core/eventdispatcher.js +23 -23
- data/src/core/font.js +80 -99
- data/src/core/fontmoduleloader.js +1 -1
- data/src/core/fontruler.js +10 -20
- data/src/core/fontwatcher.js +24 -46
- data/src/core/fontwatchrunner.js +13 -13
- data/src/core/initialize.js +0 -10
- data/src/core/webfont.js +134 -0
- data/src/custom/customcss.js +14 -10
- data/src/fontdeck/fontdeck_script.js +7 -9
- data/src/google/fontapiparser.js +11 -15
- data/src/google/googlefontapi.js +1 -2
- data/src/google/lastresortwebkitfontwatchrunner.js +15 -13
- data/src/modules.yml +2 -3
- data/src/monotype/monotype_script.js +9 -8
- data/src/typekit/typekit_script.js +17 -7
- data/webfontloader.gemspec +7 -6
- metadata +9 -8
- data/spec/core/cssfontfamilyname_spec.js +0 -38
- data/spec/core/fontvariationdescription_spec.js +0 -67
- data/src/core/cssfontfamilyname.js +0 -33
- data/src/core/fontvariationdescription.js +0 -140
data/spec/core/fontruler_spec.js
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
describe('FontRuler', function () {
|
2
|
-
var
|
2
|
+
var Font = webfont.Font,
|
3
|
+
FontRuler = webfont.FontRuler,
|
3
4
|
DomHelper = webfont.DomHelper,
|
4
5
|
Size = webfont.Size,
|
5
|
-
domHelper = null
|
6
|
+
domHelper = null,
|
7
|
+
font = null;
|
6
8
|
|
7
9
|
beforeEach(function () {
|
10
|
+
font = new Font('sans-serif');
|
8
11
|
domHelper = new DomHelper(window);
|
9
12
|
});
|
10
13
|
|
@@ -15,8 +18,8 @@ describe('FontRuler', function () {
|
|
15
18
|
fontRulerA.insert();
|
16
19
|
fontRulerB.insert();
|
17
20
|
|
18
|
-
fontRulerA.setFont(
|
19
|
-
fontRulerB.setFont(
|
21
|
+
fontRulerA.setFont(font);
|
22
|
+
fontRulerB.setFont(font);
|
20
23
|
|
21
24
|
var widthA = fontRulerA.getWidth(),
|
22
25
|
widthB = fontRulerB.getWidth();
|
@@ -1,5 +1,6 @@
|
|
1
1
|
describe('FontWatcher', function () {
|
2
2
|
var FontWatcher = webfont.FontWatcher,
|
3
|
+
Font = webfont.Font,
|
3
4
|
UserAgent = webfont.UserAgent,
|
4
5
|
BrowserInfo = webfont.BrowserInfo,
|
5
6
|
DomHelper = webfont.DomHelper,
|
@@ -7,12 +8,20 @@ describe('FontWatcher', function () {
|
|
7
8
|
eventDispatcher = {},
|
8
9
|
testStrings = null,
|
9
10
|
timeout = null,
|
11
|
+
font1 = null,
|
12
|
+
font2 = null,
|
13
|
+
font3 = null,
|
14
|
+
font4 = null,
|
10
15
|
userAgent = null,
|
11
|
-
|
16
|
+
activeFonts = [];
|
12
17
|
|
13
18
|
beforeEach(function () {
|
14
19
|
userAgent = new UserAgent('Firefox', '3.6', 'Gecko', '1.9.3', 'Macintosh', '10.6', undefined, new BrowserInfo(true, false, false));
|
15
|
-
|
20
|
+
font1 = new Font('font1');
|
21
|
+
font2 = new Font('font2');
|
22
|
+
font3 = new Font('font3');
|
23
|
+
font4 = new Font('font4');
|
24
|
+
activeFonts = [];
|
16
25
|
testStrings = jasmine.createSpy('testStrings');
|
17
26
|
timeout = jasmine.createSpy('timeout');
|
18
27
|
eventDispatcher.dispatchLoading = jasmine.createSpy('dispatchLoading');
|
@@ -24,11 +33,10 @@ describe('FontWatcher', function () {
|
|
24
33
|
});
|
25
34
|
|
26
35
|
function FakeFontWatchRunner(activeCallback, inactiveCallback, domHelper,
|
27
|
-
|
36
|
+
font, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
|
28
37
|
this.activeCallback = activeCallback;
|
29
38
|
this.inactiveCallback = inactiveCallback;
|
30
|
-
this.
|
31
|
-
this.fontDescription = fontDescription;
|
39
|
+
this.font = font;
|
32
40
|
timeout(opt_timeout);
|
33
41
|
|
34
42
|
if (opt_fontTestString) {
|
@@ -39,36 +47,43 @@ describe('FontWatcher', function () {
|
|
39
47
|
FakeFontWatchRunner.prototype.start = function () {
|
40
48
|
var found = false;
|
41
49
|
|
42
|
-
for (var i = 0; i <
|
43
|
-
if (
|
50
|
+
for (var i = 0; i < activeFonts.length; i += 1) {
|
51
|
+
if (activeFonts[i].getName() === this.font.getName()) {
|
44
52
|
found = true;
|
45
53
|
break;
|
46
54
|
}
|
47
55
|
}
|
48
|
-
|
49
56
|
if (found) {
|
50
|
-
this.activeCallback(this.
|
57
|
+
this.activeCallback(this.font);
|
51
58
|
} else {
|
52
|
-
this.inactiveCallback(this.
|
59
|
+
this.inactiveCallback(this.font);
|
53
60
|
}
|
54
61
|
};
|
55
62
|
|
56
63
|
describe('watch zero fonts', function () {
|
57
64
|
it('should call inactive when there are no fonts to load', function () {
|
58
|
-
|
65
|
+
activeFonts = [];
|
59
66
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
60
67
|
|
61
|
-
fontWatcher.watch([], {},
|
68
|
+
fontWatcher.watch([], {}, FakeFontWatchRunner, true);
|
62
69
|
expect(eventDispatcher.dispatchInactive).toHaveBeenCalled();
|
63
70
|
});
|
71
|
+
|
72
|
+
it('should not call inactive when there are no fonts to load, but this is not the last set', function () {
|
73
|
+
activeFonts = [];
|
74
|
+
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
75
|
+
|
76
|
+
fontWatcher.watch([], {}, FakeFontWatchRunner, false);
|
77
|
+
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
78
|
+
});
|
64
79
|
});
|
65
80
|
|
66
81
|
describe('watch one font not last', function () {
|
67
82
|
it('should not call font inactive, inactive or active', function () {
|
68
|
-
|
83
|
+
activeFonts = [font1];
|
69
84
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
70
85
|
|
71
|
-
fontWatcher.watch([
|
86
|
+
fontWatcher.watch([font1], {}, FakeFontWatchRunner, false);
|
72
87
|
expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
|
73
88
|
expect(eventDispatcher.dispatchActive).not.toHaveBeenCalled();
|
74
89
|
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
@@ -77,12 +92,12 @@ describe('FontWatcher', function () {
|
|
77
92
|
|
78
93
|
describe('watch one font active', function () {
|
79
94
|
it('should call font active and active', function () {
|
80
|
-
|
95
|
+
activeFonts = [font1];
|
81
96
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
82
97
|
|
83
|
-
fontWatcher.watch([
|
84
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
85
|
-
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(
|
98
|
+
fontWatcher.watch([font1], {}, FakeFontWatchRunner, true);
|
99
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
|
100
|
+
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font1);
|
86
101
|
expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
|
87
102
|
expect(eventDispatcher.dispatchActive).toHaveBeenCalled();
|
88
103
|
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
@@ -91,13 +106,13 @@ describe('FontWatcher', function () {
|
|
91
106
|
|
92
107
|
describe('watch one font inactive', function () {
|
93
108
|
it('should call inactive', function () {
|
94
|
-
|
109
|
+
activeFonts = [];
|
95
110
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
96
111
|
|
97
|
-
fontWatcher.watch([
|
98
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
112
|
+
fontWatcher.watch([font1], {}, FakeFontWatchRunner, true);
|
113
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
|
99
114
|
expect(eventDispatcher.dispatchFontActive).not.toHaveBeenCalled();
|
100
|
-
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(
|
115
|
+
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font1);
|
101
116
|
expect(eventDispatcher.dispatchActive).not.toHaveBeenCalled();
|
102
117
|
expect(eventDispatcher.dispatchInactive).toHaveBeenCalled();
|
103
118
|
});
|
@@ -105,12 +120,12 @@ describe('FontWatcher', function () {
|
|
105
120
|
|
106
121
|
describe('watch multiple fonts active', function () {
|
107
122
|
it('should call font active and active', function () {
|
108
|
-
|
123
|
+
activeFonts = [font1, font2, font3];
|
109
124
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
110
125
|
|
111
|
-
fontWatcher.watch([
|
112
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
113
|
-
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(
|
126
|
+
fontWatcher.watch([font1, font2, font3], {}, FakeFontWatchRunner, true);
|
127
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
|
128
|
+
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font1);
|
114
129
|
expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
|
115
130
|
expect(eventDispatcher.dispatchActive).toHaveBeenCalled();
|
116
131
|
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
@@ -119,13 +134,13 @@ describe('FontWatcher', function () {
|
|
119
134
|
|
120
135
|
describe('watch multiple fonts inactive', function () {
|
121
136
|
it('should call inactive', function () {
|
122
|
-
|
137
|
+
activeFonts = [];
|
123
138
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
124
139
|
|
125
|
-
fontWatcher.watch([
|
126
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
140
|
+
fontWatcher.watch([font1, font2, font3], {}, FakeFontWatchRunner, true);
|
141
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
|
127
142
|
expect(eventDispatcher.dispatchFontActive).not.toHaveBeenCalled();
|
128
|
-
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(
|
143
|
+
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font1);
|
129
144
|
expect(eventDispatcher.dispatchActive).not.toHaveBeenCalled();
|
130
145
|
expect(eventDispatcher.dispatchInactive).toHaveBeenCalled();
|
131
146
|
});
|
@@ -133,21 +148,21 @@ describe('FontWatcher', function () {
|
|
133
148
|
|
134
149
|
describe('watch multiple fonts mixed', function () {
|
135
150
|
it('should call the correct callbacks', function () {
|
136
|
-
|
151
|
+
activeFonts = [font1, font3];
|
137
152
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
138
153
|
|
139
|
-
fontWatcher.watch([
|
154
|
+
fontWatcher.watch([font1, font2, font3], {}, FakeFontWatchRunner, true);
|
140
155
|
expect(eventDispatcher.dispatchFontLoading.callCount).toEqual(3);
|
141
|
-
expect(eventDispatcher.dispatchFontLoading.calls[0].args[0]).toEqual(
|
142
|
-
expect(eventDispatcher.dispatchFontLoading.calls[1].args[0]).toEqual(
|
143
|
-
expect(eventDispatcher.dispatchFontLoading.calls[2].args[0]).toEqual(
|
156
|
+
expect(eventDispatcher.dispatchFontLoading.calls[0].args[0]).toEqual(font1);
|
157
|
+
expect(eventDispatcher.dispatchFontLoading.calls[1].args[0]).toEqual(font2);
|
158
|
+
expect(eventDispatcher.dispatchFontLoading.calls[2].args[0]).toEqual(font3);
|
144
159
|
|
145
160
|
expect(eventDispatcher.dispatchFontActive.callCount).toEqual(2);
|
146
|
-
expect(eventDispatcher.dispatchFontActive.calls[0].args[0]).toEqual(
|
147
|
-
expect(eventDispatcher.dispatchFontActive.calls[1].args[0]).toEqual(
|
161
|
+
expect(eventDispatcher.dispatchFontActive.calls[0].args[0]).toEqual(font1);
|
162
|
+
expect(eventDispatcher.dispatchFontActive.calls[1].args[0]).toEqual(font3);
|
148
163
|
|
149
164
|
expect(eventDispatcher.dispatchFontInactive.callCount).toEqual(1);
|
150
|
-
expect(eventDispatcher.dispatchFontInactive.calls[0].args[0]).toEqual(
|
165
|
+
expect(eventDispatcher.dispatchFontInactive.calls[0].args[0]).toEqual(font2);
|
151
166
|
|
152
167
|
expect(eventDispatcher.dispatchActive).toHaveBeenCalled();
|
153
168
|
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
@@ -156,30 +171,32 @@ describe('FontWatcher', function () {
|
|
156
171
|
|
157
172
|
describe('watch multiple fonts with descriptions', function () {
|
158
173
|
it('should call the correct callbacks', function () {
|
159
|
-
|
174
|
+
var font5 = new Font('font4', 'i7'),
|
175
|
+
font6 = new Font('font5'),
|
176
|
+
font7 = new Font('font6'),
|
177
|
+
font8 = new Font('font7', 'i4'),
|
178
|
+
font9 = new Font('font8', 'n7');
|
179
|
+
|
180
|
+
activeFonts = [font5, font6];
|
160
181
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
161
182
|
|
162
|
-
fontWatcher.watch([
|
163
|
-
'fontFamily1': ['i7'],
|
164
|
-
'fontFamily2': null,
|
165
|
-
'fontFamily3': ['n4', 'i4', 'n7']
|
166
|
-
}, {}, FakeFontWatchRunner, true);
|
183
|
+
fontWatcher.watch([font5, font6, font7, font8, font9], {}, FakeFontWatchRunner, true);
|
167
184
|
|
168
185
|
expect(eventDispatcher.dispatchFontLoading.callCount).toEqual(5);
|
169
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
170
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
171
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
172
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
173
|
-
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(
|
186
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font5);
|
187
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font6);
|
188
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font7);
|
189
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font8);
|
190
|
+
expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font9);
|
174
191
|
|
175
192
|
expect(eventDispatcher.dispatchFontActive.callCount).toEqual(2);
|
176
|
-
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(
|
177
|
-
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(
|
193
|
+
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font5);
|
194
|
+
expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font6);
|
178
195
|
|
179
196
|
expect(eventDispatcher.dispatchFontInactive.callCount).toEqual(3);
|
180
|
-
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(
|
181
|
-
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(
|
182
|
-
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(
|
197
|
+
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font7);
|
198
|
+
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font8);
|
199
|
+
expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font9);
|
183
200
|
|
184
201
|
expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
|
185
202
|
expect(eventDispatcher.dispatchActive).toHaveBeenCalled();
|
@@ -188,15 +205,15 @@ describe('FontWatcher', function () {
|
|
188
205
|
|
189
206
|
describe('watch multiple fonts with test strings', function () {
|
190
207
|
it('should use the correct tests strings', function () {
|
191
|
-
|
208
|
+
activeFonts = [font1, font2];
|
192
209
|
|
193
210
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
|
194
211
|
|
195
|
-
fontWatcher.watch([
|
196
|
-
'
|
197
|
-
'
|
198
|
-
'
|
199
|
-
'
|
212
|
+
fontWatcher.watch([font1, font2, font3, font4], {
|
213
|
+
'font1': 'testString1',
|
214
|
+
'font2': null,
|
215
|
+
'font3': 'testString2',
|
216
|
+
'font4': null
|
200
217
|
}, FakeFontWatchRunner, true);
|
201
218
|
|
202
219
|
expect(testStrings.callCount).toEqual(2);
|
@@ -208,7 +225,7 @@ describe('FontWatcher', function () {
|
|
208
225
|
it('should pass on the timeout to FontWatchRunner', function () {
|
209
226
|
var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher, 4000);
|
210
227
|
|
211
|
-
fontWatcher.watch([
|
228
|
+
fontWatcher.watch([font1], {}, FakeFontWatchRunner, true);
|
212
229
|
|
213
230
|
expect(timeout).toHaveBeenCalledWith(4000);
|
214
231
|
});
|
@@ -1,5 +1,6 @@
|
|
1
1
|
describe('FontWatchRunner', function () {
|
2
2
|
var FontWatchRunner = webfont.FontWatchRunner,
|
3
|
+
Font = webfont.Font,
|
3
4
|
BrowserInfo = webfont.BrowserInfo,
|
4
5
|
UserAgentParser = webfont.UserAgentParser,
|
5
6
|
DomHelper = webfont.DomHelper,
|
@@ -17,8 +18,7 @@ describe('FontWatchRunner', function () {
|
|
17
18
|
});
|
18
19
|
|
19
20
|
describe('Fake browser', function () {
|
20
|
-
var
|
21
|
-
fontDescription = 'n4',
|
21
|
+
var font = new Font('My Family', 'n4'),
|
22
22
|
TARGET_SIZE = 3,
|
23
23
|
FALLBACK_SIZE_A = 1,
|
24
24
|
FALLBACK_SIZE_B = 2,
|
@@ -84,12 +84,12 @@ describe('FontWatchRunner', function () {
|
|
84
84
|
];
|
85
85
|
|
86
86
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
87
|
-
domHelper,
|
87
|
+
domHelper, font, browserInfo);
|
88
88
|
|
89
89
|
fontWatchRunner.start();
|
90
90
|
|
91
91
|
jasmine.Clock.tick(1 * 25);
|
92
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
92
|
+
expect(activeCallback).toHaveBeenCalledWith(font);
|
93
93
|
});
|
94
94
|
|
95
95
|
it('should wait for font load and call active', function () {
|
@@ -101,12 +101,12 @@ describe('FontWatchRunner', function () {
|
|
101
101
|
];
|
102
102
|
|
103
103
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
104
|
-
domHelper,
|
104
|
+
domHelper, font, browserInfo);
|
105
105
|
|
106
106
|
fontWatchRunner.start();
|
107
107
|
|
108
108
|
jasmine.Clock.tick(3 * 25);
|
109
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
109
|
+
expect(activeCallback).toHaveBeenCalledWith(font);
|
110
110
|
});
|
111
111
|
|
112
112
|
it('should wait for font inactive and call inactive', function () {
|
@@ -121,12 +121,12 @@ describe('FontWatchRunner', function () {
|
|
121
121
|
];
|
122
122
|
|
123
123
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
124
|
-
domHelper,
|
124
|
+
domHelper, font, browserInfo);
|
125
125
|
|
126
126
|
fontWatchRunner.start();
|
127
127
|
|
128
128
|
jasmine.Clock.tick(4 * 25);
|
129
|
-
expect(inactiveCallback).toHaveBeenCalledWith(
|
129
|
+
expect(inactiveCallback).toHaveBeenCalledWith(font);
|
130
130
|
});
|
131
131
|
|
132
132
|
describe('WebKit fallback bug', function () {
|
@@ -137,12 +137,12 @@ describe('FontWatchRunner', function () {
|
|
137
137
|
];
|
138
138
|
|
139
139
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
140
|
-
domHelper,
|
140
|
+
domHelper, font, fallbackBugBrowserInfo);
|
141
141
|
|
142
142
|
fontWatchRunner.start();
|
143
143
|
|
144
144
|
jasmine.Clock.tick(1 * 25);
|
145
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
145
|
+
expect(activeCallback).toHaveBeenCalledWith(font);
|
146
146
|
});
|
147
147
|
|
148
148
|
it('should consider last resort font as having identical metrics and call active', function () {
|
@@ -154,12 +154,12 @@ describe('FontWatchRunner', function () {
|
|
154
154
|
timesToGetTimeBeforeTimeout = 2;
|
155
155
|
|
156
156
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
157
|
-
domHelper,
|
157
|
+
domHelper, font, fallbackBugBrowserInfo);
|
158
158
|
|
159
159
|
fontWatchRunner.start();
|
160
160
|
|
161
161
|
jasmine.Clock.tick(1 * 25);
|
162
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
162
|
+
expect(activeCallback).toHaveBeenCalledWith(font);
|
163
163
|
});
|
164
164
|
|
165
165
|
it('should fail to load font and call inactive', function () {
|
@@ -172,12 +172,12 @@ describe('FontWatchRunner', function () {
|
|
172
172
|
timesToGetTimeBeforeTimeout = 3;
|
173
173
|
|
174
174
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
175
|
-
domHelper,
|
175
|
+
domHelper, font, fallbackBugBrowserInfo);
|
176
176
|
|
177
177
|
fontWatchRunner.start();
|
178
178
|
|
179
179
|
jasmine.Clock.tick(2 * 25);
|
180
|
-
expect(inactiveCallback).toHaveBeenCalledWith(
|
180
|
+
expect(inactiveCallback).toHaveBeenCalledWith(font);
|
181
181
|
});
|
182
182
|
|
183
183
|
it('should call inactive when we are loading a metric incompatible font', function () {
|
@@ -189,13 +189,13 @@ describe('FontWatchRunner', function () {
|
|
189
189
|
timesToGetTimeBeforeTimeout = 2;
|
190
190
|
|
191
191
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
192
|
-
domHelper,
|
192
|
+
domHelper, font, fallbackBugBrowserInfo,
|
193
193
|
0, { 'My Other Family': true });
|
194
194
|
|
195
195
|
fontWatchRunner.start();
|
196
196
|
|
197
197
|
jasmine.Clock.tick(1 * 25);
|
198
|
-
expect(inactiveCallback).toHaveBeenCalledWith(
|
198
|
+
expect(inactiveCallback).toHaveBeenCalledWith(font);
|
199
199
|
});
|
200
200
|
|
201
201
|
it('should call active when we are loading a metric compatible font', function () {
|
@@ -207,13 +207,13 @@ describe('FontWatchRunner', function () {
|
|
207
207
|
timesToGetTimeBeforeTimeout = 2;
|
208
208
|
|
209
209
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
210
|
-
domHelper,
|
210
|
+
domHelper, font, fallbackBugBrowserInfo,
|
211
211
|
0, { 'My Family': true });
|
212
212
|
|
213
213
|
fontWatchRunner.start();
|
214
214
|
|
215
215
|
jasmine.Clock.tick(1 * 25);
|
216
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
216
|
+
expect(activeCallback).toHaveBeenCalledWith(font);
|
217
217
|
});
|
218
218
|
});
|
219
219
|
|
@@ -229,7 +229,7 @@ describe('FontWatchRunner', function () {
|
|
229
229
|
TARGET_SIZE, TARGET_SIZE
|
230
230
|
];
|
231
231
|
fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
232
|
-
domHelper,
|
232
|
+
domHelper, font, browserInfo);
|
233
233
|
|
234
234
|
fontWatchRunner.start();
|
235
235
|
|
@@ -243,7 +243,7 @@ describe('FontWatchRunner', function () {
|
|
243
243
|
];
|
244
244
|
|
245
245
|
fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
246
|
-
domHelper,
|
246
|
+
domHelper, font, browserInfo, 0, {}, 'TestString');
|
247
247
|
|
248
248
|
fontWatchRunner.start();
|
249
249
|
|
@@ -254,17 +254,26 @@ describe('FontWatchRunner', function () {
|
|
254
254
|
});
|
255
255
|
|
256
256
|
describe('real browser testing', function () {
|
257
|
-
var userAgent = null
|
257
|
+
var userAgent = null,
|
258
|
+
nullFont = null,
|
259
|
+
sourceSansA = null,
|
260
|
+
sourceSansB = null,
|
261
|
+
elena = null;
|
258
262
|
|
259
263
|
beforeEach(function () {
|
260
264
|
var userAgentParser = new UserAgentParser(window.navigator.userAgent, window.document);
|
261
265
|
|
266
|
+
nullFont = new Font('__webfontloader_test__');
|
267
|
+
sourceSansA = new Font('SourceSansA');
|
268
|
+
sourceSansB = new Font('SourceSansB');
|
269
|
+
elena = new Font('Elena');
|
270
|
+
|
262
271
|
userAgent = userAgentParser.parse();
|
263
272
|
});
|
264
273
|
|
265
274
|
it('should fail to load a null font', function () {
|
266
275
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
267
|
-
domHelper,
|
276
|
+
domHelper, nullFont, userAgent.getBrowserInfo(), 500);
|
268
277
|
|
269
278
|
runs(function () {
|
270
279
|
fontWatchRunner.start();
|
@@ -275,23 +284,25 @@ describe('FontWatchRunner', function () {
|
|
275
284
|
});
|
276
285
|
|
277
286
|
runs(function () {
|
278
|
-
expect(inactiveCallback).toHaveBeenCalledWith(
|
287
|
+
expect(inactiveCallback).toHaveBeenCalledWith(nullFont);
|
279
288
|
});
|
280
289
|
});
|
281
290
|
|
282
291
|
it('should load font succesfully', function () {
|
283
292
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
284
|
-
domHelper,
|
293
|
+
domHelper, sourceSansA, userAgent.getBrowserInfo(), 500),
|
285
294
|
ruler = new FontRuler(domHelper, 'abcdef'),
|
295
|
+
monospace = new Font('monospace'),
|
296
|
+
sourceSansAFallback = new Font("'SourceSansA', monospace"),
|
286
297
|
activeWidth = null,
|
287
298
|
originalWidth = null,
|
288
299
|
finalCheck = false;
|
289
300
|
|
290
301
|
runs(function () {
|
291
302
|
ruler.insert();
|
292
|
-
ruler.setFont(
|
303
|
+
ruler.setFont(monospace);
|
293
304
|
originalWidth = ruler.getWidth();
|
294
|
-
ruler.setFont(
|
305
|
+
ruler.setFont(sourceSansAFallback);
|
295
306
|
fontWatchRunner.start();
|
296
307
|
});
|
297
308
|
|
@@ -300,7 +311,7 @@ describe('FontWatchRunner', function () {
|
|
300
311
|
});
|
301
312
|
|
302
313
|
runs(function () {
|
303
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
314
|
+
expect(activeCallback).toHaveBeenCalledWith(sourceSansA);
|
304
315
|
activeWidth = ruler.getWidth();
|
305
316
|
expect(activeWidth).not.toEqual(originalWidth);
|
306
317
|
|
@@ -321,7 +332,7 @@ describe('FontWatchRunner', function () {
|
|
321
332
|
|
322
333
|
it('should attempt to load a non-existing font', function () {
|
323
334
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
324
|
-
domHelper,
|
335
|
+
domHelper, elena, userAgent.getBrowserInfo(), 500);
|
325
336
|
|
326
337
|
runs(function () {
|
327
338
|
fontWatchRunner.start();
|
@@ -332,23 +343,25 @@ describe('FontWatchRunner', function () {
|
|
332
343
|
});
|
333
344
|
|
334
345
|
runs(function () {
|
335
|
-
expect(inactiveCallback).toHaveBeenCalledWith(
|
346
|
+
expect(inactiveCallback).toHaveBeenCalledWith(elena);
|
336
347
|
});
|
337
348
|
});
|
338
349
|
|
339
350
|
it('should load even if @font-face is inserted after watching has started', function () {
|
340
351
|
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
|
341
|
-
domHelper,
|
352
|
+
domHelper, sourceSansB, userAgent.getBrowserInfo(), 500),
|
342
353
|
ruler = new FontRuler(domHelper, 'abcdef'),
|
354
|
+
monospace = new Font('monospace'),
|
355
|
+
sourceSansBFallback = new Font("'SourceSansB', monospace"),
|
343
356
|
activeWidth = null,
|
344
357
|
originalWidth = null,
|
345
358
|
finalCheck = false;
|
346
359
|
|
347
360
|
runs(function () {
|
348
361
|
ruler.insert();
|
349
|
-
ruler.setFont(
|
362
|
+
ruler.setFont(monospace);
|
350
363
|
originalWidth = ruler.getWidth();
|
351
|
-
ruler.setFont(
|
364
|
+
ruler.setFont(sourceSansBFallback);
|
352
365
|
fontWatchRunner.start();
|
353
366
|
var link = document.createElement('link');
|
354
367
|
|
@@ -363,7 +376,7 @@ describe('FontWatchRunner', function () {
|
|
363
376
|
});
|
364
377
|
|
365
378
|
runs(function () {
|
366
|
-
expect(activeCallback).toHaveBeenCalledWith(
|
379
|
+
expect(activeCallback).toHaveBeenCalledWith(sourceSansB);
|
367
380
|
activeWidth = ruler.getWidth();
|
368
381
|
expect(activeWidth).not.toEqual(originalWidth);
|
369
382
|
|
@@ -381,5 +394,44 @@ describe('FontWatchRunner', function () {
|
|
381
394
|
expect(ruler.getWidth()).toEqual(activeWidth);
|
382
395
|
});
|
383
396
|
});
|
397
|
+
|
398
|
+
it('should load one weight after another', function () {
|
399
|
+
var fontWatchRunnerRegular = new FontWatchRunner(activeCallback, inactiveCallback,
|
400
|
+
domHelper, 'SourceSansC', 'n4', userAgent.getBrowserInfo(), 500),
|
401
|
+
fontWatchRunnerBold = new FontWatchRunner(activeCallback, inactiveCallback,
|
402
|
+
domHelper, 'SourceSansC', 'n7', userAgent.getBrowserInfo(), 500),
|
403
|
+
fontRulerA = new FontRuler(domHelper, 'abcdef'),
|
404
|
+
fontRulerB = new FontRuler(domHelper, 'abcdef');
|
405
|
+
|
406
|
+
runs(function () {
|
407
|
+
fontRulerA.insert();
|
408
|
+
fontRulerA.setFont('SourceSansC', 'n4');
|
409
|
+
fontWatchRunnerRegular.start();
|
410
|
+
});
|
411
|
+
|
412
|
+
waitsFor(function () {
|
413
|
+
return activeCallback.wasCalled || inactiveCallback.wasCalled;
|
414
|
+
});
|
415
|
+
|
416
|
+
runs(function () {
|
417
|
+
expect(activeCallback).toHaveBeenCalledWith('SourceSansC', 'n4');
|
418
|
+
|
419
|
+
activeCallback.reset();
|
420
|
+
inactiveCallback.reset();
|
421
|
+
|
422
|
+
fontRulerB.insert();
|
423
|
+
fontRulerB.setFont('SourceSansC', 'n7');
|
424
|
+
fontWatchRunnerBold.start();
|
425
|
+
});
|
426
|
+
|
427
|
+
waitsFor(function () {
|
428
|
+
return activeCallback.wasCalled || inactiveCallback.wasCalled;
|
429
|
+
});
|
430
|
+
|
431
|
+
runs(function () {
|
432
|
+
expect(activeCallback).toHaveBeenCalledWith('SourceSansC', 'n7');
|
433
|
+
expect(fontRulerA.getSize()).not.toEqual(fontRulerB.getSize());
|
434
|
+
});
|
435
|
+
});
|
384
436
|
});
|
385
437
|
});
|