benjamin@webkit.org | 8d0f62b | 2014-08-21 03:33:18 +0000 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <script src="../../resources/js-test-pre.js"></script> |
| 5 | <style> |
| 6 | input { |
| 7 | background-color: white; |
| 8 | color: black; |
| 9 | } |
| 10 | input:placeholder-shown { |
| 11 | background-color: rgb(1, 2, 3); |
| 12 | } |
| 13 | input: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> |
| 41 | description('Check the basic features of the ":placeholder-shown" pseudo class with the <input> element.'); |
| 42 | |
| 43 | document.getElementById('placeholder-contains-only-newline').setAttribute('placeholder', '\n'); |
| 44 | document.getElementById('placeholder-contains-only-carriageReturn').setAttribute('placeholder', '\r'); |
| 45 | |
| 46 | shouldBe('document.querySelectorAll(":placeholder-shown").length', '3'); |
| 47 | shouldBe('document.querySelectorAll(":placeholder-shown")[0]', 'document.getElementById("valid-placeholder")'); |
| 48 | shouldBe('document.querySelectorAll(":placeholder-shown")[1]', 'document.getElementById("valid-placeholder-with-empty-value")'); |
| 49 | shouldBe('document.querySelectorAll(":placeholder-shown")[2]', 'document.getElementById("valid-placeholder-with-empty-value2")'); |
| 50 | |
| 51 | shouldBeEqualToString('getComputedStyle(document.getElementById("no-placeholder")).backgroundColor', 'rgb(255, 255, 255)'); |
| 52 | shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder")).backgroundColor', 'rgb(255, 255, 255)'); |
| 53 | shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder2")).backgroundColor', 'rgb(255, 255, 255)'); |
| 54 | shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-newline")).backgroundColor', 'rgb(255, 255, 255)'); |
| 55 | shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-carriageReturn")).backgroundColor', 'rgb(255, 255, 255)'); |
| 56 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-value")).backgroundColor', 'rgb(255, 255, 255)'); |
| 57 | |
| 58 | shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder")).backgroundColor', 'rgb(1, 2, 3)'); |
| 59 | shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value")).backgroundColor', 'rgb(1, 2, 3)'); |
| 60 | shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value2")).backgroundColor', 'rgb(1, 2, 3)'); |
| 61 | |
| 62 | debug(""); |
| 63 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)").length', '6'); |
| 64 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[0]', 'document.getElementById("no-placeholder")'); |
| 65 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[1]', 'document.getElementById("empty-placeholder")'); |
| 66 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[2]', 'document.getElementById("empty-placeholder2")'); |
| 67 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[3]', 'document.getElementById("placeholder-contains-only-newline")'); |
| 68 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[4]', 'document.getElementById("placeholder-contains-only-carriageReturn")'); |
| 69 | shouldBe('document.querySelectorAll("input:not(:placeholder-shown)")[5]', 'document.getElementById("with-value")'); |
| 70 | |
| 71 | shouldBeEqualToString('getComputedStyle(document.getElementById("no-placeholder")).color', 'rgb(4, 5, 6)'); |
| 72 | shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder")).color', 'rgb(4, 5, 6)'); |
| 73 | shouldBeEqualToString('getComputedStyle(document.getElementById("empty-placeholder2")).color', 'rgb(4, 5, 6)'); |
| 74 | shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-newline")).color', 'rgb(4, 5, 6)'); |
| 75 | shouldBeEqualToString('getComputedStyle(document.getElementById("placeholder-contains-only-carriageReturn")).color', 'rgb(4, 5, 6)'); |
| 76 | shouldBeEqualToString('getComputedStyle(document.getElementById("with-value")).color', 'rgb(4, 5, 6)'); |
| 77 | |
| 78 | shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder")).color', 'rgb(0, 0, 0)'); |
| 79 | shouldBeEqualToString('getComputedStyle(document.getElementById("valid-placeholder-with-empty-value")).color', 'rgb(0, 0, 0)'); |
| 80 | shouldBeEqualToString('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> |