b65c57fbcf3a536ac40aa4da9172eb4c57a69db8
[WebKit-https.git] / LayoutTests / css3 / font-feature-settings-parsing.html
1 <html>
2 <head>
3 <style>
4 #valid_normal {
5     -webkit-font-feature-settings: normal;
6 }
7
8 #valid_value_1 {
9     -webkit-font-feature-settings: "dlig" 1;
10 }
11
12 #valid_value_2 {
13     -webkit-font-feature-settings: "swsh" 2;
14 }
15
16 #valid_value_on {
17     -webkit-font-feature-settings: "smcp" on;
18 }
19
20 #valid_value_off {
21     -webkit-font-feature-settings: "liga" off;
22 }
23
24 #valid_value_omit {
25     -webkit-font-feature-settings: "c2sc";
26 }
27
28 #valid_valuelist {
29     -webkit-font-feature-settings: "tnum", 'hist';
30 }
31
32 #valid_singlequote {
33     -webkit-font-feature-settings: 'PKRN';
34 }
35
36 #valid_unusual_tag {
37     -webkit-font-feature-settings: "!@#$";
38 }
39
40 #valid_tag_space {
41     -webkit-font-feature-settings: "a bc";
42 }
43
44 #valid_composite {
45     -webkit-font-feature-settings: "dlig" 1, 'smcp' on, 'lig ' off;
46 }
47
48 #invalid_ident {
49     -webkit-font-feature-settings: dlig;
50 }
51
52 #invalid_cases {
53     -webkit-font-feature-settings: dlig, DLIG, DLig;
54 }
55
56 #invalid_1 {
57     -webkit-font-feature-settings: 1;
58 }
59
60 #invalid_off {
61     -webkit-font-feature-settings: off;
62 }
63
64 #invalid_normal_duplicate {
65     -webkit-font-feature-settings: normal, normal;
66 }
67
68 #invalid_normal_list {
69     -webkit-font-feature-settings: normal, aaaa;
70 }
71
72 #invalid_longer_ident {
73     -webkit-font-feature-settings: aaaaa;
74 }
75
76 #invalid_longer_quote {
77     -webkit-font-feature-settings: "aaaaa";
78 }
79
80 #invalid_negative {
81     -webkit-font-feature-settings: aaaa -1;
82 }
83
84 #invalid_float {
85     -webkit-font-feature-settings: aaaa 1.5;
86 }
87
88 #invalid_missing_comma {
89     -webkit-font-feature-settings: aaaa "bbbb";
90 }
91
92 #invalid_missing_comma_ident {
93     -webkit-font-feature-settings: aaaa bbbb;
94 }
95
96 #invalid_comma {
97     -webkit-font-feature-settings: ,;
98 }
99
100 #invalid_ending_comma {
101     -webkit-font-feature-settings: aaaa,;
102 }
103
104 #invalid_beginning_comma {
105     -webkit-font-feature-settings: ,aaaa;
106 }
107
108 #invalid_on {
109     -webkit-font-feature-settings: aaaa, on;
110 }
111
112 #invalid_0 {
113     -webkit-font-feature-settings: "aaaa" 1, "bbbb", 0;
114 }
115
116 #invalid_composite {
117     -webkit-font-feature-settings: aaaaa on, dlig on, PKRN -1;
118 }
119 </style>
120 <style>
121 @font-face {
122     -webkit-font-feature-settings: 'liga';
123 }
124
125 @font-face {
126     -webkit-font-feature-settings: aaaaa;
127 }
128 </style>
129 <script src="../resources/js-test-pre.js"></script>
130 </head>
131 <body>
132 <div id="valid_normal"></div>
133 <div id="valid_value_1"></div>
134 <div id="valid_value_2"></div>
135 <div id="valid_value_on"></div>
136 <div id="valid_value_off"></div>
137 <div id="valid_value_omit"></div>
138 <div id="valid_valuelist"></div>
139 <div id="valid_singlequote"></div>
140 <div id="valid_unusual_tag"></div>
141 <div id="valid_tag_space"></div>
142 <div id="valid_composite"></div>
143
144 <div id="invalid_ident"></div>
145 <div id="invalid_cases"></div>
146 <div id="invalid_1"></div>
147 <div id="invalid_off"></div>
148 <div id="invalid_normal_duplicate"></div>
149 <div id="invalid_normal_list"></div>
150 <div id="invalid_longer_ident"></div>
151 <div id="invalid_longer_quote"></div>
152 <div id="invalid_negative"></div>
153 <div id="invalid_float"></div>
154 <div id="invalid_missing_comma"></div>
155 <div id="invalid_missing_comma_ident"></div>
156 <div id="invalid_comma"></div>
157 <div id="invalid_ending_comma"></div>
158 <div id="invalid_beginning_comma"></div>
159 <div id="invalid_on"></div>
160 <div id="invalid_0"></div>
161
162 <div id="outer" style="-webkit-font-feature-settings: 'dlig';">
163   <div id="inner"></div>
164 </div>
165
166 <p id="description"></p>
167 <div id="console"></div>
168 <script>
169 description('Test parsing of the CSS3 font-feature-settings property.');
170
171 function canonicalize(fontFeatureSettingsString) {
172     var pieces = fontFeatureSettingsString.split(", ");
173     var lowered = pieces.map(function(piece) {
174         return piece.toLowerCase();
175     });
176     var sorted = lowered.sort();
177     return sorted.join(", ");
178 }
179
180 function parseResultOf(id) {
181     var element = document.getElementById(id);
182     return window.getComputedStyle(element)['-webkit-font-feature-settings'];
183 }
184
185 debug('- Tests valid inputs.');
186 shouldBeEqualToString('canonicalize(parseResultOf("valid_normal"))', canonicalize("normal"));
187 shouldBeEqualToString('canonicalize(parseResultOf("valid_value_1"))', canonicalize("'dlig' 1"));
188 shouldBeEqualToString('canonicalize(parseResultOf("valid_value_2"))', canonicalize("'swsh' 2"));
189 shouldBeEqualToString('canonicalize(parseResultOf("valid_value_on"))', canonicalize("'smcp' 1"));
190 shouldBeEqualToString('canonicalize(parseResultOf("valid_value_off"))', canonicalize("'liga' 0"));
191 shouldBeEqualToString('canonicalize(parseResultOf("valid_value_omit"))', canonicalize("'c2sc' 1"));
192 shouldBeEqualToString('canonicalize(parseResultOf("valid_valuelist"))', canonicalize("'tnum' 1, 'hist' 1"));
193 shouldBeEqualToString('canonicalize(parseResultOf("valid_singlequote"))', canonicalize("'PKRN' 1"));
194 shouldBeEqualToString('canonicalize(parseResultOf("valid_unusual_tag"))', canonicalize("'!@#$' 1"));
195 shouldBeEqualToString('canonicalize(parseResultOf("valid_tag_space"))', canonicalize("'a bc' 1"));
196 shouldBeEqualToString('canonicalize(parseResultOf("valid_composite"))', canonicalize("'dlig' 1, 'smcp' 1, 'lig ' 0"));
197
198 debug('- Tests invalid inputs.  Results should be "normal".');
199 shouldBe('parseResultOf("invalid_ident")', '"normal"');
200 shouldBe('parseResultOf("invalid_cases")', '"normal"');
201 shouldBe('parseResultOf("invalid_1")', '"normal"');
202 shouldBe('parseResultOf("invalid_off")', '"normal"');
203 shouldBe('parseResultOf("invalid_normal_duplicate")', '"normal"');
204 shouldBe('parseResultOf("invalid_normal_list")', '"normal"');
205 shouldBe('parseResultOf("invalid_longer_ident")', '"normal"');
206 shouldBe('parseResultOf("invalid_longer_quote")', '"normal"');
207 shouldBe('parseResultOf("invalid_negative")', '"normal"');
208 shouldBe('parseResultOf("invalid_float")', '"normal"');
209 shouldBe('parseResultOf("invalid_missing_comma")', '"normal"');
210 shouldBe('parseResultOf("invalid_missing_comma_ident")', '"normal"');
211 shouldBe('parseResultOf("invalid_comma")', '"normal"');
212 shouldBe('parseResultOf("invalid_ending_comma")', '"normal"');
213 shouldBe('parseResultOf("invalid_beginning_comma")', '"normal"');
214 shouldBe('parseResultOf("invalid_on")', '"normal"');
215 shouldBe('parseResultOf("invalid_0")', '"normal"');
216
217 debug('- Tests inherit.');
218 shouldBeEqualToString('canonicalize(parseResultOf("outer"))', canonicalize("'dlig' 1"));
219 shouldBeEqualToString('canonicalize(parseResultOf("inner"))', canonicalize("'dlig' 1"));
220
221 debug('- Tests @font-face.');
222 var fontFaceRuleValid = document.styleSheets[1].cssRules[0].style['-webkit-font-feature-settings'];
223 var fontFaceRuleInvalid = document.styleSheets[1].cssRules[1].style['-webkit-font-feature-settings'];
224 shouldBeEqualToString('canonicalize(fontFaceRuleValid)', canonicalize("'liga' 1"));
225 shouldBeEqualToString('fontFaceRuleInvalid', "");
226
227 </script>
228 <script src="../resources/js-test-post.js"></script>
229 </body>
230 </html>