blob: 5fb17a38a03733f37c1bf5465f17d16c0611e77f [file] [log] [blame]
benjamin@webkit.orgff47a362014-08-15 04:06:27 +00001<!doctype html>
2<html>
3<head>
4<script src="../../resources/js-test-pre.js"></script>
5<style>
6testcase {
7 background-color: white;
8}
9testcase:empty {
10 background-color: rgb(1, 2, 3);
11}
12</style>
13</head>
14<body>
15 <div>
16 <testcase id="with-renderer"></testcase>
17 </div>
18 <div style="display:none;">
19 <testcase id="without-renderer"></testcase>
20 </div>
21</body>
22<script>
23description('Test the style update with the :empty pseudo class.');
24
25var testCaseWithRender = document.getElementById("with-renderer");
26var testCaseWithoutRenderer = document.getElementById("without-renderer");
27
benjamin@webkit.org53da9532014-08-18 20:52:04 +000028debug("Initial state is empty.");
benjamin@webkit.orgff47a362014-08-15 04:06:27 +000029shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
30shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
31
32debug("Adding a comment does not change the :empty state.");
33testCaseWithRender.appendChild(document.createComment("WebKit!"));
34testCaseWithoutRenderer.appendChild(document.createComment("WebKit!"));
35shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
36shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
37
38debug("Add an element as child make updates :empty.");
39var elementForCaseWithRenderer = document.createElement('div');
40var elementForCaseWithoutRenderer = document.createElement('div');
41testCaseWithRender.appendChild(elementForCaseWithRenderer);
42testCaseWithoutRenderer.appendChild(elementForCaseWithoutRenderer);
43shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
44shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
45
46debug("Adding an empty text node, this is still not empty because of the element.");
47testCaseWithRender.appendChild(document.createTextNode(''));
48testCaseWithoutRenderer.appendChild(document.createTextNode(''));
49shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
50shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
51
52debug("Removing the elements previously added should restore the :empty state.");
53testCaseWithRender.removeChild(elementForCaseWithRenderer);
54testCaseWithoutRenderer.removeChild(elementForCaseWithoutRenderer);
55shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
56shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
57
58debug("Adding a non empty text node makes the state non empty.");
59testCaseWithRender.appendChild(document.createTextNode('WebKit!'));
60testCaseWithoutRenderer.appendChild(document.createTextNode('WebKit!'));
61shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(255, 255, 255)');
62shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(255, 255, 255)');
63
64debug("Removing the last text child, back to being empty.");
65testCaseWithRender.removeChild(testCaseWithRender.lastChild);
66testCaseWithoutRenderer.removeChild(testCaseWithoutRenderer.lastChild);
67shouldBeEqualToString('getComputedStyle(document.getElementById("with-renderer")).backgroundColor', 'rgb(1, 2, 3)');
68shouldBeEqualToString('getComputedStyle(document.getElementById("without-renderer")).backgroundColor', 'rgb(1, 2, 3)');
69</script>
70<script src="../../resources/js-test-post.js"></script>
71</html>