Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/css/fontfaceset-set-operations.html

Issue 1409433003: CSS Font Loading: make FontFaceSet Setlike (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert forEach behavior (that makes it easy!) Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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])');
49 shouldBeFalse('document.fonts.has(nonCssConnectedFace)'); 36 shouldBeFalse('document.fonts.has(nonCssConnectedFace)');
Kunihiko Sakamoto 2015/10/16 09:50:07 Can you move the rest of this function (line 36-40
Takashi Toyoshima 2015/10/16 10:07:02 Done.
50 shouldThrow('document.fonts.has("Font1")', '"TypeError: Failed to execute \' has\' on \'FontFaceSet\': The argument is not a FontFace."'); 37 shouldThrow('document.fonts.has("Font1")', '"TypeError: Failed to execute \' has\' on \'FontFaceSet\': The argument is not a FontFace."');
51 38
52 shouldThrow('document.fonts.add(faces[0])', '"InvalidModificationError: Fail ed to execute \'add\' on \'FontFaceSet\': Cannot add a CSS-connected FontFace."' ); 39 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."'); 40 shouldThrow('document.fonts.delete(faces[0])', '"InvalidModificationError: F ailed to execute \'delete\' on \'FontFaceSet\': Cannot delete a CSS-connected Fo ntFace."');
41 }
42
43 function callback(face, index, set) {
Kunihiko Sakamoto 2015/10/16 09:50:07 Second parameter is no longer an index.
Takashi Toyoshima 2015/10/16 10:07:03 Done.
44 if (faces.length == 0) {
45 callbackArgs = arguments;
46 thisValue = this;
47 shouldBeType('callbackArgs[0]', 'FontFace');
48 shouldBeTrue('callbackArgs[0] === callbackArgs[1]');
49 shouldBeTrue('callbackArgs[2] === document.fonts');
50 shouldBeTrue('thisValue === thisArg');
51 }
52 faces.push(face);
53 }
54
55 function runTests() {
56 nonCssConnectedFace = new FontFace("MyFont", "local(Arial)", {});
57
58 shouldBe('document.fonts.size', '3');
59
60 debug('check forEach');
61 document.fonts.forEach(callback, thisArg);
62 checkResults();
63
64 debug('check keys');
65 faces = [];
66 for (face of document.fonts.keys())
67 faces.push(face);
68 checkResults();
69
70 debug('check values');
71 faces = [];
72 for (face of document.fonts.values())
73 faces.push(face);
74 checkResults();
75
76 debug('check entries');
77 faces = [];
78 for (entry of document.fonts.entries()) {
79 shouldBeTrue('entry[0] === entry[1]');
80 faces.push(entry[1]);
81 }
82 checkResults();
54 83
55 document.fonts.add(nonCssConnectedFace); 84 document.fonts.add(nonCssConnectedFace);
56 shouldBe('document.fonts.size', '4'); 85 shouldBe('document.fonts.size', '4');
57 shouldBeTrue('document.fonts.has(nonCssConnectedFace)'); 86 shouldBeTrue('document.fonts.has(nonCssConnectedFace)');
58 document.fonts.add(nonCssConnectedFace); 87 document.fonts.add(nonCssConnectedFace);
59 shouldBe('document.fonts.size', '4'); 88 shouldBe('document.fonts.size', '4');
60 document.fonts.delete(nonCssConnectedFace); 89 document.fonts.delete(nonCssConnectedFace);
61 shouldBe('document.fonts.size', '3'); 90 shouldBe('document.fonts.size', '3');
62 shouldBeFalse('document.fonts.has(nonCssConnectedFace)'); 91 shouldBeFalse('document.fonts.has(nonCssConnectedFace)');
63 document.fonts.delete(nonCssConnectedFace); 92 document.fonts.delete(nonCssConnectedFace);
64 shouldBe('document.fonts.size', '3'); 93 shouldBe('document.fonts.size', '3');
65 94
66 document.fonts.add(nonCssConnectedFace); 95 document.fonts.add(nonCssConnectedFace);
67 shouldBe('document.fonts.size', '4'); 96 shouldBe('document.fonts.size', '4');
68 document.fonts.clear(); 97 document.fonts.clear();
69 shouldBe('document.fonts.size', '3'); 98 shouldBe('document.fonts.size', '3');
70 } 99 }
71 100
72 if (document.fonts) 101 if (document.fonts)
73 runTests(); 102 runTests();
74 else 103 else
75 testFailed('document.fonts does not exist'); 104 testFailed('document.fonts does not exist');
76 105
77 </script> 106 </script>
78 </head> 107 </head>
79 <body> 108 <body>
80 </body> 109 </body>
81 </html> 110 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698