FontFaceSet binding does not handle null correctly
[WebKit-https.git] / LayoutTests / fast / text / font-face-set-javascript.html
1 <!DOCTYPE html>
2 <head>
3 <script src="../../resources/js-test-pre.js"></script>
4 </head>
5 <body>
6 <script>
7 if (window.internals)
8     internals.clearMemoryCache();
9
10 var fontFace1 = new FontFace("family1", "url('asdf')", {});
11 var fontFace2 = new FontFace("family2", "url('asdf')", {});
12 var fontFace3 = new FontFace("family3", "url('../../resources/Ahem.ttf')", {});
13 var fontFace4 = new FontFace("family3", "url('../../resources/Ahem.ttf')", {'weight': 'bold'});
14 var fontFace5 = new FontFace("family5", "url('../../resources/Ahem.otf')", {});
15
16 shouldThrow("new FontFaceSet()");
17 shouldBe("new FontFaceSet([]).size", "0");
18 shouldBe("new FontFaceSet([fontFace1]).size", "1");
19
20 var fontFaceSet = new FontFaceSet([]);
21 shouldBeEqualToString("fontFaceSet.status", "loaded");
22 fontFaceSet.add(fontFace1);
23 var iterator = fontFaceSet.entries();
24 var item = iterator.next();
25 shouldBeFalse("item.done");
26 shouldBe("item.value", "[fontFace1, fontFace1]");
27 item = iterator.next();
28 shouldBeTrue("item.done");
29
30 iterator = fontFaceSet.keys();
31 item = iterator.next();
32 shouldBeFalse("item.done");
33 shouldBe("item.value", "fontFace1");
34 item = iterator.next();
35 shouldBeTrue("item.done");
36
37 iterator = fontFaceSet.values();
38 item = iterator.next();
39 shouldBeFalse("item.done");
40 shouldBe("item.value", "fontFace1");
41 item = iterator.next();
42 shouldBeTrue("item.done");
43
44 shouldBe("fontFaceSet.add(fontFace2)", "fontFaceSet");
45 shouldBe("fontFaceSet.size", "2");
46
47 shouldThrow("fontFaceSet.add(null)");
48
49 iterator = fontFaceSet.keys();
50 item = iterator.next();
51 shouldBeFalse("item.done");
52 shouldBe("item.value", "fontFace1");
53 item = iterator.next();
54 shouldBeFalse("item.done");
55 shouldBe("item.value", "fontFace2");
56 item = iterator.next();
57 shouldBeTrue("item.done");
58
59 shouldBe("fontFaceSet.delete(fontFace1)", "true");
60 shouldBe("fontFaceSet.delete(fontFace3)", "false");
61
62 shouldThrow("fontFaceSet.delete(null)");
63
64 shouldBeFalse("fontFaceSet.has(fontFace1)");
65 shouldBeTrue("fontFaceSet.has(fontFace2)");
66 shouldThrow("fontFaceSet.has(null)");
67
68 fontFaceSet.clear();
69
70 shouldBe("fontFaceSet.size", "0");
71 shouldBeTrue("fontFaceSet.values().next().done");
72 shouldThrow("fontFaceSet.check('garbage')");
73 shouldBeTrue("fontFaceSet.check('16px garbage')");
74
75 self.jsTestIsAsync = true;
76 fontFaceSet.add(fontFace1);
77 shouldBeFalse("fontFaceSet.check('16px family1')");
78 var item;
79 fontFaceSet.load("garbage").then(function(arg) {
80     testFailed("Should not be able to parse garbage");
81     finishJSTest();
82 }, function(arg) {
83     item = arg;
84     shouldBe("item.code", "item.SYNTAX_ERR");
85     shouldBeFalse("fontFaceSet.check('16px family1')");
86     return fontFaceSet.load("16px garbage");
87 }).then(function(arg) {
88     item = arg;
89     shouldBe("item", "[]");
90     return fontFaceSet.load("16px family1");
91 }, function(arg) {
92     testFailed("Should not be able to parse garbage");
93     finishJSTest();
94 }).then(function(arg) {
95     testFailed("Bogus URL should not load");
96     finishJSTest();
97 }, function(arg) {
98     item = arg;
99     shouldBe("item.code", "item.NETWORK_ERR");
100     fontFaceSet.add(fontFace3);
101     shouldBeFalse("fontFaceSet.check('16px family3')");
102     var result = fontFaceSet.load("16px family3");
103     shouldBeEqualToString("fontFaceSet.status", "loading");
104     return result;
105 }).then(function(arg) {
106     item = arg;
107     shouldBe("item", "[fontFace3]");
108     shouldBeTrue("fontFaceSet.check('16px family3')");
109     shouldBeEqualToString("fontFaceSet.status", "loaded");
110     var result = fontFaceSet.load("16px family3"); // Test when it's in the cache.
111     shouldBeEqualToString("fontFaceSet.status", "loaded");
112     return result;
113 }, function(arg) {
114     testFailed("Real URL should load");
115     finishJSTest();
116 }).then(function(arg) {
117     item = arg;
118     shouldBe("item", "[fontFace3]");
119     fontFaceSet.add(fontFace4);
120     return fontFaceSet.load("16px family3");
121 }, function(arg) {
122     testFailed("Real URL should load");
123     finishJSTest();
124 }).then(function(arg) {
125     item = arg;
126     shouldBe("item", "[fontFace3, fontFace4]");
127     fontFaceSet.add(fontFace4);
128     fontFaceSet.load("16px family3");
129     return fontFaceSet.ready;
130 }, function(arg) {
131     testFailed("Multiple matching faces should load");
132     finishJSTest();
133 }).then(function(arg) {
134     item = arg;
135     shouldBe("item", "fontFaceSet");
136     fontFaceSet.add(fontFace5);
137     shouldBeEqualToString("fontFaceSet.status", "loaded");
138     fontFaceSet.load("16px family5");
139     shouldBeEqualToString("fontFaceSet.status", "loading");
140     return fontFaceSet.ready;
141 }, function(arg) {
142     testFailed("Ready attribute should never fail");
143     finishJSTest();
144 }).then(function(arg) {
145     item = arg;
146     shouldBe("item", "fontFaceSet");
147     finishJSTest();
148 }, function(arg) {
149     testFailed("Ready attribute should never fail");
150     finishJSTest();
151 });
152 shouldBeEqualToString("fontFaceSet.status", "loaded");
153 </script>
154 <script src="../../resources/js-test-post.js"></script>
155 </body>
156 </html>