OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import pickle | 8 import pickle |
9 | 9 |
10 import autofill_dataset_converter | 10 import autofill_dataset_converter |
11 import autofill_dataset_generator | 11 import autofill_dataset_generator |
12 import pyauto_functional # Must be imported before pyauto | 12 import pyauto_functional # Must be imported before pyauto |
13 import pyauto | 13 import pyauto |
14 | 14 |
15 TAB_KEYPRESS = 0x09 # Tab keyboard key press. | |
16 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. | |
17 RETURN_KEYPRESS = 0x0D # Return keyboard key press. | |
18 | 15 |
19 class AutofillTest(pyauto.PyUITest): | 16 class AutofillTest(pyauto.PyUITest): |
20 """Tests that autofill works correctly""" | 17 """Tests that autofill works correctly""" |
21 | 18 |
22 def Debug(self): | 19 def Debug(self): |
23 """Test method for experimentation. | 20 """Test method for experimentation. |
24 | 21 |
25 This method will not run automatically. | 22 This method will not run automatically. |
26 """ | 23 """ |
27 import pprint | 24 import pprint |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 js_code = """ | 141 js_code = """ |
145 document.getElementById("merge_dup").submit(); | 142 document.getElementById("merge_dup").submit(); |
146 window.addEventListener("unload", function() { | 143 window.addEventListener("unload", function() { |
147 window.domAutomationController.send("done"); | 144 window.domAutomationController.send("done"); |
148 }); | 145 }); |
149 """ | 146 """ |
150 self.ExecuteJavascript(js_code, 0, 0) | 147 self.ExecuteJavascript(js_code, 0, 0) |
151 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: | 148 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: |
152 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | 149 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') |
153 | 150 |
| 151 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0): |
| 152 """Send key events to populate a web form with Autofill profile data. |
| 153 |
| 154 Args: |
| 155 tab_index: The tab index, default is 0. |
| 156 windex: The window index, default is 0. |
| 157 """ |
| 158 TAB_KEYPRESS = 0x09 # Tab keyboard key press. |
| 159 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. |
| 160 RETURN_KEYPRESS = 0x0D # Return keyboard key press. |
| 161 |
| 162 self.SendWebkitKeyEvent(TAB_KEYPRESS, tab_index, windex) |
| 163 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index, windex) |
| 164 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index, windex) |
| 165 self.SendWebkitKeyEvent(RETURN_KEYPRESS, tab_index, windex) |
| 166 |
154 def testComparePhoneNumbers(self): | 167 def testComparePhoneNumbers(self): |
155 """Test phone fields parse correctly from a given profile. | 168 """Test phone fields parse correctly from a given profile. |
156 | 169 |
157 The high level key presses execute the following: Select the first text | 170 The high level key presses execute the following: Select the first text |
158 field, invoke the autofill popup list, select the first profile within the | 171 field, invoke the autofill popup list, select the first profile within the |
159 list, and commit to the profile to populate the form. | 172 list, and commit to the profile to populate the form. |
160 """ | 173 """ |
161 profile_path = os.path.join(self.DataDir(), 'autofill', | 174 profile_path = os.path.join(self.DataDir(), 'autofill', |
162 'phone_pinput_autofill.txt') | 175 'phone_pinput_autofill.txt') |
163 profile_expected_path = os.path.join(self.DataDir(), 'autofill', | 176 profile_expected_path = os.path.join(self.DataDir(), 'autofill', |
164 'phone_pexpected_autofill.txt') | 177 'phone_pexpected_autofill.txt') |
165 profiles = self.EvalDataFrom(profile_path) | 178 profiles = self.EvalDataFrom(profile_path) |
166 profiles_expected = self.EvalDataFrom(profile_expected_path) | 179 profiles_expected = self.EvalDataFrom(profile_expected_path) |
167 self.FillAutofillProfile(profiles=profiles) | 180 self.FillAutofillProfile(profiles=profiles) |
168 url = self.GetHttpURLForDataPath( | 181 url = self.GetHttpURLForDataPath( |
169 os.path.join('autofill', 'form_phones.html')) | 182 os.path.join('autofill', 'form_phones.html')) |
170 for profile_expected in profiles_expected: | 183 for profile_expected in profiles_expected: |
171 self.NavigateToURL(url) | 184 self.NavigateToURL(url) |
172 # Tab keyboard key press. | 185 self._SendKeyEventsToPopulateForm() |
173 self.SendWebkitKeyEvent(TAB_KEYPRESS, tab_index=0, windex=0) | |
174 # Down arrow keyboard key press. | |
175 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
176 # Down arrow keyboard key press. | |
177 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
178 # Return keyboard key press. | |
179 self.SendWebkitKeyEvent(RETURN_KEYPRESS, tab_index=0, windex=0) | |
180 form_values = {} | 186 form_values = {} |
181 for key, value in profile_expected.iteritems(): | 187 for key, value in profile_expected.iteritems(): |
182 js_returning_field_value = ( | 188 js_returning_field_value = ( |
183 'var field_value = document.getElementById("%s").value;' | 189 'var field_value = document.getElementById("%s").value;' |
184 'window.domAutomationController.send(field_value);' | 190 'window.domAutomationController.send(field_value);' |
185 ) % key | 191 ) % key |
186 form_values[key] = self.ExecuteJavascript( | 192 form_values[key] = self.ExecuteJavascript( |
187 js_returning_field_value, 0, 0) | 193 js_returning_field_value, 0, 0) |
188 self.assertEqual( | 194 self.assertEqual( |
189 form_values[key], value, | 195 form_values[key], value, |
(...skipping 26 matching lines...) Expand all Loading... |
216 """ | 222 """ |
217 self.ExecuteJavascript(js_code, 0, 0) | 223 self.ExecuteJavascript(js_code, 0, 0) |
218 # Wait until form is submitted and page completes loading. | 224 # Wait until form is submitted and page completes loading. |
219 self.WaitUntil( | 225 self.WaitUntil( |
220 lambda: self.GetDOMValue('document.readyState'), | 226 lambda: self.GetDOMValue('document.readyState'), |
221 expect_retval='complete') | 227 expect_retval='complete') |
222 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | 228 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] |
223 self.assertEqual(0, len(cc_infobar), | 229 self.assertEqual(0, len(cc_infobar), |
224 'Save credit card infobar offered to save CC info.') | 230 'Save credit card infobar offered to save CC info.') |
225 | 231 |
| 232 def testNoAutofillForReadOnlyFields(self): |
| 233 """Test that Autofill does not fill in read-only fields.""" |
| 234 profile = {'NAME_FIRST': 'Bob', |
| 235 'NAME_LAST': 'Smith', |
| 236 'EMAIL_ADDRESS': 'bsmith@gmail.com', |
| 237 'ADDRESS_HOME_LINE1': '1234 H St.', |
| 238 'ADDRESS_HOME_CITY': 'San Jose', |
| 239 'ADDRESS_HOME_STATE': 'CA', |
| 240 'ADDRESS_HOME_ZIP': '95110', |
| 241 'COMPANY_NAME': 'Company X', |
| 242 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} |
| 243 |
| 244 self.FillAutofillProfile(profiles=[profile]) |
| 245 url = self.GetHttpURLForDataPath( |
| 246 os.path.join('autofill', 'read_only_field_test.html')) |
| 247 self.NavigateToURL(url) |
| 248 self._SendKeyEventsToPopulateForm() |
| 249 js_return_readonly_field = ( |
| 250 'var field_value = document.getElementById("email").value;' |
| 251 'window.domAutomationController.send(field_value);') |
| 252 readonly_field_value = self.ExecuteJavascript( |
| 253 js_return_readonly_field, 0, 0) |
| 254 js_return_addrline1_field = ( |
| 255 'var field_value = document.getElementById("address").value;' |
| 256 'window.domAutomationController.send(field_value);') |
| 257 addrline1_field_value = self.ExecuteJavascript( |
| 258 js_return_addrline1_field, 0, 0) |
| 259 self.assertNotEqual( |
| 260 readonly_field_value, profile['EMAIL_ADDRESS'], |
| 261 'Autofill filled in value for a read-only field.') |
| 262 self.assertEqual( |
| 263 addrline1_field_value, profile['ADDRESS_HOME_LINE1'], |
| 264 'Unexpected value in the Address field.') |
| 265 |
226 def FormFillLatencyAfterSubmit(self): | 266 def FormFillLatencyAfterSubmit(self): |
227 """Test latency time on form submit with lots of stored Autofill profiles. | 267 """Test latency time on form submit with lots of stored Autofill profiles. |
228 | 268 |
229 This test verifies when a profile is selected from the Autofill dictionary | 269 This test verifies when a profile is selected from the Autofill dictionary |
230 that consists of thousands of profiles, the form does not hang after being | 270 that consists of thousands of profiles, the form does not hang after being |
231 submitted. | 271 submitted. |
232 | 272 |
233 The high level key presses execute the following: Select the first text | 273 The high level key presses execute the following: Select the first text |
234 field, invoke the autofill popup list, select the first profile within the | 274 field, invoke the autofill popup list, select the first profile within the |
235 list, and commit to the profile to populate the form. | 275 list, and commit to the profile to populate the form. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 merged_profile = os.path.join(self.DataDir(), 'autofill', | 367 merged_profile = os.path.join(self.DataDir(), 'autofill', |
328 'merged-profiles.txt') | 368 'merged-profiles.txt') |
329 profile_dict = self.GetAutofillProfile()['profiles'] | 369 profile_dict = self.GetAutofillProfile()['profiles'] |
330 output = open(merged_profile, 'wb') | 370 output = open(merged_profile, 'wb') |
331 pickle.dump(profile_dict, output) | 371 pickle.dump(profile_dict, output) |
332 output.close() | 372 output.close() |
333 | 373 |
334 | 374 |
335 if __name__ == '__main__': | 375 if __name__ == '__main__': |
336 pyauto_functional.Main() | 376 pyauto_functional.Main() |
OLD | NEW |