blob: 57a995ce55f1d1c9a760b362e0866a2814e94e23 [file] [log] [blame]
benjamin@webkit.org8d0f62b2014-08-21 03:33:18 +00001<!doctype html>
2<html>
3<head>
4<script src="../../resources/js-test-pre.js"></script>
5<style>
6input {
7 background-color: white;
8 color: black;
9}
10input:placeholder-shown {
11 background-color: rgb(1, 2, 3);
12}
13input:not(:placeholder-shown) {
14 color: rgb(4, 5, 6);
15}
16</style>
17</head>
18<body>
19 <div style="display:none">
20 <!-- Does not match: no placeholder defined. -->
21 <input type="text" id="no-placeholder">
22
23 <!-- Does not match: empty placeholder. -->
24 <input type="text" id="empty-placeholder" placeholder>
25 <input type="text" id="empty-placeholder2" placeholder="">
26
27 <!-- Does not match: placeholder contains only newline or carriage return characters. -->
28 <input type="text" id="placeholder-contains-only-newline">
29 <input type="text" id="placeholder-contains-only-carriageReturn">
30
31 <!-- Does not match: the placeholder is not shown when a value is set -->
32 <input type="text" id="with-value" placeholder="WebKit" value="FooBar">
33
34 <!-- Valid cases -->
35 <input type="text" id="valid-placeholder" placeholder="WebKit">
36 <input type="text" id="valid-placeholder-with-empty-value" placeholder="WebKit" value>
37 <input type="text" id="valid-placeholder-with-empty-value2" placeholder="WebKit" value="">
38 </div>
39</body>
40<script>
41description('Check the basic features of the ":placeholder-shown" pseudo class with the &lt;input&gt; element.');
42
43document.getElementById('placeholder-contains-only-newline').setAttribute('placeholder', '\n');
44document.getElementById('placeholder-contains-only-carriageReturn').setAttribute('placeholder', '\r');
45
46shouldBe('document.querySelectorAll(":placeholder-shown").length', '3');
47shouldBe('document.querySelectorAll(":placeholder-shown")[0]', 'document.getElementById("valid-placeholder")');
48shouldBe('document.querySelectorAll(":placeholder-shown")[1]', 'document.getElementById("valid-placeholder-with-empty-value")');
49shouldBe('document.querySelectorAll(":placeholder-shown")[2]', 'document.getElementById("valid-placeholder-with-empty-value2")');
50
51shouldBeEqualToString('getComputedStyle(document.getElementById("no-placeholder")).backgroundColor', 'rgb(255, 255, 255)');
52shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder")).backgroundColor', 'rgb(255, 255, 255)');
53shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder2")).backgroundColor', 'rgb(255, 255, 255)');
54shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-newline")).backgroundColor', 'rgb(255, 255, 255)');
55shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-carriageReturn")).backgroundColor', 'rgb(255, 255, 255)');
56shouldBeEqualToString('getComputedStyle(document.getElementById("with-value")).backgroundColor', 'rgb(255, 255, 255)');
57
58shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder")).backgroundColor', 'rgb(1, 2, 3)');
59shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value")).backgroundColor', 'rgb(1, 2, 3)');
60shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value2")).backgroundColor', 'rgb(1, 2, 3)');
61
62debug("");
63shouldBe('document.querySelectorAll("input:not(:placeholder-shown)").length', '6');
64shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[0]', 'document.getElementById("no-placeholder")');
65shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[1]', 'document.getElementById("empty-placeholder")');
66shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[2]', 'document.getElementById("empty-placeholder2")');
67shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[3]', 'document.getElementById("placeholder-contains-only-newline")');
68shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[4]', 'document.getElementById("placeholder-contains-only-carriageReturn")');
69shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[5]', 'document.getElementById("with-value")');
70
71shouldBeEqualToString('getComputedStyle(document.getElementById("no-placeholder")).color', 'rgb(4, 5, 6)');
72shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder")).color', 'rgb(4, 5, 6)');
73shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder2")).color', 'rgb(4, 5, 6)');
74shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-newline")).color', 'rgb(4, 5, 6)');
75shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-carriageReturn")).color', 'rgb(4, 5, 6)');
76shouldBeEqualToString('getComputedStyle(document.getElementById("with-value")).color', 'rgb(4, 5, 6)');
77
78shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder")).color', 'rgb(0, 0, 0)');
79shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value")).color', 'rgb(0, 0, 0)');
80shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value2")).color', 'rgb(0, 0, 0)');
81</script>
82<script src="../../resources/js-test-post.js"></script>
83</html>