1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_namespace_rule.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,462 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for CSS Namespace rules</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body onload="run()"> 1.12 +<p id="display"><iframe id="iframe" src="data:application/xhtml+xml,<html%20xmlns='http://www.w3.org/1999/xhtml'><head/><body/></html>"></iframe></p> 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 + 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 + 1.18 +var HTML_NS = "http://www.w3.org/1999/xhtml"; 1.19 +var style_text; 1.20 + 1.21 +function run() { 1.22 + var iframe = $("iframe"); 1.23 + var ifwin = iframe.contentWindow; 1.24 + var ifdoc = iframe.contentDocument; 1.25 + var ifbody = ifdoc.getElementsByTagName("body")[0]; 1.26 + 1.27 + function setup_style_text() { 1.28 + var style_elem = ifdoc.createElement("style"); 1.29 + style_elem.setAttribute("type", "text/css"); 1.30 + ifdoc.getElementsByTagName("head")[0].appendChild(style_elem); 1.31 + var style_text = ifdoc.createCDATASection(""); 1.32 + style_elem.appendChild(style_text); 1.33 + return style_text; 1.34 + } 1.35 + 1.36 + style_text = setup_style_text(); 1.37 + var gCounter = 0; 1.38 + 1.39 + /* 1.40 + * namespaceRules: the @namespace rules to use 1.41 + * selector: the selector to test 1.42 + * body_contents: what to set the body's innerHTML to 1.43 + * match_fn: a function that, given the document object into which 1.44 + * body_contents has been inserted, produces an array of nodes that 1.45 + * should match selector 1.46 + * notmatch_fn: likewise, but for nodes that should not match 1.47 + */ 1.48 + function test_selector_in_html(namespaceRules, selector, body_contents, 1.49 + match_fn, notmatch_fn) 1.50 + { 1.51 + var zi = ++gCounter; 1.52 + if (typeof(body_contents) == "string") { 1.53 + ifbody.innerHTML = body_contents; 1.54 + } else { 1.55 + // It's a function. 1.56 + ifbody.innerHTML = ""; 1.57 + body_contents(ifbody); 1.58 + } 1.59 + style_text.data = 1.60 + namespaceRules + " " + selector + "{ z-index: " + zi + " }"; 1.61 + var should_match = match_fn(ifdoc); 1.62 + var should_not_match = notmatch_fn(ifdoc); 1.63 + if (should_match.length + should_not_match.length == 0) { 1.64 + ok(false, "nothing to check"); 1.65 + } 1.66 + 1.67 + for (var i = 0; i < should_match.length; ++i) { 1.68 + var e = should_match[i]; 1.69 + is(ifwin.getComputedStyle(e, "").zIndex, zi, 1.70 + "element in " + body_contents + " matched " + selector); 1.71 + } 1.72 + for (var i = 0; i < should_not_match.length; ++i) { 1.73 + var e = should_not_match[i]; 1.74 + is(ifwin.getComputedStyle(e, "").zIndex, "auto", 1.75 + "element in " + body_contents + " did not match " + selector); 1.76 + } 1.77 + 1.78 + // Now, since we're here, may as well make sure serialization 1.79 + // works correctly. It need not produce the exact same text, 1.80 + // but it should produce a selector that matches the same 1.81 + // elements. 1.82 + zi = ++gCounter; 1.83 + var ruleList = style_text.parentNode.sheet.cssRules; 1.84 + var ser1 = ruleList[ruleList.length-1].selectorText; 1.85 + style_text.data = 1.86 + namespaceRules + " " + ser1 + "{ z-index: " + zi + " }"; 1.87 + for (var i = 0; i < should_match.length; ++i) { 1.88 + var e = should_match[i]; 1.89 + is(ifwin.getComputedStyle(e, "").zIndex, zi, 1.90 + "element in " + body_contents + " matched " + ser1 + 1.91 + " which is the reserialization of " + selector); 1.92 + } 1.93 + for (var i = 0; i < should_not_match.length; ++i) { 1.94 + var e = should_not_match[i]; 1.95 + is(ifwin.getComputedStyle(e, "").zIndex, "auto", 1.96 + "element in " + body_contents + " did not match " + ser1 + 1.97 + " which is the reserialization of " + selector); 1.98 + } 1.99 + 1.100 + // But when we serialize the serialized result, we should get 1.101 + // the same text. 1.102 + var ser2 = ruleList[ruleList.length-1].selectorText; 1.103 + is(ser2, ser1, "parse+serialize of selector \"" + selector + 1.104 + "\" is idempotent"); 1.105 + 1.106 + ifbody.innerHTML = ""; 1.107 + style_text.data = ""; 1.108 + } 1.109 + 1.110 + // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-001.xml 1.111 + test_selector_in_html( 1.112 + '@namespace foo "x"; @namespace Foo "y";', 1.113 + 'Foo|test', 1.114 + '<test xmlns="y"/>', 1.115 + function (doc) { return doc.getElementsByTagName("test"); }, 1.116 + function (doc) { return []; } 1.117 + ); 1.118 + 1.119 + test_selector_in_html( 1.120 + '@namespace foo "x"; @namespace Foo "y";', 1.121 + 'foo|test', 1.122 + '<test xmlns="y"/>', 1.123 + function (doc) { return []; }, 1.124 + function (doc) { return doc.getElementsByTagName("test");} 1.125 + ); 1.126 + 1.127 + // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-002.xml 1.128 + test_selector_in_html( 1.129 + '@namespace foo "";', 1.130 + 'test', 1.131 + '<test xmlns=""/>', 1.132 + function (doc) { return doc.getElementsByTagName("test");}, 1.133 + function (doc) { return []; } 1.134 + ); 1.135 + 1.136 + test_selector_in_html( 1.137 + '@namespace foo "";', 1.138 + 'foo|test', 1.139 + '<test xmlns=""/>', 1.140 + function (doc) { return doc.getElementsByTagName("test");}, 1.141 + function (doc) { return []; } 1.142 + ); 1.143 + 1.144 + // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-003.xml 1.145 + test_selector_in_html( 1.146 + '@namespace foo "";', 1.147 + 'test', 1.148 + '<foo xmlns=""><test/></foo>', 1.149 + function (doc) { return doc.getElementsByTagName("test");}, 1.150 + function (doc) { return []; } 1.151 + ); 1.152 + 1.153 + test_selector_in_html( 1.154 + '@namespace foo "";', 1.155 + 'foo|test', 1.156 + '<foo xmlns=""><test/></foo>', 1.157 + function (doc) { return doc.getElementsByTagName("test");}, 1.158 + function (doc) { return []; } 1.159 + ); 1.160 + 1.161 + // 4 tests from http://tc.labs.opera.com/css/namespaces/prefix-004.xml 1.162 + test_selector_in_html( 1.163 + '@namespace ""; @namespace x "test";', 1.164 + 'test[x]', 1.165 + '<foo xmlns=""><test x=""/></foo>', 1.166 + function (doc) { return doc.getElementsByTagName("test");}, 1.167 + function (doc) { return []; } 1.168 + ); 1.169 + 1.170 + test_selector_in_html( 1.171 + '@namespace ""; @namespace x "test";', 1.172 + '*|test', 1.173 + '<foo xmlns=""><test x=""/></foo>', 1.174 + function (doc) { return doc.getElementsByTagName("test");}, 1.175 + function (doc) { return []; } 1.176 + ); 1.177 + 1.178 + test_selector_in_html( 1.179 + '@namespace ""; @namespace x "test";', 1.180 + '*|test', 1.181 + '<test xmlns="test"/>', 1.182 + function (doc) { return doc.getElementsByTagName("test");}, 1.183 + function (doc) { return []; } 1.184 + ); 1.185 + 1.186 + test_selector_in_html( 1.187 + '@namespace ""; @namespace x "test";', 1.188 + 'test', 1.189 + '<test xmlns="test"/>', 1.190 + function (doc) { return []; }, 1.191 + function (doc) { return doc.getElementsByTagName("test");} 1.192 + ); 1.193 + 1.194 + // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-005.xml 1.195 + test_selector_in_html( 1.196 + '@namespace x "test";', 1.197 + 'test', 1.198 + '<test/>', 1.199 + function (doc) { return doc.getElementsByTagName("test");}, 1.200 + function (doc) { return []; } 1.201 + ); 1.202 + 1.203 + test_selector_in_html( 1.204 + '@namespace x "test";', 1.205 + 'test', 1.206 + '<test xmlns="test"/>', 1.207 + function (doc) { return doc.getElementsByTagName("test");}, 1.208 + function (doc) { return []; } 1.209 + ); 1.210 + 1.211 + // Skipping the scope tests because they involve import, and we have no way 1.212 + // to know when the import load completes. 1.213 + 1.214 + // 1 test from http://tc.labs.opera.com/css/namespaces/syntax-001.xml 1.215 + test_selector_in_html( 1.216 + '@NAmespace x "http://www.w3.org/1999/xhtml";', 1.217 + 'x|test', 1.218 + '<test/>', 1.219 + function (doc) { return doc.getElementsByTagName("test");}, 1.220 + function (doc) { return []; } 1.221 + ); 1.222 + 1.223 + // 1 test from http://tc.labs.opera.com/css/namespaces/syntax-002.xml 1.224 + test_selector_in_html( 1.225 + '@NAmespac\\65 x "http://www.w3.org/1999/xhtml";', 1.226 + 'x|test', 1.227 + '<test/>', 1.228 + function (doc) { return doc.getElementsByTagName("test");}, 1.229 + function (doc) { return []; } 1.230 + ); 1.231 + 1.232 + // 3 tests from http://tc.labs.opera.com/css/namespaces/syntax-003.xml 1.233 + test_selector_in_html( 1.234 + '@namespace url("test");', 1.235 + '*|test', 1.236 + '<test xmlns="test"/>', 1.237 + function (doc) { return doc.getElementsByTagName("test");}, 1.238 + function (doc) { return []; } 1.239 + ); 1.240 + 1.241 + test_selector_in_html( 1.242 + '@namespace url("test");', 1.243 + 'test', 1.244 + '<test xmlns="test"/>', 1.245 + function (doc) { return doc.getElementsByTagName("test");}, 1.246 + function (doc) { return []; } 1.247 + ); 1.248 + 1.249 + test_selector_in_html( 1.250 + '@namespace url("test");', 1.251 + 'test', 1.252 + '<test/>', 1.253 + function (doc) { return []; }, 1.254 + function (doc) { return doc.getElementsByTagName("test");} 1.255 + ); 1.256 + 1.257 + // 3 tests from http://tc.labs.opera.com/css/namespaces/syntax-004.xml 1.258 + test_selector_in_html( 1.259 + '@namespace u\\00072l("test");', 1.260 + '*|test', 1.261 + '<test xmlns="test"/>', 1.262 + function (doc) { return doc.getElementsByTagName("test");}, 1.263 + function (doc) { return []; } 1.264 + ); 1.265 + 1.266 + test_selector_in_html( 1.267 + '@namespace u\\00072l("test");', 1.268 + 'test', 1.269 + '<test xmlns="test"/>', 1.270 + function (doc) { return doc.getElementsByTagName("test");}, 1.271 + function (doc) { return []; } 1.272 + ); 1.273 + 1.274 + test_selector_in_html( 1.275 + '@namespace u\\00072l("test");', 1.276 + 'test', 1.277 + '<test/>', 1.278 + function (doc) { return []; }, 1.279 + function (doc) { return doc.getElementsByTagName("test");} 1.280 + ); 1.281 + 1.282 + // Skipping http://tc.labs.opera.com/css/namespaces/syntax-005.xml because it 1.283 + // involves import, and we have no way // to know when the import load completes. 1.284 + 1.285 + // Skipping http://tc.labs.opera.com/css/namespaces/syntax-006.xml because it 1.286 + // involves import, and we have no way // to know when the import load completes. 1.287 + 1.288 + // 2 tests from http://tc.labs.opera.com/css/namespaces/syntax-007.xml 1.289 + test_selector_in_html( 1.290 + '@charset "x"; @namespace url("test"); @namespace url("test2");', 1.291 + '*|test', 1.292 + '<test xmlns="test"/>', 1.293 + function (doc) { return doc.getElementsByTagName("test");}, 1.294 + function (doc) { return []; } 1.295 + ); 1.296 + 1.297 + test_selector_in_html( 1.298 + '@charset "x"; @namespace url("test"); @namespace url("test2");', 1.299 + 'test', 1.300 + '<test xmlns="test"/>', 1.301 + function (doc) { return []; }, 1.302 + function (doc) { return doc.getElementsByTagName("test");} 1.303 + ); 1.304 + 1.305 + // 2 tests from http://tc.labs.opera.com/css/namespaces/syntax-008.xml 1.306 + test_selector_in_html( 1.307 + '@namespace \\72x url("test");', 1.308 + 'rx|test', 1.309 + '<test xmlns="test"/>', 1.310 + function (doc) { return doc.getElementsByTagName("test");}, 1.311 + function (doc) { return []; } 1.312 + ); 1.313 + 1.314 + test_selector_in_html( 1.315 + '@namespace \\72x url("test");', 1.316 + 'test', 1.317 + '<test xmlns="test"/>', 1.318 + function (doc) { return doc.getElementsByTagName("test");}, 1.319 + function (doc) { return []; } 1.320 + ); 1.321 + 1.322 + // And now some :not() tests 1.323 + test_selector_in_html( 1.324 + '@namespace url("test");', 1.325 + '*|*:not(test)', 1.326 + '<test xmlns="test"/>', 1.327 + function (doc) { return []; }, 1.328 + function (doc) { return doc.getElementsByTagName("test");} 1.329 + ); 1.330 + 1.331 + test_selector_in_html( 1.332 + '@namespace url("test");', 1.333 + '*|*:not(test)', 1.334 + '<test xmlns="testing"/>', 1.335 + function (doc) { return doc.getElementsByTagName("test");}, 1.336 + function (doc) { return []; } 1.337 + ); 1.338 + 1.339 + test_selector_in_html( 1.340 + '@namespace x url("test");', 1.341 + '*|*:not(x|test)', 1.342 + '<test xmlns="test"/>', 1.343 + function (doc) { return []; }, 1.344 + function (doc) { return doc.getElementsByTagName("test");} 1.345 + ); 1.346 + 1.347 + test_selector_in_html( 1.348 + '@namespace x url("test");', 1.349 + '*|*:not(x|test)', 1.350 + '<test xmlns="testing"/>', 1.351 + function (doc) { return doc.getElementsByTagName("test");}, 1.352 + function (doc) { return []; } 1.353 + ); 1.354 + 1.355 + test_selector_in_html( 1.356 + '@namespace url("test");', 1.357 + '*|*:not(*)', 1.358 + '<test xmlns="testing"/>', 1.359 + function (doc) { return doc.getElementsByTagName("test");}, 1.360 + function (doc) { return []; } 1.361 + ); 1.362 + 1.363 + test_selector_in_html( 1.364 + '@namespace url("test");', 1.365 + '*|*:not(*)', 1.366 + '<test xmlns="test"/>', 1.367 + function (doc) { return []; }, 1.368 + function (doc) { return doc.getElementsByTagName("test");} 1.369 + ); 1.370 + 1.371 + test_selector_in_html( 1.372 + '@namespace x url("test");', 1.373 + '*|*:not(x|*)', 1.374 + '<test xmlns="testing"/>', 1.375 + function (doc) { return doc.getElementsByTagName("test");}, 1.376 + function (doc) { return []; } 1.377 + ); 1.378 + 1.379 + test_selector_in_html( 1.380 + '@namespace x url("test");', 1.381 + '*|*:not(x|*)', 1.382 + '<test xmlns="test"/>', 1.383 + function (doc) { return []; }, 1.384 + function (doc) { return doc.getElementsByTagName("test");} 1.385 + ); 1.386 + 1.387 + test_selector_in_html( 1.388 + '@namespace url("test");', 1.389 + '*|*:not([foo])', 1.390 + '<test xmlns="testing" foo="bar"/>', 1.391 + function (doc) { return []; }, 1.392 + function (doc) { return doc.getElementsByTagName("test");} 1.393 + ); 1.394 + 1.395 + test_selector_in_html( 1.396 + '@namespace url("test");', 1.397 + '*|*:not([foo])', 1.398 + '<test xmlns="test" foo="bar"/>', 1.399 + function (doc) { return []; }, 1.400 + function (doc) { return doc.getElementsByTagName("test");} 1.401 + ); 1.402 + 1.403 + test_selector_in_html( 1.404 + '@namespace url("test");', 1.405 + '*|*[foo]', 1.406 + '<test foo="bar"/>', 1.407 + function (doc) { return doc.getElementsByTagName("test");}, 1.408 + function (doc) { return []; } 1.409 + ); 1.410 + 1.411 + test_selector_in_html( 1.412 + '@namespace url("test");', 1.413 + '*|*[|foo]', 1.414 + '<test foo="bar"/>', 1.415 + function (doc) { return doc.getElementsByTagName("test");}, 1.416 + function (doc) { return []; } 1.417 + ); 1.418 + 1.419 + test_selector_in_html( 1.420 + '@namespace test url("test");', 1.421 + '*|*[test|foo]', 1.422 + '<test foo="bar"/>', 1.423 + function (doc) { return []; }, 1.424 + function (doc) { return doc.getElementsByTagName("test");} 1.425 + ); 1.426 + 1.427 + test_selector_in_html( 1.428 + '@namespace test url("test");', 1.429 + '*|*[test|foo]', 1.430 + '<test xmlns:t="test" t:foo="bar"/>', 1.431 + function (doc) { return doc.getElementsByTagName("test");}, 1.432 + function (doc) { return []; } 1.433 + ); 1.434 + 1.435 + test_selector_in_html( 1.436 + '@namespace url("test");', 1.437 + '*|*[foo]', 1.438 + '<test xmlns:t="test" t:foo="bar"/>', 1.439 + function (doc) { return []; }, 1.440 + function (doc) { return doc.getElementsByTagName("test");} 1.441 + ); 1.442 + 1.443 + test_selector_in_html( 1.444 + '@namespace url("test");', 1.445 + '*|*[*|foo]', 1.446 + '<test xmlns:t="test" t:foo="bar"/>', 1.447 + function (doc) { return doc.getElementsByTagName("test");}, 1.448 + function (doc) { return []; } 1.449 + ); 1.450 + 1.451 + test_selector_in_html( 1.452 + '', 1.453 + '*|*[*|foo]', 1.454 + '<test xmlns:t="test" t:foo="bar"/>', 1.455 + function (doc) { return doc.getElementsByTagName("test");}, 1.456 + function (doc) { return []; } 1.457 + ); 1.458 + 1.459 + SimpleTest.finish(); 1.460 +} 1.461 + 1.462 +</script> 1.463 +</pre> 1.464 +</body> 1.465 +</html>