blob: 74582a031eee05b55980ffd58cee030a46f4f96f [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">
<testcase id="testcase1" class="bar" attribute3="value3">Not empty</testcaseA>
<testcase id="testcase2" class="bazoo" attribute3="value3">Not empty</testcaseA>
<testcase id="testcase3" class="baz" attribute3="value3">Not empty</testcaseA>
</div>
</body>
<script>
description('Test :matches() with a selector list ending with selector that can never match.');
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", 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(allTestCases[i].id) >= 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("");
}
testSelector("testcase:matches(.bar, :not(*))", ["testcase1"]);
testSelector("testcase:matches(.bazoo, *:not(*))", ["testcase2"]);
testSelector("testcase:matches(.baz, #foo#bar)", ["testcase3"]);
testSelector("testcase:matches(.bar, #foo#bar, :not(*), *:not(*), foo:not(*))", ["testcase1"]);
testSelector("testcase:matches(.bazoo, #foo#bar, :not(*), *:not(*), foo:not(*), #foo#bar, :not(*), *:not(*), foo:not(*))", ["testcase2"]);
</script>
<script src="../../resources/js-test-post.js"></script>
</html>