blob: fc1c1c633b951906d139dee96cb430c1e539e9f9 [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 style="display:none">
16 <!-- Success: No content -->
17 <testcase id="no-content"></testcase>
18
19 <!-- Success: Comments are not elment -->
20 <testcase id="comment"><!-- empty --></testcase>
21
22 <!-- Success: Empty text node are okay. -->
23 <testcase id="empty-textnodes"></testcase>
24
25 <!-- Success: The two above. -->
26 <testcase id="comments-and-empty-textnodes"></testcase>
27
28 <!-- Failure: Non empty text node, there is a space character. -->
29 <testcase id="space-character"> </testcase>
30
31 <!-- Failure: the <span> element inside makes the node non-empty. -->
32 <testcase id="element"><span></span></testcase>
33 </div>
34</body>
35<script>
36description('Check the basic features of the ":empty" pseudo class.');
37
38var emptyTextnodes = document.getElementById("empty-textnodes");
39for (var i = 0; i < 10; ++i)
40 emptyTextnodes.appendChild(document.createTextNode(""));
41
42var commentsAndEmptyTextnodes = document.getElementById("comments-and-empty-textnodes");
43for (var i = 0; i < 10; ++i) {
44 commentsAndEmptyTextnodes.appendChild(document.createTextNode(""));
45 commentsAndEmptyTextnodes.appendChild(document.createComment("WebKit!"));
46}
47
48shouldBe('document.querySelectorAll("testcase:empty").length', '4');
49shouldBe('document.querySelectorAll("testcase:empty")[0]', 'document.getElementById("no-content")');
50shouldBe('document.querySelectorAll("testcase:empty")[1]', 'document.getElementById("comment")');
51shouldBe('document.querySelectorAll("testcase:empty")[2]', 'document.getElementById("empty-textnodes")');
52shouldBe('document.querySelectorAll("testcase:empty")[3]', 'document.getElementById("comments-and-empty-textnodes")');
53
54shouldBeEqualToString('getComputedStyle(document.getElementById("no-content")).backgroundColor', 'rgb(1, 2, 3)');
55shouldBeEqualToString('getComputedStyle(document.getElementById("comment")).backgroundColor', 'rgb(1, 2, 3)');
56shouldBeEqualToString('getComputedStyle(document.getElementById("empty-textnodes")).backgroundColor', 'rgb(1, 2, 3)');
57shouldBeEqualToString('getComputedStyle(document.getElementById("comments-and-empty-textnodes")).backgroundColor', 'rgb(1, 2, 3)');
58shouldBeEqualToString('getComputedStyle(document.getElementById("space-character")).backgroundColor', 'rgb(255, 255, 255)');
59shouldBeEqualToString('getComputedStyle(document.getElementById("element")).backgroundColor', 'rgb(255, 255, 255)');
60
61</script>
62<script src="../../resources/js-test-post.js"></script>
63</html>