111 lines
4.1 KiB
HTML
111 lines
4.1 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
<style>
|
|
target {
|
|
background-color: white;
|
|
}
|
|
target:nth-last-child(n+5) {
|
|
background-color: rgb(1, 2, 3);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="with-renderer">
|
|
<target class="element_1"></target>
|
|
<target class="element_2"></target>
|
|
<target class="element_3"></target>
|
|
<target class="element_4"></target>
|
|
<target class="element_5"></target>
|
|
</div>
|
|
<div id="without-renderer" style="display:none;">
|
|
<target class="element_1"></target>
|
|
<target class="element_2"></target>
|
|
<target class="element_3"></target>
|
|
<target class="element_4"></target>
|
|
<target class="element_5"></target>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
description('Test style update of :nth-last-child() when the tree structure is modified.');
|
|
|
|
function testColor(classesThatShouldMatch) {
|
|
var allTargets = document.querySelectorAll("target");
|
|
for (var i = 0; i < allTargets.length; ++i) {
|
|
var expectMath = classesThatShouldMatch.indexOf(allTargets[i].className) != -1;
|
|
shouldBeEqualToString('getComputedStyle(document.querySelectorAll("target")[' + i + ']).backgroundColor', expectMath ? 'rgb(1, 2, 3)' : 'rgb(255, 255, 255)');
|
|
}
|
|
}
|
|
|
|
function addElementAsFirstChild(tagName, className)
|
|
{
|
|
var newElement = document.createElement(tagName);
|
|
newElement.className = className;
|
|
|
|
var withRenderer = document.getElementById("with-renderer");
|
|
withRenderer.insertBefore(newElement, withRenderer.firstChild);
|
|
|
|
var withoutRenderer = document.getElementById("without-renderer");
|
|
withoutRenderer.insertBefore(newElement.cloneNode(), withoutRenderer.firstChild);
|
|
}
|
|
|
|
function removeElementsOfClass(className)
|
|
{
|
|
var allElementsToRemove = document.querySelectorAll('.' + className);
|
|
for (var i = 0; i < allElementsToRemove.length; ++i)
|
|
allElementsToRemove[i].parentElement.removeChild(allElementsToRemove[i]);
|
|
}
|
|
|
|
debug("Initialy, only the first can match.");
|
|
testColor(["element_1"]);
|
|
|
|
debug("Adding an element <target> on top, we should now match 0 and 1.");
|
|
addElementAsFirstChild("target", "element_0")
|
|
testColor(["element_0", "element_1"]);
|
|
|
|
// Using nottarget is interesting because the ':nth-last-child()' part is not matched for those elements.
|
|
debug("Adding an element <nottarget> on top, we should now match -1, 0, 1.");
|
|
addElementAsFirstChild("nottarget", "element_-1")
|
|
testColor(["element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Adding an element <nottarget> on top, we should now match -2, -1, 0, 1.");
|
|
addElementAsFirstChild("nottarget", "element_-2")
|
|
testColor(["element_-2", "element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Adding an element <target> on top, we should now match -3, -2, -1, 0, 1.");
|
|
addElementAsFirstChild("target", "element_-3")
|
|
testColor(["element_-3", "element_-2", "element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Adding an element <nottarget> on top, we should now match -4, -3, -2, -1, 0, 1.");
|
|
addElementAsFirstChild("nottarget", "element_-4")
|
|
testColor(["element_-4", "element_-3", "element_-2", "element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Removing one of the <nottarget>, -2 should no longer match.");
|
|
removeElementsOfClass("element_-2");
|
|
testColor(["element_-4", "element_-3", "element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Removing one of the <target>, -4 should no longer match.");
|
|
removeElementsOfClass("element_-4");
|
|
testColor(["element_-3", "element_-1", "element_0", "element_1"]);
|
|
|
|
debug("Removing one of the <notarget>, -1 should no longer match.");
|
|
removeElementsOfClass("element_-1");
|
|
testColor(["element_-3", "element_0", "element_1"]);
|
|
|
|
debug("Removing one of the <target>, -3 should no longer match.");
|
|
removeElementsOfClass("element_-3");
|
|
testColor(["element_0", "element_1"]);
|
|
|
|
debug("Removing one of the <target>, 0 should no longer match.");
|
|
removeElementsOfClass("element_0");
|
|
testColor(["element_1"]);
|
|
|
|
debug("Removing one of the <target>, there are only 4 siblings left, nothing can match.");
|
|
removeElementsOfClass("element_1");
|
|
testColor([]);
|
|
|
|
</script>
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
</html>
|