OLD | NEW |
1 <head> | 1 <head> |
2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
3 <script src="resources/common.js"></script> | 3 <script> |
4 <script> | 4 function test() { |
| 5 if (window.testRunner) { |
| 6 testRunner.dumpAsText(); |
| 7 } |
5 | 8 |
6 function backgroundOf(element) { | 9 if (!window.internals) { |
7 return document.defaultView.getComputedStyle(element, null).getPropertyValue
('background-color'); | 10 testFailed('This test requires the test harness to run.'); |
8 } | 11 return; |
| 12 } |
9 | 13 |
10 function foregroundOf(element) { | 14 var field = document.getElementById('field'); |
11 return document.defaultView.getComputedStyle(element, null).getPropertyValue
('color'); | 15 var textarea = document.getElementById('textarea'); |
12 } | 16 var select = document.getElementById('select'); |
13 | 17 |
14 var select2; | 18 var computedStyleField = document.defaultView.getComputedStyle(field); |
15 var autofilledSelectForeground; | 19 var computedStyleTextarea = document.defaultView.getComputedStyle(textar
ea); |
16 var autofilledSelectBackground; | 20 var computedStyleSelect = document.defaultView.getComputedStyle(select); |
17 var originalForeground = 'rgb(255, 255, 255)'; | 21 var originalForeground = computedStyleField.color; |
18 var originalBackground = 'rgb(255, 255, 255)'; | 22 var originalBackground = computedStyleField.backgroundColor; |
19 | 23 |
20 function test() { | 24 if (originalForeground != computedStyleTextarea.color) { |
21 if (!window.internals) { | 25 testFailed('Unexpected initial foreground color for <textarea> field
.'); |
22 testFailed('This test requires the test harness to run.'); | 26 return; |
23 return; | 27 } |
| 28 if (originalForeground != computedStyleTextarea.backgroundColor) { |
| 29 testFailed('Unexpected initial background color for <textarea> field
.'); |
| 30 return; |
| 31 } |
| 32 |
| 33 if (window.internals) { |
| 34 window.internals.setAutofilled(field, true); |
| 35 window.internals.setAutofilled(textarea, true); |
| 36 window.internals.setAutofilled(select, true); |
| 37 } |
| 38 |
| 39 // Both the foreground and background colors should change. |
| 40 computedStyleField = document.defaultView.getComputedStyle(field); |
| 41 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); |
| 42 computedStyleSelect = document.defaultView.getComputedStyle(select); |
| 43 if (computedStyleField.color == originalForeground) { |
| 44 testFailed('Foreground color for <input> element did not change when
autofilled.'); |
| 45 return; |
| 46 } |
| 47 if (computedStyleField.backgroundColor == originalBackground) { |
| 48 testFailed('Background color for <input> element did not change when
autofilled.'); |
| 49 return; |
| 50 } |
| 51 if (computedStyleTextarea.color == originalForeground) { |
| 52 testFailed('Foreground color for <textarea> element did not change w
hen autofilled.'); |
| 53 return; |
| 54 } |
| 55 if (computedStyleTextarea.backgroundColor == originalBackground) { |
| 56 testFailed('Background color for <textarea> element did not change w
hen autofilled.'); |
| 57 return; |
| 58 } |
| 59 if (computedStyleSelect.color == originalForeground) { |
| 60 testFailed('Foreground color for <select> element did not change whe
n autofilled.'); |
| 61 return; |
| 62 } |
| 63 if (computedStyleSelect.backgroundColor == originalBackground) { |
| 64 testFailed('Background color for <select> element did not change whe
n autofilled.'); |
| 65 return; |
| 66 } |
| 67 |
| 68 if (window.internals) { |
| 69 window.internals.setAutofilled(field, false); |
| 70 window.internals.setAutofilled(textarea, false); |
| 71 window.internals.setAutofilled(select, false); |
| 72 } |
| 73 |
| 74 // Colors should be restored. |
| 75 computedStyleField = document.defaultView.getComputedStyle(field); |
| 76 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); |
| 77 computedStyleSelect = document.defaultView.getComputedStyle(select); |
| 78 if (computedStyleField.color != originalForeground) { |
| 79 testFailed('Foreground color for <input> element did not revert when
un-autofilled.'); |
| 80 return; |
| 81 } |
| 82 if (computedStyleField.backgroundColor != originalBackground) { |
| 83 testFailed('Background color for <input> element did not revert when
un-autofilled.'); |
| 84 return; |
| 85 } |
| 86 if (computedStyleTextarea.color != originalForeground) { |
| 87 testFailed('Foreground color for <textarea> element did not revert w
hen un-autofilled.'); |
| 88 return; |
| 89 } |
| 90 if (computedStyleTextarea.backgroundColor != originalBackground) { |
| 91 testFailed('Background color for <textarea> element did not revert w
hen un-autofilled.'); |
| 92 return; |
| 93 } |
| 94 if (computedStyleSelect.color != originalForeground) { |
| 95 testFailed('Foreground color for <select> element did not revert whe
n un-autofilled.'); |
| 96 return; |
| 97 } |
| 98 if (computedStyleSelect.backgroundColor != originalBackground) { |
| 99 testFailed('Background color for <select> element did not revert whe
n un-autofilled.'); |
| 100 return; |
| 101 } |
| 102 |
| 103 testPassed(''); |
24 } | 104 } |
| 105 </script> |
25 | 106 |
26 var field = document.getElementById('field'); | 107 <style> |
27 var search = document.getElementById('search'); | 108 #field, #textarea, #select { |
28 var textarea1 = document.getElementById('textarea1'); | 109 color: #FFFFFF; |
29 var textarea2 = document.getElementById('textarea2'); | 110 background-color: #FFFFFF; |
30 textarea2.value = 'autofilled is true'; | 111 } |
31 var select1 = document.getElementById('select1'); | 112 </style> |
32 select2 = document.getElementById('select2'); | |
33 | |
34 shouldBe('foregroundOf(textarea1)', 'originalForeground'); | |
35 shouldBe('backgroundOf(textarea1)', 'originalBackground'); | |
36 | |
37 window.internals.setAutofilled(field, true); | |
38 window.internals.setAutofilled(search, true); | |
39 window.internals.setAutofilled(textarea1, true); | |
40 window.internals.setAutofilled(textarea2, true); | |
41 window.internals.setAutofilled(select1, true); | |
42 window.internals.setAutofilled(select2, true); | |
43 | |
44 shouldBeEqualToString('search.value', 'Search value'); | |
45 | |
46 // Both the foreground and background colors should change. | |
47 shouldNotBe('foregroundOf(field)', 'originalForeground'); | |
48 shouldNotBe('backgroundOf(field)', 'originalBackground'); | |
49 shouldNotBe('foregroundOf(search)', 'originalForeground'); | |
50 shouldNotBe('backgroundOf(search)', 'originalBackground'); | |
51 shouldNotBe('foregroundOf(textarea1)', 'originalForeground'); | |
52 shouldNotBe('backgroundOf(textarea1)', 'originalBackground'); | |
53 shouldNotBe('foregroundOf(textarea2)', 'originalForeground'); | |
54 shouldNotBe('backgroundOf(textarea2)', 'originalBackground'); | |
55 shouldNotBe('foregroundOf(select1)', 'originalForeground'); | |
56 shouldNotBe('backgroundOf(select1)', 'originalBackground'); | |
57 shouldNotBe('foregroundOf(select2)', 'originalForeground'); | |
58 shouldNotBe('backgroundOf(select2)', 'originalBackground'); | |
59 | |
60 // Remove an unselected option from <select> element. This should not affect
the background color for the autofilled <select> element. | |
61 shouldBe('select2.options.length', '3'); | |
62 select2.removeChild(select2.childNodes[1]); | |
63 shouldBe('select2.options.length', '2'); | |
64 autofilledSelectForeground = foregroundOf(select2); | |
65 autofilledSelectBackground = backgroundOf(select2); | |
66 shouldBe('foregroundOf(select2)', 'autofilledSelectForeground'); | |
67 shouldBe('backgroundOf(select2)', 'autofilledSelectBackground'); | |
68 | |
69 window.internals.setAutofilled(field, false); | |
70 window.internals.setAutofilled(textarea1, false); | |
71 window.internals.setAutofilled(select1, false); | |
72 | |
73 // Cancel search by pressing cancel button | |
74 var cancelPos = searchCancelButtonPosition(search); | |
75 eventSender.mouseMoveTo(cancelPos.x, cancelPos.y); | |
76 eventSender.mouseDown(); | |
77 eventSender.mouseUp(); | |
78 shouldBeEmptyString('search.value'); | |
79 | |
80 // Edit text in the autofilled textarea. | |
81 textarea2.focus(); | |
82 document.execCommand('Delete', false, null); | |
83 document.execCommand('Delete', false, null); | |
84 document.execCommand('Delete', false, null); | |
85 document.execCommand('Delete', false, null); | |
86 document.execCommand('InsertText', false, 'false'); | |
87 | |
88 // Remove selected option for select2 element | |
89 select2.removeChild(select2[select2.selectedIndex]); | |
90 | |
91 // Colors should be restored. | |
92 shouldBe('foregroundOf(field)', 'originalForeground'); | |
93 shouldBe('backgroundOf(field)', 'originalBackground'); | |
94 shouldBe('foregroundOf(search)', 'originalForeground'); | |
95 shouldBe('backgroundOf(search)', 'originalBackground'); | |
96 shouldBe('foregroundOf(textarea1)', 'originalForeground'); | |
97 shouldBe('backgroundOf(textarea1)', 'originalBackground'); | |
98 shouldBe('foregroundOf(textarea2)', 'originalForeground'); | |
99 shouldBe('backgroundOf(textarea2)', 'originalBackground'); | |
100 shouldBe('foregroundOf(select1)', 'originalForeground'); | |
101 shouldBe('backgroundOf(select1)', 'originalBackground'); | |
102 shouldBe('foregroundOf(select2)', 'originalForeground'); | |
103 shouldBe('backgroundOf(select2)', 'originalBackground'); | |
104 } | |
105 </script> | |
106 | |
107 <style> | |
108 #field, #search, #textarea1, #textarea2, #select1, #select2 { | |
109 color: #FFFFFF; | |
110 background-color: #FFFFFF; | |
111 } | |
112 </style> | |
113 </head> | 113 </head> |
114 <body onload="test()"> | 114 <body onload="test()"> |
115 This tests that foreground and background colors properly change for autofil
led inputs or select options. It can only be run using the test harness.<br> | 115 This tests that foreground and background colors properly change for autofil
led inputs or select options. It can only be run using the test harness.<br> |
116 <form name="fm"> | 116 <form name="fm"> |
117 <input type="text" id="field" value="Field value"> | 117 <input type="text" id="field" value="Field value"> |
118 <input type="search" id="search" value="Search value"> | 118 <textarea id="textarea"></textarea> |
119 <textarea id="textarea1"></textarea> | 119 <select id="select"></select> |
120 <textarea id="textarea2"></textarea> | |
121 <select id="select1"></select> | |
122 <select id="select2"> | |
123 <option selected>1</option> | |
124 <option >2</option> | |
125 <option>3</option> | |
126 </select> | |
127 </form> | 120 </form> |
128 <div id="console"></div> | 121 <div id="console"></div> |
129 </body> | 122 </body> |
OLD | NEW |