blob: 4ad01b7ddaef7df6fe13568acd5135d16dfaf595 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<style>
div {
background-color: white;
}
input[type="checkbox"]:not(:checked) + div + div {
background-color: red;
}
input[type="checkbox"] + div + div {
background-color: lime;
}
</style>
</head>
<body>
<div id="to-hide-after-testing">
<input type="checkbox" checked>
<div id="foo-with-renderer">foo</div>
<div id="bar-with-renderer">bar</div>
</div>
<div style="display:none;">
<input type="checkbox" checked>
<div id="foo-without-renderer">foo</div>
<div id="bar-without-renderer">bar</div>
</div>
</body>
<script>
description('Test direct adjacent style update on changes of the :checked state of input element.');
function testColor(expectMatch) {
shouldBeEqualToString('getComputedStyle(document.getElementById("foo-with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
shouldBeEqualToString('getComputedStyle(document.getElementById("bar-with-renderer")).backgroundColor', expectMatch ? 'rgb(255, 0, 0)' : 'rgb(0, 255, 0)');
shouldBeEqualToString('getComputedStyle(document.getElementById("foo-without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
shouldBeEqualToString('getComputedStyle(document.getElementById("bar-without-renderer")).backgroundColor', expectMatch ? 'rgb(255, 0, 0)' : 'rgb(0, 255, 0)');
}
function setChecked(value) {
var allCheckboxes = document.querySelectorAll("input[type=checkbox]");
for (var i = 0; i < allCheckboxes.length; ++i)
allCheckboxes[i].checked = value;
}
debug("Initial state is checked through the checked attribute.");
testColor(false);
debug("Checking the boxes through API.");
setChecked(true);
testColor(false);
debug("Unchecking through API");
setChecked(false);
testColor(true);
document.getElementById('to-hide-after-testing').style.display = 'none';
</script>
<script src="../../resources/js-test-post.js"></script>
</html>