1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
@font-face {
font-family: TestFont1;
src: local('Courier New');
}
@font-face {
font-family: TestFont2;
src: url(../../resources/Ahem.ttf);
unicode-range: u+61-7a; /* 'a'-'z' */
}
@font-face {
font-family: TestFont3;
src: url(data:application/x-truetype-font,) format(truetype);
}
@font-face {
font-family: TestFont4;
src: url(data:application/xml,) format(svg);
}
</style>
<script>
description('Test load events for fonts.loadFont() with multiple font families.');
window.jsTestIsAsync = true;
function runTests() {
document.fonts.addEventListener('loading', onLoading);
document.fonts.addEventListener('loadingdone', onLoadingDone);
document.fonts.addEventListener('loadingerror', onLoadingError);
document.fonts.ready.then(finish);
document.fonts.load('10px TestFont1, TestFont2, TestFont3, TestFont4', 'abc').catch(function() {});
}
var event;
var firedEvents = [];
function onLoading(e) {
firedEvents.push(e.type);
}
function onLoadingDone(e) {
firedEvents.push(e.type);
event = e;
shouldBe("event.fontfaces.length", "2");
shouldBeEqualToString("event.fontfaces[0].status", "loaded");
shouldBeEqualToString("event.fontfaces[1].status", "loaded");
loadedFonts = e.fontfaces.map(function(face){return face.family;}).sort();
shouldBe('loadedFonts', "['TestFont1', 'TestFont2']");
shouldBeTrue("document.fonts.check('10px TestFont1')");
shouldBeTrue("document.fonts.check('10px TestFont2')");
shouldBeTrue("document.fonts.check('10px TestFont1, TestFont2')");
shouldBeTrue("document.fonts.check('10px Times')");
shouldBeTrue("document.fonts.check('10px TestFont1, Times')");
}
function onLoadingError(e) {
firedEvents.push(e.type);
event = e;
shouldBe("event.fontfaces.length", "2");
shouldBeEqualToString("event.fontfaces[0].status", "error");
shouldBeEqualToString("event.fontfaces[1].status", "error");
failedFonts = e.fontfaces.map(function(face){return face.family;}).sort();
shouldBe('failedFonts', "['TestFont3', 'TestFont4']");
shouldBeFalse("document.fonts.check('10px TestFont3')");
shouldBeFalse("document.fonts.check('10px TestFont4')");
shouldBeFalse("document.fonts.check('10px TestFont4, Times')");
}
function finish() {
shouldBe("firedEvents", "['loading', 'loadingdone', 'loadingerror']");
finishJSTest();
}
if (document.fonts)
runTests();
else {
testFailed('document.fonts does not exist');
finishJSTest();
}
</script>
</head>
<body>
</body>
</html>
|