layout/style/test/test_namespace_rule.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for CSS Namespace rules</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body onload="run()">
michael@0 9 <p id="display"><iframe id="iframe" src="data:application/xhtml+xml,<html%20xmlns='http://www.w3.org/1999/xhtml'><head/><body/></html>"></iframe></p>
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14
michael@0 15 var HTML_NS = "http://www.w3.org/1999/xhtml";
michael@0 16 var style_text;
michael@0 17
michael@0 18 function run() {
michael@0 19 var iframe = $("iframe");
michael@0 20 var ifwin = iframe.contentWindow;
michael@0 21 var ifdoc = iframe.contentDocument;
michael@0 22 var ifbody = ifdoc.getElementsByTagName("body")[0];
michael@0 23
michael@0 24 function setup_style_text() {
michael@0 25 var style_elem = ifdoc.createElement("style");
michael@0 26 style_elem.setAttribute("type", "text/css");
michael@0 27 ifdoc.getElementsByTagName("head")[0].appendChild(style_elem);
michael@0 28 var style_text = ifdoc.createCDATASection("");
michael@0 29 style_elem.appendChild(style_text);
michael@0 30 return style_text;
michael@0 31 }
michael@0 32
michael@0 33 style_text = setup_style_text();
michael@0 34 var gCounter = 0;
michael@0 35
michael@0 36 /*
michael@0 37 * namespaceRules: the @namespace rules to use
michael@0 38 * selector: the selector to test
michael@0 39 * body_contents: what to set the body's innerHTML to
michael@0 40 * match_fn: a function that, given the document object into which
michael@0 41 * body_contents has been inserted, produces an array of nodes that
michael@0 42 * should match selector
michael@0 43 * notmatch_fn: likewise, but for nodes that should not match
michael@0 44 */
michael@0 45 function test_selector_in_html(namespaceRules, selector, body_contents,
michael@0 46 match_fn, notmatch_fn)
michael@0 47 {
michael@0 48 var zi = ++gCounter;
michael@0 49 if (typeof(body_contents) == "string") {
michael@0 50 ifbody.innerHTML = body_contents;
michael@0 51 } else {
michael@0 52 // It's a function.
michael@0 53 ifbody.innerHTML = "";
michael@0 54 body_contents(ifbody);
michael@0 55 }
michael@0 56 style_text.data =
michael@0 57 namespaceRules + " " + selector + "{ z-index: " + zi + " }";
michael@0 58 var should_match = match_fn(ifdoc);
michael@0 59 var should_not_match = notmatch_fn(ifdoc);
michael@0 60 if (should_match.length + should_not_match.length == 0) {
michael@0 61 ok(false, "nothing to check");
michael@0 62 }
michael@0 63
michael@0 64 for (var i = 0; i < should_match.length; ++i) {
michael@0 65 var e = should_match[i];
michael@0 66 is(ifwin.getComputedStyle(e, "").zIndex, zi,
michael@0 67 "element in " + body_contents + " matched " + selector);
michael@0 68 }
michael@0 69 for (var i = 0; i < should_not_match.length; ++i) {
michael@0 70 var e = should_not_match[i];
michael@0 71 is(ifwin.getComputedStyle(e, "").zIndex, "auto",
michael@0 72 "element in " + body_contents + " did not match " + selector);
michael@0 73 }
michael@0 74
michael@0 75 // Now, since we're here, may as well make sure serialization
michael@0 76 // works correctly. It need not produce the exact same text,
michael@0 77 // but it should produce a selector that matches the same
michael@0 78 // elements.
michael@0 79 zi = ++gCounter;
michael@0 80 var ruleList = style_text.parentNode.sheet.cssRules;
michael@0 81 var ser1 = ruleList[ruleList.length-1].selectorText;
michael@0 82 style_text.data =
michael@0 83 namespaceRules + " " + ser1 + "{ z-index: " + zi + " }";
michael@0 84 for (var i = 0; i < should_match.length; ++i) {
michael@0 85 var e = should_match[i];
michael@0 86 is(ifwin.getComputedStyle(e, "").zIndex, zi,
michael@0 87 "element in " + body_contents + " matched " + ser1 +
michael@0 88 " which is the reserialization of " + selector);
michael@0 89 }
michael@0 90 for (var i = 0; i < should_not_match.length; ++i) {
michael@0 91 var e = should_not_match[i];
michael@0 92 is(ifwin.getComputedStyle(e, "").zIndex, "auto",
michael@0 93 "element in " + body_contents + " did not match " + ser1 +
michael@0 94 " which is the reserialization of " + selector);
michael@0 95 }
michael@0 96
michael@0 97 // But when we serialize the serialized result, we should get
michael@0 98 // the same text.
michael@0 99 var ser2 = ruleList[ruleList.length-1].selectorText;
michael@0 100 is(ser2, ser1, "parse+serialize of selector \"" + selector +
michael@0 101 "\" is idempotent");
michael@0 102
michael@0 103 ifbody.innerHTML = "";
michael@0 104 style_text.data = "";
michael@0 105 }
michael@0 106
michael@0 107 // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-001.xml
michael@0 108 test_selector_in_html(
michael@0 109 '@namespace foo "x"; @namespace Foo "y";',
michael@0 110 'Foo|test',
michael@0 111 '<test xmlns="y"/>',
michael@0 112 function (doc) { return doc.getElementsByTagName("test"); },
michael@0 113 function (doc) { return []; }
michael@0 114 );
michael@0 115
michael@0 116 test_selector_in_html(
michael@0 117 '@namespace foo "x"; @namespace Foo "y";',
michael@0 118 'foo|test',
michael@0 119 '<test xmlns="y"/>',
michael@0 120 function (doc) { return []; },
michael@0 121 function (doc) { return doc.getElementsByTagName("test");}
michael@0 122 );
michael@0 123
michael@0 124 // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-002.xml
michael@0 125 test_selector_in_html(
michael@0 126 '@namespace foo "";',
michael@0 127 'test',
michael@0 128 '<test xmlns=""/>',
michael@0 129 function (doc) { return doc.getElementsByTagName("test");},
michael@0 130 function (doc) { return []; }
michael@0 131 );
michael@0 132
michael@0 133 test_selector_in_html(
michael@0 134 '@namespace foo "";',
michael@0 135 'foo|test',
michael@0 136 '<test xmlns=""/>',
michael@0 137 function (doc) { return doc.getElementsByTagName("test");},
michael@0 138 function (doc) { return []; }
michael@0 139 );
michael@0 140
michael@0 141 // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-003.xml
michael@0 142 test_selector_in_html(
michael@0 143 '@namespace foo "";',
michael@0 144 'test',
michael@0 145 '<foo xmlns=""><test/></foo>',
michael@0 146 function (doc) { return doc.getElementsByTagName("test");},
michael@0 147 function (doc) { return []; }
michael@0 148 );
michael@0 149
michael@0 150 test_selector_in_html(
michael@0 151 '@namespace foo "";',
michael@0 152 'foo|test',
michael@0 153 '<foo xmlns=""><test/></foo>',
michael@0 154 function (doc) { return doc.getElementsByTagName("test");},
michael@0 155 function (doc) { return []; }
michael@0 156 );
michael@0 157
michael@0 158 // 4 tests from http://tc.labs.opera.com/css/namespaces/prefix-004.xml
michael@0 159 test_selector_in_html(
michael@0 160 '@namespace ""; @namespace x "test";',
michael@0 161 'test[x]',
michael@0 162 '<foo xmlns=""><test x=""/></foo>',
michael@0 163 function (doc) { return doc.getElementsByTagName("test");},
michael@0 164 function (doc) { return []; }
michael@0 165 );
michael@0 166
michael@0 167 test_selector_in_html(
michael@0 168 '@namespace ""; @namespace x "test";',
michael@0 169 '*|test',
michael@0 170 '<foo xmlns=""><test x=""/></foo>',
michael@0 171 function (doc) { return doc.getElementsByTagName("test");},
michael@0 172 function (doc) { return []; }
michael@0 173 );
michael@0 174
michael@0 175 test_selector_in_html(
michael@0 176 '@namespace ""; @namespace x "test";',
michael@0 177 '*|test',
michael@0 178 '<test xmlns="test"/>',
michael@0 179 function (doc) { return doc.getElementsByTagName("test");},
michael@0 180 function (doc) { return []; }
michael@0 181 );
michael@0 182
michael@0 183 test_selector_in_html(
michael@0 184 '@namespace ""; @namespace x "test";',
michael@0 185 'test',
michael@0 186 '<test xmlns="test"/>',
michael@0 187 function (doc) { return []; },
michael@0 188 function (doc) { return doc.getElementsByTagName("test");}
michael@0 189 );
michael@0 190
michael@0 191 // 2 tests from http://tc.labs.opera.com/css/namespaces/prefix-005.xml
michael@0 192 test_selector_in_html(
michael@0 193 '@namespace x "test";',
michael@0 194 'test',
michael@0 195 '<test/>',
michael@0 196 function (doc) { return doc.getElementsByTagName("test");},
michael@0 197 function (doc) { return []; }
michael@0 198 );
michael@0 199
michael@0 200 test_selector_in_html(
michael@0 201 '@namespace x "test";',
michael@0 202 'test',
michael@0 203 '<test xmlns="test"/>',
michael@0 204 function (doc) { return doc.getElementsByTagName("test");},
michael@0 205 function (doc) { return []; }
michael@0 206 );
michael@0 207
michael@0 208 // Skipping the scope tests because they involve import, and we have no way
michael@0 209 // to know when the import load completes.
michael@0 210
michael@0 211 // 1 test from http://tc.labs.opera.com/css/namespaces/syntax-001.xml
michael@0 212 test_selector_in_html(
michael@0 213 '@NAmespace x "http://www.w3.org/1999/xhtml";',
michael@0 214 'x|test',
michael@0 215 '<test/>',
michael@0 216 function (doc) { return doc.getElementsByTagName("test");},
michael@0 217 function (doc) { return []; }
michael@0 218 );
michael@0 219
michael@0 220 // 1 test from http://tc.labs.opera.com/css/namespaces/syntax-002.xml
michael@0 221 test_selector_in_html(
michael@0 222 '@NAmespac\\65 x "http://www.w3.org/1999/xhtml";',
michael@0 223 'x|test',
michael@0 224 '<test/>',
michael@0 225 function (doc) { return doc.getElementsByTagName("test");},
michael@0 226 function (doc) { return []; }
michael@0 227 );
michael@0 228
michael@0 229 // 3 tests from http://tc.labs.opera.com/css/namespaces/syntax-003.xml
michael@0 230 test_selector_in_html(
michael@0 231 '@namespace url("test");',
michael@0 232 '*|test',
michael@0 233 '<test xmlns="test"/>',
michael@0 234 function (doc) { return doc.getElementsByTagName("test");},
michael@0 235 function (doc) { return []; }
michael@0 236 );
michael@0 237
michael@0 238 test_selector_in_html(
michael@0 239 '@namespace url("test");',
michael@0 240 'test',
michael@0 241 '<test xmlns="test"/>',
michael@0 242 function (doc) { return doc.getElementsByTagName("test");},
michael@0 243 function (doc) { return []; }
michael@0 244 );
michael@0 245
michael@0 246 test_selector_in_html(
michael@0 247 '@namespace url("test");',
michael@0 248 'test',
michael@0 249 '<test/>',
michael@0 250 function (doc) { return []; },
michael@0 251 function (doc) { return doc.getElementsByTagName("test");}
michael@0 252 );
michael@0 253
michael@0 254 // 3 tests from http://tc.labs.opera.com/css/namespaces/syntax-004.xml
michael@0 255 test_selector_in_html(
michael@0 256 '@namespace u\\00072l("test");',
michael@0 257 '*|test',
michael@0 258 '<test xmlns="test"/>',
michael@0 259 function (doc) { return doc.getElementsByTagName("test");},
michael@0 260 function (doc) { return []; }
michael@0 261 );
michael@0 262
michael@0 263 test_selector_in_html(
michael@0 264 '@namespace u\\00072l("test");',
michael@0 265 'test',
michael@0 266 '<test xmlns="test"/>',
michael@0 267 function (doc) { return doc.getElementsByTagName("test");},
michael@0 268 function (doc) { return []; }
michael@0 269 );
michael@0 270
michael@0 271 test_selector_in_html(
michael@0 272 '@namespace u\\00072l("test");',
michael@0 273 'test',
michael@0 274 '<test/>',
michael@0 275 function (doc) { return []; },
michael@0 276 function (doc) { return doc.getElementsByTagName("test");}
michael@0 277 );
michael@0 278
michael@0 279 // Skipping http://tc.labs.opera.com/css/namespaces/syntax-005.xml because it
michael@0 280 // involves import, and we have no way // to know when the import load completes.
michael@0 281
michael@0 282 // Skipping http://tc.labs.opera.com/css/namespaces/syntax-006.xml because it
michael@0 283 // involves import, and we have no way // to know when the import load completes.
michael@0 284
michael@0 285 // 2 tests from http://tc.labs.opera.com/css/namespaces/syntax-007.xml
michael@0 286 test_selector_in_html(
michael@0 287 '@charset "x"; @namespace url("test"); @namespace url("test2");',
michael@0 288 '*|test',
michael@0 289 '<test xmlns="test"/>',
michael@0 290 function (doc) { return doc.getElementsByTagName("test");},
michael@0 291 function (doc) { return []; }
michael@0 292 );
michael@0 293
michael@0 294 test_selector_in_html(
michael@0 295 '@charset "x"; @namespace url("test"); @namespace url("test2");',
michael@0 296 'test',
michael@0 297 '<test xmlns="test"/>',
michael@0 298 function (doc) { return []; },
michael@0 299 function (doc) { return doc.getElementsByTagName("test");}
michael@0 300 );
michael@0 301
michael@0 302 // 2 tests from http://tc.labs.opera.com/css/namespaces/syntax-008.xml
michael@0 303 test_selector_in_html(
michael@0 304 '@namespace \\72x url("test");',
michael@0 305 'rx|test',
michael@0 306 '<test xmlns="test"/>',
michael@0 307 function (doc) { return doc.getElementsByTagName("test");},
michael@0 308 function (doc) { return []; }
michael@0 309 );
michael@0 310
michael@0 311 test_selector_in_html(
michael@0 312 '@namespace \\72x url("test");',
michael@0 313 'test',
michael@0 314 '<test xmlns="test"/>',
michael@0 315 function (doc) { return doc.getElementsByTagName("test");},
michael@0 316 function (doc) { return []; }
michael@0 317 );
michael@0 318
michael@0 319 // And now some :not() tests
michael@0 320 test_selector_in_html(
michael@0 321 '@namespace url("test");',
michael@0 322 '*|*:not(test)',
michael@0 323 '<test xmlns="test"/>',
michael@0 324 function (doc) { return []; },
michael@0 325 function (doc) { return doc.getElementsByTagName("test");}
michael@0 326 );
michael@0 327
michael@0 328 test_selector_in_html(
michael@0 329 '@namespace url("test");',
michael@0 330 '*|*:not(test)',
michael@0 331 '<test xmlns="testing"/>',
michael@0 332 function (doc) { return doc.getElementsByTagName("test");},
michael@0 333 function (doc) { return []; }
michael@0 334 );
michael@0 335
michael@0 336 test_selector_in_html(
michael@0 337 '@namespace x url("test");',
michael@0 338 '*|*:not(x|test)',
michael@0 339 '<test xmlns="test"/>',
michael@0 340 function (doc) { return []; },
michael@0 341 function (doc) { return doc.getElementsByTagName("test");}
michael@0 342 );
michael@0 343
michael@0 344 test_selector_in_html(
michael@0 345 '@namespace x url("test");',
michael@0 346 '*|*:not(x|test)',
michael@0 347 '<test xmlns="testing"/>',
michael@0 348 function (doc) { return doc.getElementsByTagName("test");},
michael@0 349 function (doc) { return []; }
michael@0 350 );
michael@0 351
michael@0 352 test_selector_in_html(
michael@0 353 '@namespace url("test");',
michael@0 354 '*|*:not(*)',
michael@0 355 '<test xmlns="testing"/>',
michael@0 356 function (doc) { return doc.getElementsByTagName("test");},
michael@0 357 function (doc) { return []; }
michael@0 358 );
michael@0 359
michael@0 360 test_selector_in_html(
michael@0 361 '@namespace url("test");',
michael@0 362 '*|*:not(*)',
michael@0 363 '<test xmlns="test"/>',
michael@0 364 function (doc) { return []; },
michael@0 365 function (doc) { return doc.getElementsByTagName("test");}
michael@0 366 );
michael@0 367
michael@0 368 test_selector_in_html(
michael@0 369 '@namespace x url("test");',
michael@0 370 '*|*:not(x|*)',
michael@0 371 '<test xmlns="testing"/>',
michael@0 372 function (doc) { return doc.getElementsByTagName("test");},
michael@0 373 function (doc) { return []; }
michael@0 374 );
michael@0 375
michael@0 376 test_selector_in_html(
michael@0 377 '@namespace x url("test");',
michael@0 378 '*|*:not(x|*)',
michael@0 379 '<test xmlns="test"/>',
michael@0 380 function (doc) { return []; },
michael@0 381 function (doc) { return doc.getElementsByTagName("test");}
michael@0 382 );
michael@0 383
michael@0 384 test_selector_in_html(
michael@0 385 '@namespace url("test");',
michael@0 386 '*|*:not([foo])',
michael@0 387 '<test xmlns="testing" foo="bar"/>',
michael@0 388 function (doc) { return []; },
michael@0 389 function (doc) { return doc.getElementsByTagName("test");}
michael@0 390 );
michael@0 391
michael@0 392 test_selector_in_html(
michael@0 393 '@namespace url("test");',
michael@0 394 '*|*:not([foo])',
michael@0 395 '<test xmlns="test" foo="bar"/>',
michael@0 396 function (doc) { return []; },
michael@0 397 function (doc) { return doc.getElementsByTagName("test");}
michael@0 398 );
michael@0 399
michael@0 400 test_selector_in_html(
michael@0 401 '@namespace url("test");',
michael@0 402 '*|*[foo]',
michael@0 403 '<test foo="bar"/>',
michael@0 404 function (doc) { return doc.getElementsByTagName("test");},
michael@0 405 function (doc) { return []; }
michael@0 406 );
michael@0 407
michael@0 408 test_selector_in_html(
michael@0 409 '@namespace url("test");',
michael@0 410 '*|*[|foo]',
michael@0 411 '<test foo="bar"/>',
michael@0 412 function (doc) { return doc.getElementsByTagName("test");},
michael@0 413 function (doc) { return []; }
michael@0 414 );
michael@0 415
michael@0 416 test_selector_in_html(
michael@0 417 '@namespace test url("test");',
michael@0 418 '*|*[test|foo]',
michael@0 419 '<test foo="bar"/>',
michael@0 420 function (doc) { return []; },
michael@0 421 function (doc) { return doc.getElementsByTagName("test");}
michael@0 422 );
michael@0 423
michael@0 424 test_selector_in_html(
michael@0 425 '@namespace test url("test");',
michael@0 426 '*|*[test|foo]',
michael@0 427 '<test xmlns:t="test" t:foo="bar"/>',
michael@0 428 function (doc) { return doc.getElementsByTagName("test");},
michael@0 429 function (doc) { return []; }
michael@0 430 );
michael@0 431
michael@0 432 test_selector_in_html(
michael@0 433 '@namespace url("test");',
michael@0 434 '*|*[foo]',
michael@0 435 '<test xmlns:t="test" t:foo="bar"/>',
michael@0 436 function (doc) { return []; },
michael@0 437 function (doc) { return doc.getElementsByTagName("test");}
michael@0 438 );
michael@0 439
michael@0 440 test_selector_in_html(
michael@0 441 '@namespace url("test");',
michael@0 442 '*|*[*|foo]',
michael@0 443 '<test xmlns:t="test" t:foo="bar"/>',
michael@0 444 function (doc) { return doc.getElementsByTagName("test");},
michael@0 445 function (doc) { return []; }
michael@0 446 );
michael@0 447
michael@0 448 test_selector_in_html(
michael@0 449 '',
michael@0 450 '*|*[*|foo]',
michael@0 451 '<test xmlns:t="test" t:foo="bar"/>',
michael@0 452 function (doc) { return doc.getElementsByTagName("test");},
michael@0 453 function (doc) { return []; }
michael@0 454 );
michael@0 455
michael@0 456 SimpleTest.finish();
michael@0 457 }
michael@0 458
michael@0 459 </script>
michael@0 460 </pre>
michael@0 461 </body>
michael@0 462 </html>

mercurial