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
|
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
/* Test 1: Invalid font data */
@font-face {
font-family: myfont1;
src: url('resources/invalidfont.png') format(opentype);
}
/* Test 2: Download error */
@font-face {
font-family: myfont2;
src: url('resources/DownLoadErrorAhem.otf');
}
/* Test 3: Empty data url */
@font-face {
font-family: myfont3;
src: url(data:application/x-truetype-font,) format(truetype);
}
/* Test 4: Download error followed by existing local font */
@font-face {
font-family: myfont4;
src: url('resources/DownLoadErrorAhem.otf'), local('Courier New');
}
/* Test 5: Multiple errors */
@font-face {
font-family: myfont5;
src: url('resources/DownLoadErrorAhem.otf'), url(data:application/x-truetype-font,) format(truetype);
}
</style>
<script>
description('Test download error cases.');
window.jsTestIsAsync = true;
function runTests() {
document.fonts.addEventListener('loading', onLoading);
document.fonts.addEventListener('loadingdone', onLoadingDone);
document.fonts.addEventListener('loadingerror', onLoadingError);
document.fonts.load('10px myfont1').catch(function() {
document.fonts.load('10px myfont2, myfont3, myfont4, myfont5').catch(function(){});
});
document.fonts.ready.then(finish);
}
var event;
var firedEvents = [];
function onLoading(e) {
firedEvents.push(e.type);
}
function onLoadingDone(e) {
firedEvents.push(e.type);
event = e;
shouldBe('event.fontfaces.length', '1');
shouldBeEqualToString('event.fontfaces[0].family', 'myfont4');
}
function onLoadingError(e) {
firedEvents.push(e.type);
event = e;
shouldBe('event.fontfaces.length', '4');
failedFonts = e.fontfaces.map(function(face){return face.family;}).sort();
shouldBe('failedFonts', "['myfont1', 'myfont2', 'myfont3', 'myfont5']");
}
function finish() {
shouldBe("firedEvents", "['loading', 'loadingdone', 'loadingerror']");
finishJSTest();
}
if (document.fonts)
runTests();
else {
testFailed('document.fonts does not exist');
finishJSTest();
}
</script>
</head>
</html>
|