blob: 15fdd5bf3430b79481974389debb781ff705ec58 [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="Web-É-Kit" multiple="WEB-é-KIT" id="target1"></div>
<div data-attribute="web-É-kit" multiple="Web-é-Kit" id="target2"></div>
<div data-attribute="WEB-É-KIT" multiple="Web-é-kit" id="target3"></div>
<div data-attribute="Web-é-Kit" multiple="web-É-kit" id="target4"></div>
<div data-attribute="web-é-kit" multiple="web-É-Kit" id="target5"></div>
</div>
</body>
<script>
description('When matching attributes case insensitively, it should be ASCII case insensitive. This test verifies the behavior when matching substring anywhere in the values (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*=Web-É-Kit]', [1]],
['[data-attribute*=b-É-K]', [1]],
['[data-attribute*=web-É-kit]', [2]],
['[data-attribute*=b-É-k]', [2]],
['[data-attribute*=WEB-É-KIT]', [3]],
['[data-attribute*=B-É-K]', [3]],
['[data-attribute*=Web-é-Kit]', [4]],
['[data-attribute*=b-é-K]', [4]],
['[data-attribute*=web-é-kit]', [5]],
['[data-attribute*=b-é-k]', [5]],
// Same selectors with the case-insensitive flag.
['[data-attribute*=Web-É-Kit i]', [1, 2, 3]],
['[data-attribute*=b-É-k i]', [1, 2, 3]],
['[data-attribute*=web-É-kit i]', [1, 2, 3]],
['[data-attribute*=b-É-k i]', [1, 2, 3]],
['[data-attribute*=WEB-É-KIT i]', [1, 2, 3]],
['[data-attribute*=B-É-K i]', [1, 2, 3]],
['[data-attribute*=Web-é-Kit i]', [4, 5]],
['[data-attribute*=b-é-k i]', [4, 5]],
['[data-attribute*=web-é-kit i]', [4, 5]],
['[data-attribute*=b-é-k i]', [4, 5]],
// "multiple" is one of those weird legacy exception: it is always case insensitive in HTML.
['[multiple*=WEB-é-KIT]', [1, 2, 3]],
['[multiple*=B-é-K]', [1, 2, 3]],
['[multiple*=Web-é-Kit]', [1, 2, 3]],
['[multiple*=b-é-k]', [1, 2, 3]],
['[multiple*=Web-é-kit]', [1, 2, 3]],
['[multiple*=b-é-K]', [1, 2, 3]],
['[multiple*=web-É-kit]', [4, 5]],
['[multiple*=b-É-K]', [4, 5]],
['[multiple*=web-É-Kit]', [4, 5]],
['[multiple*=b-É-k]', [4, 5]],
['[multiple*=WEB-é-KIT i]', [1, 2, 3]],
['[multiple*=B-é-k i]', [1, 2, 3]],
['[multiple*=Web-é-Kit i]', [1, 2, 3]],
['[multiple*=b-é-K i]', [1, 2, 3]],
['[multiple*=Web-é-kit i]', [1, 2, 3]],
['[multiple*=B-é-K i]', [1, 2, 3]],
['[multiple*=web-É-kit i]', [4, 5]],
['[multiple*=b-É-K i]', [4, 5]],
['[multiple*=web-É-Kit i]', [4, 5]],
['[multiple*=b-É-k i]', [4, 5]],
];
for (var testCase of testCases) {
testSelector(testCase[0], testCase[1]);
}
</script>
<script src="../../resources/js-test-post.js"></script>
</html>