blob: 2c5b79ca692485f4551f69f9bf230b1091c12ffc [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">
<testcaseA id="testcase1" attribute1="value1" class="bar baz bazoo" attribute3="value3">Not empty</testcaseA>
<testcaseB id="testcase2" class="bar baz bazoo" attribute2="value2" attribute3="value3"></testcaseB>
<testcaseA id="testcase3" attribute1="value1" class="foo baz bazoo">Not empty</testcaseA>
<testcaseB id="testcase4" attribute1="value1" class="foo bar bazoo">Not empty</testcaseB>
<testcaseA id="testcase5" class="foo baz bazoo" attribute2="value2" attribute3="value3">Not empty</testcaseA>
<testcaseB id="testcase6" attribute1="value1" class="foo bar baz" attribute3="value3">Not empty</testcaseB>
<testcaseA id="testcase7" attribute1="value1" class="bar baz bazoo">Not empty</testcaseA>
<testcaseB id="testcase8" attribute1="value1" class="foo baz bazoo">Not empty</testcaseB>
<testcaseA id="testcase9" class="foo bar bazoo" attribute2="value2" attribute3="value3"></testcaseA>
<testcaseB id="testcase10" attribute1="value1" class="foo bar bazoo" attribute3="value3">Not empty</testcaseB>
</div>
</body>
<script>
description('Check the validity of :not() inside :not() matching.');
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("");
}
// Stress test the nesting.
testSelector(":not(testcaseA)", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(testcaseA))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(testcaseA)))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(testcaseA))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(testcaseA)))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(testcaseA))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(testcaseA)))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(testcaseA))))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA)))))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA))))))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA)))))))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA))))))))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA)))))))))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA))))))))))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA)))))))))))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA))))))))))))))))", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase9"]);
testSelector(":not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(:not(testcaseA)))))))))))))))))", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
// The matches inside the outside :not() is a tautology.
testSelector(":not(testcaseA, :not(testcaseA))", []);
// Interesting cases, :not() on a compound selector cannot be moved outside:
// A && !(B) != !(B && !A)
testSelector(".baz:not(testcaseA)", ["testcase2", "testcase6", "testcase8"]);
testSelector(":not(testcaseA:not(.baz))", ["testcase1", "testcase2", "testcase3", "testcase4", "testcase5", "testcase6", "testcase7", "testcase8", "testcase10"]);
</script>
<script src="../../resources/js-test-post.js"></script>
</html>