OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
4 <style> | 4 <style> |
5 @font-face { | 5 @font-face { |
6 font-family: Font1; | 6 font-family: Font1; |
7 src: local(Arial); | 7 src: local(Arial); |
8 } | 8 } |
9 | 9 |
10 @font-face { | 10 @font-face { |
11 font-family: Font2; | 11 font-family: Font2; |
12 src: local(Arial); | 12 src: local(Arial); |
13 } | 13 } |
14 | 14 |
15 @font-face { | 15 @font-face { |
16 font-family: Font3; | 16 font-family: Font3; |
17 src: local(Arial); | 17 src: local(Arial); |
18 } | 18 } |
19 </style> | 19 </style> |
20 <script> | 20 <script> |
21 description('Tests Set operations of FontFaceSet.'); | 21 description('Tests Set operations of FontFaceSet.'); |
22 | 22 |
23 function runTests() { | 23 thisArg = {}; |
24 nonCssConnectedFace = new FontFace("MyFont", "local(Arial)", {}); | 24 faces = [] |
25 | 25 |
26 shouldBe('document.fonts.size', '3'); | 26 function checkResults() { |
27 | |
28 thisArg = {}; | |
29 faces = []; | |
30 document.fonts.forEach(function(face, faceAgain, set) { | |
31 if (faces.length == 0) { | |
32 callbackArgs = arguments; | |
33 thisValue = this; | |
34 shouldBeTrue('callbackArgs[0] === callbackArgs[1]'); | |
35 shouldBeTrue('callbackArgs[2] === document.fonts'); | |
36 shouldBeTrue('thisValue === thisArg'); | |
37 } | |
38 faces.push(face); | |
39 }, thisArg); | |
40 shouldBe('faces.length', '3'); | 27 shouldBe('faces.length', '3'); |
41 | 28 |
42 shouldBeEqualToString('faces[0].family', 'Font1'); | 29 shouldBeEqualToString('faces[0].family', 'Font1'); |
43 shouldBeEqualToString('faces[1].family', 'Font2'); | 30 shouldBeEqualToString('faces[1].family', 'Font2'); |
44 shouldBeEqualToString('faces[2].family', 'Font3'); | 31 shouldBeEqualToString('faces[2].family', 'Font3'); |
45 | 32 |
46 shouldBeTrue('document.fonts.has(faces[0])'); | 33 shouldBeTrue('document.fonts.has(faces[0])'); |
47 shouldBeTrue('document.fonts.has(faces[1])'); | 34 shouldBeTrue('document.fonts.has(faces[1])'); |
48 shouldBeTrue('document.fonts.has(faces[2])'); | 35 shouldBeTrue('document.fonts.has(faces[2])'); |
| 36 } |
| 37 |
| 38 function callback(face, faceAgain, set) { |
| 39 if (faces.length == 0) { |
| 40 callbackArgs = arguments; |
| 41 thisValue = this; |
| 42 shouldBeType('callbackArgs[0]', 'FontFace'); |
| 43 shouldBeTrue('callbackArgs[0] === callbackArgs[1]'); |
| 44 shouldBeTrue('callbackArgs[2] === document.fonts'); |
| 45 shouldBeTrue('thisValue === thisArg'); |
| 46 } |
| 47 faces.push(face); |
| 48 } |
| 49 |
| 50 function runTests() { |
| 51 nonCssConnectedFace = new FontFace("MyFont", "local(Arial)", {}); |
| 52 |
| 53 shouldBe('document.fonts.size', '3'); |
| 54 |
| 55 debug('check forEach'); |
| 56 document.fonts.forEach(callback, thisArg); |
| 57 checkResults(); |
| 58 |
| 59 debug('check keys'); |
| 60 faces = []; |
| 61 for (face of document.fonts.keys()) |
| 62 faces.push(face); |
| 63 checkResults(); |
| 64 |
| 65 debug('check values'); |
| 66 faces = []; |
| 67 for (face of document.fonts.values()) |
| 68 faces.push(face); |
| 69 checkResults(); |
| 70 |
| 71 debug('check entries'); |
| 72 faces = []; |
| 73 for (entry of document.fonts.entries()) { |
| 74 shouldBeTrue('entry[0] === entry[1]'); |
| 75 faces.push(entry[1]); |
| 76 } |
| 77 checkResults(); |
| 78 |
49 shouldBeFalse('document.fonts.has(nonCssConnectedFace)'); | 79 shouldBeFalse('document.fonts.has(nonCssConnectedFace)'); |
50 shouldThrow('document.fonts.has("Font1")', '"TypeError: Failed to execute \'
has\' on \'FontFaceSet\': The argument is not a FontFace."'); | 80 shouldThrow('document.fonts.has("Font1")', '"TypeError: Failed to execute \'
has\' on \'FontFaceSet\': The argument is not a FontFace."'); |
51 | 81 |
52 shouldThrow('document.fonts.add(faces[0])', '"InvalidModificationError: Fail
ed to execute \'add\' on \'FontFaceSet\': Cannot add a CSS-connected FontFace."'
); | 82 shouldThrow('document.fonts.add(faces[0])', '"InvalidModificationError: Fail
ed to execute \'add\' on \'FontFaceSet\': Cannot add a CSS-connected FontFace."'
); |
53 shouldThrow('document.fonts.delete(faces[0])', '"InvalidModificationError: F
ailed to execute \'delete\' on \'FontFaceSet\': Cannot delete a CSS-connected Fo
ntFace."'); | 83 shouldThrow('document.fonts.delete(faces[0])', '"InvalidModificationError: F
ailed to execute \'delete\' on \'FontFaceSet\': Cannot delete a CSS-connected Fo
ntFace."'); |
54 | 84 |
55 document.fonts.add(nonCssConnectedFace); | 85 document.fonts.add(nonCssConnectedFace); |
56 shouldBe('document.fonts.size', '4'); | 86 shouldBe('document.fonts.size', '4'); |
57 shouldBeTrue('document.fonts.has(nonCssConnectedFace)'); | 87 shouldBeTrue('document.fonts.has(nonCssConnectedFace)'); |
58 document.fonts.add(nonCssConnectedFace); | 88 document.fonts.add(nonCssConnectedFace); |
(...skipping 13 matching lines...) Expand all Loading... |
72 if (document.fonts) | 102 if (document.fonts) |
73 runTests(); | 103 runTests(); |
74 else | 104 else |
75 testFailed('document.fonts does not exist'); | 105 testFailed('document.fonts does not exist'); |
76 | 106 |
77 </script> | 107 </script> |
78 </head> | 108 </head> |
79 <body> | 109 <body> |
80 </body> | 110 </body> |
81 </html> | 111 </html> |
OLD | NEW |