blob: b260045a35c86237e431f0bb5517727ce2a3a062 [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<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">
<div data-attribute="WebKit-É" multiple="WEBKIT-é" id="target1"></div>
<div data-attribute="webkit-É" multiple="WebKit-é" id="target2"></div>
<div data-attribute="WEBKIT-É" multiple="Webkit-é" id="target3"></div>
<div data-attribute="WebKit-é" multiple="webkit-É" id="target4"></div>
<div data-attribute="webkit-é" multiple="webKit-É" id="target5"></div>
</div>
</body>
<script>
description('When matching attributes case insensitively, it should be ASCII case insensitive. This test verifies the behavior for exact value matching (e.g. [a="b"])');
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", 'target' + 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(parseInt(allTestCases[i].id.replace('target', ''))) >= 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("");
}
var testCases = [
// Regular attribute matching is case sensitive.
['[data-attribute=WebKit-É]', [1]],
['[data-attribute=webkit-É]', [2]],
['[data-attribute=WEBKIT-É]', [3]],
['[data-attribute=WebKit-é]', [4]],
['[data-attribute=webkit-é]', [5]],
// Same selectors with the case-insensitivie flag.
['[data-attribute=WebKit-É i]', [1, 2, 3]],
['[data-attribute=webkit-É i]', [1, 2, 3]],
['[data-attribute=WEBKIT-É i]', [1, 2, 3]],
['[data-attribute=WebKit-é i]', [4, 5]],
['[data-attribute=webkit-é i]', [4, 5]],
// "multiple" is one of those weird legacy exception: it is always case insensitive in HTML.
['[multiple=WEBKIT-é]', [1, 2, 3]],
['[multiple=WebKit-é]', [1, 2, 3]],
['[multiple=Webkit-é]', [1, 2, 3]],
['[multiple=webkit-É]', [4, 5]],
['[multiple=webKit-É]', [4, 5]],
['[multiple=WEBKIT-é i]', [1, 2, 3]],
['[multiple=WebKit-é i]', [1, 2, 3]],
['[multiple=Webkit-é i]', [1, 2, 3]],
['[multiple=webkit-É i]', [4, 5]],
['[multiple=webKit-É i]', [4, 5]],
];
for (var testCase of testCases) {
testSelector(testCase[0], testCase[1]);
}
</script>
<script src="../../resources/js-test-post.js"></script>
</html>