0e6c7b76774d6c1786f73af59cb74ed60dff587c
[WebKit.git] / LayoutTests / fast / text / font-face-javascript.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <script>
8 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).family", "family_name");
9 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).style", "normal");
10 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).weight", "normal");
11 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).stretch", "normal");
12 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).unicodeRange", "U+0-10ffff");
13 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).variant", "normal");
14 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).featureSettings", "normal");
15
16 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'style': 'normal'}).style", "normal");
17 shouldThrow("new FontFace('family_name', 'url(\\'asdf\\')', {'style': 'inherit'}).style");
18 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'style': 'italic'}).style", "italic");
19 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'style': 'oblique'}).style", "italic");
20 shouldThrow("new FontFace('family_name', 'url(\\'asdf\\')', {'style': 'asdf'})");
21 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': 'normal'}).weight", "normal");
22 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': '200'}).weight", "200");
23 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': 'bold'}).weight", "bold");
24 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': 'bolder'}).weight", "bold");
25 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': 'lighter'}).weight", "200");
26 shouldThrow("new FontFace('family_name', 'url(\\'asdf\\')', {'weight': 'inherit'}).weight");
27 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'stretch': 'stretch_name'}).stretch", "normal");
28 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'unicodeRange': 'U+26'}).unicodeRange", "U+26-26");
29 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'unicodeRange': 'U+0-7F'}).unicodeRange", "U+0-7f");
30 shouldThrow("new FontFace('family_name', 'url(\\'asdf\\')', {'variant': 'variant_name'}).variant");
31 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'variant': 'small-caps'}).variant", "small-caps");
32 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'variant': 'small-caps common-ligatures'}).variant", "common-ligatures small-caps");
33 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {'featureSettings': '\\'titl\\''}).featureSettings", "'titl' 1");
34
35 var everything = new FontFace('family_name', 'url(\'asdf\')', {'style': 'italic', 'weight': 'bold', 'stretch': 'stretch_name', 'unicodeRange': 'U+26', 'variant': 'small-caps', 'featureSettings': '\'titl\''});
36 shouldBeEqualToString("everything.style", "italic");
37 shouldBeEqualToString("everything.weight", "bold");
38 shouldBeEqualToString("everything.stretch", "normal");
39 shouldBeEqualToString("everything.unicodeRange", "U+26-26");
40 shouldBeEqualToString("everything.variant", "small-caps");
41 shouldBeEqualToString("everything.featureSettings", "'titl' 1");
42
43 everything.family = "other_family_name";
44 shouldBeEqualToString("everything.family", "other_family_name");
45 everything.style = "normal";
46 shouldBeEqualToString("everything.style", "normal");
47 everything.weight = "300";
48 shouldBeEqualToString("everything.weight", "300");
49 everything.stretch = "other_stretch_name";
50 shouldBeEqualToString("everything.stretch", "normal");
51 everything.unicodeRange = "U+0-7F";
52 shouldBeEqualToString("everything.unicodeRange", "U+0-7f");
53 everything.variant = "stacked-fractions";
54 shouldBeEqualToString("everything.variant", "stacked-fractions");
55 everything.featureSettings = "'smcp'";
56 shouldBeEqualToString("everything.featureSettings", "'smcp' 1");
57
58 shouldNotThrow("new FontFace('family_name', 'url(\\'asdf\\')', {})");
59 var newArrayBuffer = new ArrayBuffer(100);
60 shouldNotThrow("new FontFace('family_name', newArrayBuffer, {})");
61 shouldNotThrow("new FontFace('family_name', new DataView(newArrayBuffer), {})");
62 shouldNotThrow("new FontFace('family_name', new Uint8Array(newArrayBuffer), {})");
63 shouldThrow("new FontFace('family_name', 5, {})");
64 shouldThrow("new FontFace('family_name', {}, {})");
65 shouldThrow("new FontFace('family_name', new Array(), {})");
66 shouldThrow("new FontFace('family_name', { toString: function() { return 5; } }, {})");
67 shouldThrow("new FontFace('family_name', { toString: function() { throw \"Error\"; } }, {})");
68 shouldBeEqualToString("new FontFace('family_name', { toString: function() { return \"url(\'asdf\')\"; } }, {}).family", "family_name");
69
70 shouldBeEqualToString("new FontFace('family_name', 'url(\\'asdf\\')', {}).status", "unloaded");
71
72 var promiseEqualityCheck = new FontFace('family_name', 'url(\'asdf\')', {});
73 var promise1 = promiseEqualityCheck.loaded;
74 var promise2 = promiseEqualityCheck.loaded;
75 var promise3 = promiseEqualityCheck.load();
76 var promise4 = promiseEqualityCheck.loaded;
77 var promise5 = promiseEqualityCheck.load();
78 shouldBe("promise1", "promise2");
79 shouldBe("promise1", "promise3");
80 shouldBe("promise1", "promise4");
81 shouldBe("promise1", "promise5");
82 shouldBeEqualToString("promiseEqualityCheck.status", "loading");
83
84 var oldFontFace;
85 var newFontFace;
86 self.jsTestIsAsync = true;
87 promiseEqualityCheck.loaded.then(function(x) {
88     testFailed("Bogus URL should not load");
89     finishJSTest();
90 }, function(y) {
91     oldFontFace = y;
92     shouldBe("oldFontFace.code", "oldFontFace.NETWORK_ERR");
93     shouldBeEqualToString("promiseEqualityCheck.status", "error");
94     oldFontFace = new FontFace('family_name', 'url(\'../../resources/Ahem.ttf\')', {});
95     return oldFontFace.load();
96 }).then(function(x) {
97     newFontFace = x;
98     shouldBe("newFontFace", "oldFontFace");
99     shouldBeEqualToString("newFontFace.status", "loaded");
100     // Test behavior when the font is in the cache.
101     oldFontFace = new FontFace('family_name', 'url(\'../../resources/Ahem.ttf\')', {});
102     return oldFontFace.load();
103 }, function(y) {
104     testFailed("Legit URL should load");
105     finishJSTest();
106 }).then(function(x) {
107     newFontFace = x;
108     shouldBe("newFontFace", "oldFontFace");
109     shouldBeEqualToString("newFontFace.status", "loaded");
110     return (new FontFace('family_name2', 'url(\'../../resources/Ahem.ttf\') format(\'garbage\')', {})).load()
111 }, function(y) {
112     testFailed("Legit URL should load");
113     finishJSTest();
114 }).then(function() {
115     testFailed("Unknown format should not load successfully.");
116     finishJSTest();
117 }, function(y) {
118     oldFontFace = y;
119     shouldBe("oldFontFace.code", "oldFontFace.NETWORK_ERR");
120     finishJSTest();
121 });
122
123 </script>
124 <script src="../../resources/js-test-post.js"></script>
125 </body>
126 </html>