3 <script src=
"../../resources/js-test.js"></script>
6 font-family: TestFont1;
7 src: local('Courier New');
11 font-family: TestFont2;
12 src: url(../../resources/Ahem.ttf);
13 unicode-range: u+
61-
7a; /* 'a'-'z' */
17 font-family: TestFont3;
18 src: url(data:application/x-truetype-font,) format(truetype);
22 font-family: TestFont4;
23 src: url(data:application/xml,) format(svg);
27 description('Test load events for fonts.loadFont() with multiple font families.');
29 window
.jsTestIsAsync
= true;
32 document
.fonts
.addEventListener('loading', onLoading
);
33 document
.fonts
.addEventListener('loadingdone', onLoadingDone
);
34 document
.fonts
.addEventListener('loadingerror', onLoadingError
);
35 document
.fonts
.ready
.then(finish
);
37 document
.fonts
.load('10px TestFont1, TestFont2, TestFont3, TestFont4', 'abc').catch(function() {});
43 function onLoading(e
) {
44 firedEvents
.push(e
.type
);
47 function onLoadingDone(e
) {
48 firedEvents
.push(e
.type
);
50 shouldBe("event.fontfaces.length", "2");
51 shouldBeEqualToString("event.fontfaces[0].status", "loaded");
52 shouldBeEqualToString("event.fontfaces[1].status", "loaded");
53 loadedFonts
= e
.fontfaces
.map(function(face
){return face
.family
;}).sort();
54 shouldBe('loadedFonts', "['TestFont1', 'TestFont2']");
55 shouldBeTrue("document.fonts.check('10px TestFont1')");
56 shouldBeTrue("document.fonts.check('10px TestFont2')");
57 shouldBeTrue("document.fonts.check('10px TestFont1, TestFont2')");
58 shouldBeTrue("document.fonts.check('10px Times')");
59 shouldBeTrue("document.fonts.check('10px TestFont1, Times')");
62 function onLoadingError(e
) {
63 firedEvents
.push(e
.type
);
65 shouldBe("event.fontfaces.length", "2");
66 shouldBeEqualToString("event.fontfaces[0].status", "error");
67 shouldBeEqualToString("event.fontfaces[1].status", "error");
68 failedFonts
= e
.fontfaces
.map(function(face
){return face
.family
;}).sort();
69 shouldBe('failedFonts', "['TestFont3', 'TestFont4']");
70 shouldBeFalse("document.fonts.check('10px TestFont3')");
71 shouldBeFalse("document.fonts.check('10px TestFont4')");
72 shouldBeFalse("document.fonts.check('10px TestFont4, Times')");
76 shouldBe("firedEvents", "['loading', 'loadingdone', 'loadingerror']");
83 testFailed('document.fonts does not exist');