blob: 878260c64e3d964901ad4579d206bab0aeeafd05 [file] [log] [blame]
<!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 :matches pseudo class, nested and multiple :matches.');
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 :matches.
testSelector("testcase:matches(:matches(bb, gg) > testcase)", [1, 2, 3, 4]);
testSelector("testcase:matches(:matches(dd, cc) + *)", [1, 3]);
testSelector("testcase:matches(:matches(ee > ee > ee > ff > ee > ee > ff > gg) > *)", [2]);
testSelector('testcase:matches(bb > :matches(bb, bb > aa) > aa > bb testcase)', [1, 2, 3, 4]);
testSelector('testcase:matches(:matches(bb > aa > aa > bb > aa) > aa > bb testcase)', [3, 4]);
testSelector('testcase:matches(:matches(aa:matches(bb > aa > aa) > bb > aa) > aa > bb testcase)', [3, 4]);
testSelector('testcase:matches(:matches(aa:matches(bb > aa > aa) > bb > aa) > aa > bb > testcase)', [3]);
testSelector("testcase:matches(:matches(dd + dd) + cc + dd ~ testcase)", [3]);
testSelector("testcase:matches(:matches(dd + dd + cc + *) ~ testcase)", [3]);
testSelector("testcase:matches(:matches(:matches(:matches(:matches(dd) + dd) + *) + dd) ~ testcase)", [3]);
testSelector("testcase:matches(:matches(dd + * + :matches(cc + dd)) ~ testcase)", [1, 3]);
testSelector("testcase:matches(:matches(* + dd + cc + :matches(cc + dd)) ~ testcase)", [1, 3]);
testSelector("testcase:matches(* + :matches(* + cc) + dd ~ testcase)", [1, 3]);
testSelector("testcase:matches(cc + * + * + :matches(cc + cc + cc) + dd ~ testcase)", [1]);
testSelector("testcase:matches(cc + cc + cc + :matches(cc + :matches(unknown, *)) ~ testcase)", [1]);
testSelector("testcase:matches(:matches(:matches(* + * + * + *) + *, :matches(*) + cc + * + * + *) ~ testcase)", [1, 3]);
testSelector("testcase:matches(:matches(:matches(aa > aa > aa > *) testcase, * + * + * + * + * ~ testcase))", [1, 2, 3]);
// :matches with CannotMatchAnything.
testSelector("testcase:matches(:visited)", [])
testSelector("testcase:matches(cc + *, :visited)", [3])
// Multiple :matches.
testSelector("testcase:matches(:matches(bb, gg) > testcase):matches(ff > gg > testcase)", [2, 4]);
testSelector("testcase:matches(:matches(dd, cc) + *):matches(dd + * + *)", [3]);
testSelector("testcase:matches(:matches(ee > ee > ee > ff > ee > ee > ff > gg) > *):matches(testcase *)", [2]);
// :not and :matches.
testSelector("testcase:matches(:matches(:not(dd)) + *)", [3]);
testSelector("testcase:matches(:matches(:not(cc)) + *)", [1]);
testSelector("testcase:matches(:matches(:not(cc), :not(dd)) + *)", [1, 3]);
// Multiple nested :matches.
testSelector('testcase:matches(:matches(aa:matches(bb > aa > aa) > bb > aa) > aa > bb testcase):matches(* + :matches(* + cc) + dd ~ testcase)', [3]);
testSelector('testcase:matches(:matches(aa:matches(bb > aa > aa) > bb > aa) > aa > bb testcase, * + :matches(* + cc) + dd ~ testcase):matches(* + :matches(* + cc) + dd ~ testcase)', [1, 3]);
testSelector('testcase:matches(bb > :matches(bb, bb > aa) > aa > bb testcase):matches(:matches(bb > aa > aa > bb > aa) > aa > bb testcase)', [3, 4]);
// A lot of selectors inside :matches.
testSelector("testcase:matches(aa + *, bb + *, cc + *, dd + *, ee + *, ff + *, gg + *, hh + *, ii + *, jj + *, kk + *, ll + *, mm + *, nn + *)", [1, 3]);
testSelector("testcase:matches(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>