Regression(r188105): Seems to have caused crashes during PLT on some iPads
[WebKit-https.git] / LayoutTests / fast / css / css-lang-selector-with-string-arguments-text.html
1 <html>
2 <head id="head">
3 <script src="../../resources/js-test-pre.js"></script>
4 </head>
5 <body>
6 <script>
7
8 description("This tests parsing and re-serialization of :lang CSS selector with string arguments");
9
10 function parseThenSerializeRule(rule)
11 {
12     var styleElement = document.getElementById("style");
13     var head = document.getElementById("head");
14     if (styleElement)
15         head.removeChild(styleElement);
16
17     styleElement = document.createElement("style");
18     styleElement.id = "style";
19     var head = document.getElementById("head");
20     head.appendChild(styleElement);
21     
22     styleElement.appendChild(document.createTextNode(rule));
23     return styleElement.sheet.cssRules[0].cssText;
24 }
25
26 function expectedSerializedSelector(selector)
27 {
28     var args = /\(([^)]+)/.exec(selector);
29     if (!args[1])
30         return;
31
32     args = args[1].split(/\s*,\s*/);
33     var expected = ':lang(';
34     for (var i = 0; i < args.length; ++i) {
35         var arg = args[i];
36         var hasQuotes = arg.indexOf('"') == 0 && arg.lastIndexOf('"') == arg.length - 1;
37         if (!hasQuotes)
38             expected += '"';
39         expected += args[i];
40         if (!hasQuotes)
41             expected += '"';
42         if (i < args.length - 1)
43             expected += ', ';
44     }
45     expected += ')';
46     return expected;
47 }
48
49 function testSelectorRoundTrip(selector)
50 {
51     shouldBe("parseThenSerializeRule('" + selector + " { }')", "'" + expectedSerializedSelector(selector) + " { }'");
52 }
53
54 testSelectorRoundTrip(':lang("a")');
55 testSelectorRoundTrip(':lang("bb", cc)');
56 testSelectorRoundTrip(':lang("ddd", eee)');
57 testSelectorRoundTrip(':lang("ddd", eee, ffff)');
58 testSelectorRoundTrip(':lang("ddd", eee, "ffff")');
59 testSelectorRoundTrip(':lang("*-1997")');
60 testSelectorRoundTrip(':lang("*-1997", "*-1998")');
61 testSelectorRoundTrip(':lang("*-1997", "*-1998", "*-1999")');
62 testSelectorRoundTrip(':lang("")');
63
64 debug('');
65
66 shouldBe("parseThenSerializeRule(':lang(foo, \"bar\", baz) { }')", "':lang(\"foo\", \"bar\", \"baz\") { }'");
67 shouldBe("parseThenSerializeRule(':lang(foo,      \"bar\"     , baz) { }')", "':lang(\"foo\", \"bar\", \"baz\") { }'");
68 shouldBe("parseThenSerializeRule(':lang(    foo    ,     \"bar\"    ,     baz    ) { }')", "':lang(\"foo\", \"bar\", \"baz\") { }'");
69 </script>
70 <script src="../../resources/js-test-post.js"></script>
71 </body>
72 </html>