OLD | NEW |
---|---|
1 <head> | 1 <head> |
tkent
2014/08/14 23:10:26
We should remove |input| from the file name becaus
ziran.sun
2014/08/15 13:58:28
I'll do this in another CL once this patch is land
| |
2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
3 <script> | 3 <script> |
4 function test() { | 4 function test() { |
5 if (window.testRunner) { | 5 if (!window.internals) { |
6 testRunner.dumpAsText(); | 6 testFailed('This test requires the test harness to run.'); |
7 } | 7 return; |
8 | 8 } |
9 if (!window.internals) { | 9 |
10 testFailed('This test requires the test harness to run.'); | 10 var field = document.getElementById('field'); |
11 return; | 11 var search = document.getElementById('search'); |
12 } | 12 var textarea1 = document.getElementById('textarea1'); |
13 | 13 var textarea2 = document.getElementById('textarea2'); |
14 var field = document.getElementById('field'); | 14 textarea2.value = 'autofilled is true'; |
15 var textarea = document.getElementById('textarea'); | 15 var select1 = document.getElementById('select1'); |
16 var select = document.getElementById('select'); | 16 var select2 = document.getElementById('select2'); |
17 | 17 |
18 var computedStyleField = document.defaultView.getComputedStyle(field); | 18 var computedStyleField = document.defaultView.getComputedStyle(field); |
19 var computedStyleTextarea = document.defaultView.getComputedStyle(textar ea); | 19 var computedStyleSearch = document.defaultView.getComputedStyle(search); |
20 var computedStyleSelect = document.defaultView.getComputedStyle(select); | 20 var computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1 ); |
21 var originalForeground = computedStyleField.color; | 21 var computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2 ); |
22 var originalBackground = computedStyleField.backgroundColor; | 22 var computedStyleSelect1 = document.defaultView.getComputedStyle(select1); |
23 | 23 var computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
24 if (originalForeground != computedStyleTextarea.color) { | 24 var originalForeground = computedStyleField.color; |
25 testFailed('Unexpected initial foreground color for <textarea> field .'); | 25 var originalBackground = computedStyleField.backgroundColor; |
26 return; | 26 |
27 } | 27 if (originalForeground != computedStyleTextarea1.color) { |
28 if (originalForeground != computedStyleTextarea.backgroundColor) { | 28 testFailed('Unexpected initial foreground color for <textarea> field.'); |
29 testFailed('Unexpected initial background color for <textarea> field .'); | 29 return; |
30 return; | 30 } |
31 } | 31 if (originalBackground != computedStyleTextarea1.backgroundColor) { |
32 | 32 testFailed('Unexpected initial background color for <textarea> field.'); |
33 if (window.internals) { | 33 return; |
34 window.internals.setAutofilled(field, true); | 34 } |
35 window.internals.setAutofilled(textarea, true); | 35 |
36 window.internals.setAutofilled(select, true); | 36 if (window.internals) { |
tkent
2014/08/14 23:10:25
This check is unnecessary. We already have it in
| |
37 } | 37 window.internals.setAutofilled(field, true); |
38 | 38 window.internals.setAutofilled(search, true); |
39 // Both the foreground and background colors should change. | 39 window.internals.setAutofilled(textarea1, true); |
40 computedStyleField = document.defaultView.getComputedStyle(field); | 40 window.internals.setAutofilled(textarea2, true); |
41 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); | 41 window.internals.setAutofilled(select1, true); |
42 computedStyleSelect = document.defaultView.getComputedStyle(select); | 42 window.internals.setAutofilled(select2, true); |
43 if (computedStyleField.color == originalForeground) { | 43 } |
44 testFailed('Foreground color for <input> element did not change when autofilled.'); | 44 |
45 return; | 45 shouldBe('search.value', '"Search value"'); |
tkent
2014/08/14 23:10:25
shouldBeEqualToString('search.value', 'Search valu
| |
46 } | 46 |
47 if (computedStyleField.backgroundColor == originalBackground) { | 47 // Both the foreground and background colors should change. |
48 testFailed('Background color for <input> element did not change when autofilled.'); | 48 computedStyleField = document.defaultView.getComputedStyle(field); |
49 return; | 49 computedStyleSearch = document.defaultView.getComputedStyle(search); |
tkent
2014/08/14 23:10:25
inconsistent indentation.
| |
50 } | 50 computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1); |
51 if (computedStyleTextarea.color == originalForeground) { | 51 computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2); |
52 testFailed('Foreground color for <textarea> element did not change w hen autofilled.'); | 52 computedStyleSelect1 = document.defaultView.getComputedStyle(select1); |
53 return; | 53 computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
54 } | 54 if (computedStyleField.color == originalForeground) { |
tkent
2014/08/14 23:10:25
Why don't you use shouldBe()?
| |
55 if (computedStyleTextarea.backgroundColor == originalBackground) { | 55 testFailed('Foreground color for <input> text element did not change whe n autofilled.'); |
56 testFailed('Background color for <textarea> element did not change w hen autofilled.'); | 56 return; |
57 return; | 57 } |
58 } | 58 if (computedStyleField.backgroundColor == originalBackground) { |
59 if (computedStyleSelect.color == originalForeground) { | 59 testFailed('Background color for <input> text element did not change whe n autofilled.'); |
60 testFailed('Foreground color for <select> element did not change whe n autofilled.'); | 60 return; |
61 return; | 61 } |
62 } | 62 if (computedStyleSearch.color == originalForeground) { |
63 if (computedStyleSelect.backgroundColor == originalBackground) { | 63 testFailed('Foreground color for <input> serach element did not change w hen autofilled.'); |
64 testFailed('Background color for <select> element did not change whe n autofilled.'); | 64 return; |
65 return; | 65 } |
66 } | 66 if (computedStyleSearch.backgroundColor == originalBackground) { |
67 | 67 testFailed('Background color for <input> search element did not change w hen autofilled.'); |
68 if (window.internals) { | 68 return; |
69 window.internals.setAutofilled(field, false); | 69 } |
70 window.internals.setAutofilled(textarea, false); | 70 if (computedStyleTextarea1.color == originalForeground) { |
71 window.internals.setAutofilled(select, false); | 71 testFailed('Foreground color for <textarea> element did not change when autofilled.'); |
72 } | 72 return; |
73 | 73 } |
74 // Colors should be restored. | 74 if (computedStyleTextarea1.backgroundColor == originalBackground) { |
75 computedStyleField = document.defaultView.getComputedStyle(field); | 75 testFailed('Background color for <textarea> element did not change when autofilled.'); |
76 computedStyleTextarea = document.defaultView.getComputedStyle(textarea); | 76 return; |
77 computedStyleSelect = document.defaultView.getComputedStyle(select); | 77 } |
78 if (computedStyleField.color != originalForeground) { | 78 if (computedStyleTextarea2.color == originalForeground) { |
79 testFailed('Foreground color for <input> element did not revert when un-autofilled.'); | 79 testFailed('Foreground color for <textarea> element did not change when autofilled.'); |
80 return; | 80 return; |
81 } | 81 } |
82 if (computedStyleField.backgroundColor != originalBackground) { | 82 if (computedStyleTextarea2.backgroundColor == originalBackground) { |
83 testFailed('Background color for <input> element did not revert when un-autofilled.'); | 83 testFailed('Background color for <textarea> element did not change when autofilled.'); |
84 return; | 84 return; |
85 } | 85 } |
86 if (computedStyleTextarea.color != originalForeground) { | 86 if (computedStyleSelect1.color == originalForeground) { |
87 testFailed('Foreground color for <textarea> element did not revert w hen un-autofilled.'); | 87 testFailed('Foreground color for <select> element did not change when au tofilled.'); |
88 return; | 88 return; |
89 } | 89 } |
90 if (computedStyleTextarea.backgroundColor != originalBackground) { | 90 if (computedStyleSelect1.backgroundColor == originalBackground) { |
91 testFailed('Background color for <textarea> element did not revert w hen un-autofilled.'); | 91 testFailed('Background color for <select> element did not change when au tofilled.'); |
92 return; | 92 return; |
93 } | 93 } |
94 if (computedStyleSelect.color != originalForeground) { | 94 if (computedStyleSelect2.color == originalForeground) { |
95 testFailed('Foreground color for <select> element did not revert whe n un-autofilled.'); | 95 testFailed('Foreground color for <select> element did not change when au tofilled.'); |
96 return; | 96 return; |
97 } | 97 } |
98 if (computedStyleSelect.backgroundColor != originalBackground) { | 98 if (computedStyleSelect2.backgroundColor == originalBackground) { |
99 testFailed('Background color for <select> element did not revert whe n un-autofilled.'); | 99 testFailed('Background color for <select> element did not change when au tofilled.'); |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 testPassed(''); | 103 // Remove an unselected option from <select> element. This should not affect the background color for the autofilled <select> element. |
104 } | 104 if (select2.options.length != 3) |
105 </script> | 105 log("Incorrect options length: " + select2.options.length); |
tkent
2014/08/14 23:10:25
Inconsistent quote marks. This line uses double-q
| |
106 | 106 select2.removeChild(select2.childNodes[1]); |
107 <style> | 107 if (select2.options.length != 2) |
108 #field, #textarea, #select { | 108 log("Incorrect options length: " + select2.options.length); |
109 color: #FFFFFF; | 109 var autofilledSelectForeground = computedStyleSelect2.color; |
110 background-color: #FFFFFF; | 110 var autofilledSelectBackground = computedStyleSelect2.backgroundColor; |
111 } | 111 computedStyleSelect2 = document.defaultView.getComputedStyle(select2); |
112 </style> | 112 if (computedStyleSelect2.color !== autofilledSelectForeground) { |
113 testFailed('Foreground color for <select> element changed after removing unselected option(s).'); | |
114 return; | |
115 } | |
116 if (computedStyleSelect2.backgroundColor !== autofilledSelectBackground) { | |
117 testFailed('Background color for <select> element changed after removing unselected option(s).'); | |
118 return; | |
119 } | |
120 | |
121 if (window.internals) { | |
tkent
2014/08/14 23:10:25
This check is unnecessary.
| |
122 window.internals.setAutofilled(field, false); | |
123 window.internals.setAutofilled(textarea1, false); | |
124 window.internals.setAutofilled(select1, false); | |
125 } | |
126 | |
127 // Cancel search by pressing cancel button | |
128 eventSender.mouseMoveTo(search.offsetLeft + search.offsetWidth - 8, search.o ffsetTop + search.offsetHeight / 2); | |
tkent
2014/08/14 23:10:25
Please use searchCancelButtonPosition() defined in
| |
129 eventSender.mouseDown(); | |
130 eventSender.mouseUp(); | |
131 shouldBe('search.value', '""'); | |
tkent
2014/08/14 23:10:25
shouldBeEqualToString
| |
132 | |
133 // Edit text in the autofilled textarea. | |
134 textarea2.focus(); | |
135 document.execCommand('Delete', false, null); | |
136 document.execCommand('Delete', false, null); | |
137 document.execCommand('Delete', false, null); | |
138 document.execCommand('Delete', false, null); | |
139 document.execCommand('InsertText', false, 'false'); | |
140 | |
141 // Remove selected option for select2 element | |
142 select2.removeChild(select2.firstChild); | |
143 | |
144 // Colors should be restored. | |
145 computedStyleField = document.defaultView.getComputedStyle(field); | |
146 computedStyleSearch = document.defaultView.getComputedStyle(search); | |
147 computedStyleTextarea1 = document.defaultView.getComputedStyle(textarea1); | |
148 computedStyleTextarea2 = document.defaultView.getComputedStyle(textarea2); | |
149 computedStyleSelect1 = document.defaultView.getComputedStyle(select1); | |
150 computedStyleSelect2 = document.defaultView.getComputedStyle(select2); | |
tkent
2014/08/14 23:10:26
inconsistent indentation
| |
151 if (computedStyleField.color !== originalForeground) { | |
tkent
2014/08/14 23:10:26
Why don't you use shouldBe()?
| |
152 testFailed('Foreground color for <input> element did not revert when un- autofilled.'); | |
153 return; | |
154 } | |
155 if (computedStyleField.backgroundColor !== originalBackground) { | |
156 testFailed('Background color for <input> text element did not revert whe n un-autofilled.'); | |
157 return; | |
158 } | |
159 if (computedStyleSearch.color !== originalForeground) { | |
160 testFailed('Foreground color for <input> search element did not revert w hen search is cancelled'); | |
161 return; | |
162 } | |
163 if (computedStyleSearch.backgroundColor !== originalBackground) { | |
164 testFailed('Background color for <input> search element did not revert w hen search is cancelled'); | |
165 return; | |
166 } | |
167 if (computedStyleTextarea1.color !== originalForeground) { | |
168 testFailed('Foreground color for <textarea> element did not revert when un-autofilled.'); | |
169 return; | |
170 } | |
171 if (computedStyleTextarea1.backgroundColor !== originalBackground) { | |
172 testFailed('Background color for <textarea> element did not revert when un-autofilled.'); | |
173 return; | |
174 } | |
175 if (computedStyleTextarea2.color !== originalForeground) { | |
176 testFailed('Foreground color for <textarea> element did not revert when editing autofilled text.'); | |
177 return; | |
178 } | |
179 if (computedStyleTextarea2.backgroundColor !== originalBackground) { | |
180 testFailed('Background color for <textarea> element did not revert when editing autofilled text.'); | |
181 return; | |
182 } | |
183 if (computedStyleSelect1.color != originalForeground) { | |
184 testFailed('Foreground color for <select> element did not revert when un -autofilled.'); | |
185 return; | |
186 } | |
187 if (computedStyleSelect1.backgroundColor != originalBackground) { | |
188 testFailed('Background color for <select> element did not revert when un -autofilled.'); | |
189 return; | |
190 } | |
191 if (computedStyleSelect2.color != originalForeground) { | |
192 testFailed('Foreground color for <select> element did not revert when au tofilled option is removed'); | |
193 return; | |
194 } | |
195 if (computedStyleSelect2.backgroundColor != originalBackground) { | |
196 testFailed('Background color for <select> element did not revert when au tofilled option is removed'); | |
197 return; | |
198 } | |
199 | |
200 testPassed(''); | |
201 } | |
202 </script> | |
203 | |
204 <style> | |
205 #field, #search, #textarea1, #textarea2, #select1, #select2 { | |
tkent
2014/08/14 23:10:25
Indentation is unnecessary.
| |
206 color: #FFFFFF; | |
207 background-color: #FFFFFF; | |
208 } | |
209 </style> | |
113 </head> | 210 </head> |
114 <body onload="test()"> | 211 <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> | 212 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"> | 213 <form name="fm"> |
117 <input type="text" id="field" value="Field value"> | 214 <input type="text" id="field" value="Field value"> |
118 <textarea id="textarea"></textarea> | 215 <input type="search" id="search" value="Search value"> |
119 <select id="select"></select> | 216 <textarea id="textarea1"></textarea> |
217 <textarea id="textarea2"></textarea> | |
218 <select id="select1"></select> | |
219 <select id="select2"> | |
220 <option selected>1</option> | |
221 <option >2</option> | |
222 <option>3</option> | |
223 </select> | |
120 </form> | 224 </form> |
121 <div id="console"></div> | 225 <div id="console"></div> |
122 </body> | 226 </body> |
OLD | NEW |