blob: 848e3b72857a7ff702ed744c6cd4f8c72306a7c9 [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 ":not(selectorList)" pseudo class with selector lists.');
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("");
}
// Simple selectors.
testSelector(":not(testcaseA, testcaseB)", []);
testSelector(":not(#testcase1, #testcase2, #testcase3, #testcase4, #testcase5, #testcase6, #testcase7, #testcase8, #testcase9, #testcase10)", []);
testSelector(":not(#testcase1, #testcase2, #testcase4, #testcase5, #testcase6, #testcase8, #testcase9, #testcase10)", ["testcase3", "testcase7"]);
testSelector(":not(testcaseA, #testcase1, #testcase2, #testcase4, #testcase5, #testcase8, #testcase9, #testcase10)", ["testcase6"]);
testSelector(":not([attribute3], [attribute2=value2])", ["testcase3", "testcase4", "testcase7", "testcase8"]);
testSelector(":not([attribute3], [attribute2=value2], testcaseB)", ["testcase3", "testcase7"]);
testSelector(":not(.bar, .bazoo)", []);
testSelector(":not(.foo, .bar)", []);
testSelector(":not(.baz, .foo)", []);
// Compound selectors.
testSelector(":not(.bar.bazoo, .bar.baz)", ["testcase3", "testcase5", "testcase8"]);
testSelector(":not(testcaseeA.bar.bazoo, .bar.baz)", ["testcase3", "testcase4", "testcase5", "testcase8", "testcase9", "testcase10"]);
testSelector(":not(testcaseB.bar, .baz.foo.bar)", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase8", "testcase9"]);
testSelector(":not(.baz.foo.bar, testcaseA[attribute1^=value])", ["testcase2", "testcase4", "testcase5", "testcase8", "testcase9", "testcase10"]);
testSelector(":not(testcaseA[attribute1^=value], .foo:empty)", ["testcase2", "testcase4", "testcase5", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(.foo:empty, .bar.baz)", ["testcase3", "testcase4", "testcase5", "testcase8", "testcase10"]);
testSelector(":not(.bar.bazoo, .bar.baz, testcaseeA.bar.bazoo, .baz.foo.bar, testcaseA[attribute1^=value])", ["testcase5", "testcase8"]);
testSelector(":not(testcaseeA.bar.bazoo, .bar.baz, .foo:empty)", ["testcase3", "testcase4", "testcase5", "testcase8", "testcase10"]);
testSelector(":not(testcaseB.bar, .baz.foo.bar, testcaseA[attribute1^=value])", ["testcase5", "testcase8", "testcase9"]);
// Complex selectors.
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar)", ["testcase1", "testcase3", "testcase5", "testcase7", "testcase8", "testcase9"]);
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value])", ["testcase5", "testcase8", "testcase9"]);
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty)", ["testcase5", "testcase8"]);
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *)", ["testcase8"]);
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *)", ["testcase8"]);
testSelector(":not(html>body testcaseB.bar, html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *, testcaseA ~ *)", []);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value])", ["testcase2", "testcase4", "testcase5", "testcase8", "testcase9", "testcase10"]);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty)", ["testcase2", "testcase4", "testcase5", "testcase8", "testcase10"]);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *)", ["testcase2", "testcase4", "testcase8", "testcase10"]);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *)", ["testcase2", "testcase4", "testcase8", "testcase10"]);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *, testcaseA + testcaseB ~ testcaseB)", ["testcase2"]);
testSelector(":not(html body div .baz.foo.bar, :root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *, testcaseA + testcaseB ~ testcaseB, testcaseA ~ *)", []);
testSelector(":not(:root div>testcaseA[attribute1^=value], body>div .foo:empty)", ["testcase2", "testcase4", "testcase5", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *)", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *)", ["testcase2", "testcase4", "testcase6", "testcase8", "testcase10"]);
testSelector(":not(:root div>testcaseA[attribute1^=value], body>div .foo:empty, testcaseB + *, :root body>div testcaseB + *, testcaseA + testcaseB ~ testcaseB)", ["testcase2",]);
</script>
<script src="../../resources/js-test-post.js"></script>
</html>