| <!doctype html> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| <style> |
| #test-root * { |
| background-color: red; |
| } |
| </style> |
| <style id="style"> |
| </style> |
| </head> |
| <body> |
| <div style="display:none" id="test-root"> |
| <aa> |
| <aa> |
| <aa> |
| <bb> |
| <aa> |
| <aa> |
| <bb> |
| <cc></cc> |
| <cc></cc> |
| <cc></cc> |
| <cc></cc> |
| <dd></dd> |
| <cc></cc> |
| <cc></cc> |
| <cc></cc> |
| <dd></dd> |
| <cc></cc> |
| <cc></cc> |
| <dd></dd> |
| <cc></cc> |
| <dd></dd> |
| <testcase id="testcase1"> |
| <ee> |
| <ee> |
| <ee> |
| <ff> |
| <ee> |
| <ee> |
| <ff> |
| <gg> |
| <testcase id="testcase2"></testcase> |
| </gg> |
| </ff> |
| </ee> |
| </ee> |
| </ff> |
| </ee> |
| </ee> |
| </ee> |
| </testcase> |
| </bb> |
| </aa> |
| </aa> |
| </bb> |
| </aa> |
| </aa> |
| </aa> |
| <bb> |
| <aa> |
| <aa> |
| <bb> |
| <aa> |
| <aa> |
| <bb> |
| <dd></dd> |
| <dd></dd> |
| <dd></dd> |
| <cc></cc> |
| <dd></dd> |
| <dd></dd> |
| <dd></dd> |
| <cc></cc> |
| <dd></dd> |
| <dd></dd> |
| <cc></cc> |
| <dd></dd> |
| <cc></cc> |
| <testcase id="testcase3"> |
| <ee> |
| <ee> |
| <ff> |
| <ee> |
| <ee> |
| <ff> |
| <gg> |
| <testcase id="testcase4"></testcase> |
| </gg> |
| </ff> |
| </ee> |
| </ee> |
| </ff> |
| </ee> |
| </ee> |
| </testcase> |
| </bb> |
| </aa> |
| </aa> |
| </bb> |
| </aa> |
| </aa> |
| </bb> |
| </div> |
| </body> |
| <script> |
| description('Check the complex selectors with :is pseudo class, nested and multiple :is.'); |
| |
| function testQuerySelector(selector, expectedIds) { |
| shouldBe("document.querySelectorAll('" + selector + "').length", '' + expectedIds.length); |
| for (var i = 0; i < expectedIds.length; ++i) |
| shouldBeEqualToString("document.querySelectorAll('" + selector + "')[" + i + "].id", 'testcase' + expectedIds[i]); |
| } |
| |
| function testStyling(selector, expectedIds) { |
| var stylingElement = document.getElementById("style"); |
| stylingElement.innerHTML = '' + selector + ' { background-color: rgb(10, 100, 200); }'; |
| |
| var allTestCases = document.querySelectorAll("#test-root *"); |
| for (var i = 0; i < allTestCases.length; ++i) { |
| var expectMatch = expectedIds.indexOf(Number(allTestCases[i].id.substring(8))) >= 0; |
| shouldBeEqualToString('getComputedStyle(document.querySelectorAll("#test-root *")[' + i + ']).backgroundColor', expectMatch ? 'rgb(10, 100, 200)' : 'rgb(255, 0, 0)'); |
| } |
| |
| stylingElement.innerHTML = ''; |
| } |
| |
| function testSelector(selector, expectedIds) { |
| debug("Testing \"" + selector + "\""); |
| testQuerySelector("#test-root " + selector, expectedIds); |
| testStyling("#test-root " + selector, expectedIds); |
| debug(""); |
| } |
| |
| // Nested :is. |
| testSelector("testcase:is(:is(bb, gg) > testcase)", [1, 2, 3, 4]); |
| testSelector("testcase:is(:is(dd, cc) + *)", [1, 3]); |
| testSelector("testcase:is(:is(ee > ee > ee > ff > ee > ee > ff > gg) > *)", [2]); |
| testSelector('testcase:is(bb > :is(bb, bb > aa) > aa > bb testcase)', [1, 2, 3, 4]); |
| testSelector('testcase:is(:is(bb > aa > aa > bb > aa) > aa > bb testcase)', [3, 4]); |
| testSelector('testcase:is(:is(aa:is(bb > aa > aa) > bb > aa) > aa > bb testcase)', [3, 4]); |
| testSelector('testcase:is(:is(aa:is(bb > aa > aa) > bb > aa) > aa > bb > testcase)', [3]); |
| testSelector("testcase:is(:is(dd + dd) + cc + dd ~ testcase)", [3]); |
| testSelector("testcase:is(:is(dd + dd + cc + *) ~ testcase)", [3]); |
| testSelector("testcase:is(:is(:is(:is(:is(dd) + dd) + *) + dd) ~ testcase)", [3]); |
| testSelector("testcase:is(:is(dd + * + :is(cc + dd)) ~ testcase)", [1, 3]); |
| testSelector("testcase:is(:is(* + dd + cc + :is(cc + dd)) ~ testcase)", [1, 3]); |
| testSelector("testcase:is(* + :is(* + cc) + dd ~ testcase)", [1, 3]); |
| |
| testSelector("testcase:is(cc + * + * + :is(cc + cc + cc) + dd ~ testcase)", [1]); |
| testSelector("testcase:is(cc + cc + cc + :is(cc + :is(unknown, *)) ~ testcase)", [1]); |
| testSelector("testcase:is(:is(:is(* + * + * + *) + *, :is(*) + cc + * + * + *) ~ testcase)", [1, 3]); |
| testSelector("testcase:is(:is(:is(aa > aa > aa > *) testcase, * + * + * + * + * ~ testcase))", [1, 2, 3]); |
| |
| // :is with CannotMatchAnything. |
| testSelector("testcase:is(:visited)", []) |
| testSelector("testcase:is(cc + *, :visited)", [3]) |
| |
| // Multiple :is. |
| testSelector("testcase:is(:is(bb, gg) > testcase):is(ff > gg > testcase)", [2, 4]); |
| testSelector("testcase:is(:is(dd, cc) + *):is(dd + * + *)", [3]); |
| testSelector("testcase:is(:is(ee > ee > ee > ff > ee > ee > ff > gg) > *):is(testcase *)", [2]); |
| |
| // :not and :is. |
| testSelector("testcase:is(:is(:not(dd)) + *)", [3]); |
| testSelector("testcase:is(:is(:not(cc)) + *)", [1]); |
| testSelector("testcase:is(:is(:not(cc), :not(dd)) + *)", [1, 3]); |
| |
| // Multiple nested :is. |
| testSelector('testcase:is(:is(aa:is(bb > aa > aa) > bb > aa) > aa > bb testcase):is(* + :is(* + cc) + dd ~ testcase)', [3]); |
| testSelector('testcase:is(:is(aa:is(bb > aa > aa) > bb > aa) > aa > bb testcase, * + :is(* + cc) + dd ~ testcase):is(* + :is(* + cc) + dd ~ testcase)', [1, 3]); |
| testSelector('testcase:is(bb > :is(bb, bb > aa) > aa > bb testcase):is(:is(bb > aa > aa > bb > aa) > aa > bb testcase)', [3, 4]); |
| |
| // A lot of selectors inside :is. |
| testSelector("testcase:is(aa + *, bb + *, cc + *, dd + *, ee + *, ff + *, gg + *, hh + *, ii + *, jj + *, kk + *, ll + *, mm + *, nn + *)", [1, 3]); |
| testSelector("testcase:is(aa > aa > aa > aa *, aa > aa > aa > dd *, aa > aa > aa > hh *, cc aa > aa > aa > hh *, cc ff > aa > aa > hh *, bb > aa > aa > bb *, aa > aa > aa > bb *, aa > cc > aa > aa *)", [1, 2, 3, 4]); |
| |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </html> |