Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Side by Side Diff: chrome/test/functional/autofill.py

Issue 6850007: Fixed a few Autofill automation failures and added new tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 re
dennis_jeffrey 2011/04/16 00:22:16 move this 2 lines down to ensure it's in alphabeti
dyu1 2011/04/16 00:37:32 Done.
7 import os 8 import os
8 import pickle 9 import pickle
9 10
10 import autofill_dataset_converter 11 import autofill_dataset_converter
11 import autofill_dataset_generator 12 import autofill_dataset_generator
12 import pyauto_functional # Must be imported before pyauto 13 import pyauto_functional # Must be imported before pyauto
13 import pyauto 14 import pyauto
14 15
15 16
16 class AutofillTest(pyauto.PyUITest): 17 class AutofillTest(pyauto.PyUITest):
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 'ADDRESS_HOME_ZIP': 'my_zip', 84 'ADDRESS_HOME_ZIP': 'my_zip',
84 'ADDRESS_HOME_COUNTRY': 'United States'} 85 'ADDRESS_HOME_COUNTRY': 'United States'}
85 # Add some invalid fields. 86 # Add some invalid fields.
86 with_invalid = without_invalid.copy() 87 with_invalid = without_invalid.copy()
87 with_invalid['PHONE_HOME_WHOLE_NUMBER'] = 'Invalid_Phone_Number' 88 with_invalid['PHONE_HOME_WHOLE_NUMBER'] = 'Invalid_Phone_Number'
88 with_invalid['PHONE_FAX_WHOLE_NUMBER'] = 'Invalid_Fax_Number' 89 with_invalid['PHONE_FAX_WHOLE_NUMBER'] = 'Invalid_Fax_Number'
89 self.FillAutofillProfile(profiles=[with_invalid]) 90 self.FillAutofillProfile(profiles=[with_invalid])
90 self.assertEqual([without_invalid], 91 self.assertEqual([without_invalid],
91 self.GetAutofillProfile()['profiles']) 92 self.GetAutofillProfile()['profiles'])
92 93
93 def testFilterIncompleteAddresses(self): 94 def testAutofillPrefsStringSavedAsIs(self):
94 """Test Autofill filters out profile with incomplete address info.""" 95 """Test invalid credit card numbers typed in prefs should be saved as-is."""
96 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'}
97 self.FillAutofillProfile(credit_cards=[credit_card])
98 self.assertEqual([credit_card],
99 self.GetAutofillProfile()['credit_cards'],
100 msg='Credit card number in prefs not saved as-is.')
101
102 def _LuhnCreditCardNumberValidator(self, number):
103 """Validates whether a number is valid or invalid using the Luhn test.
104
105 Validation steps:
106 1. Reverse the order of the digits in the number.
107 2. Double the value of every digit that is in an even-numbered position.
108 3. For every doubled digit, if the value is greater than 9, subtract 9
109 from the value.
110 4. Sum all resulting digit values in all psitions.
dennis_jeffrey 2011/04/16 00:22:16 "psitions" --> "positions"
dyu1 2011/04/16 00:37:32 Reworded it.
111 5. Is the sum is divisible by 10, the number is valid. Otherwise, the
dennis_jeffrey 2011/04/16 00:22:16 "Is the sum" --> "If the sum"
dyu1 2011/04/16 00:37:32 Re wrote it.
112 number is invalid.
113
114 Args:
115 number: the credit card number being validated, as a string.
116
117 Return:
118 boolean whether the credit card number is valid or not.
119 """
120 # Filters out non-digit characters.
121 number = re.sub('[^0-9]', '', number)
122 reverse = [int(ch) for ch in str(number)][::-1]
123 # The divmod of the function splits a number into two digits, ready for
124 # summing.
125 return ((sum(reverse[0::2]) + sum(sum(divmod(d*2, 10))
dennis_jeffrey 2011/04/16 00:22:16 The implementation needs to be updated to reflect
dyu1 2011/04/16 00:37:32 Rewrote it to fit this formula.
126 for d in reverse[1::2])) % 10 == 0)
127
128 def testInvalidCreditCardNumberIsNotAggregated(self):
129 """Test credit card info with an invalid number is not aggregated.
130
131 When filling out a form with an invalid credit card number (one that
132 does not pass the Luhn test) the credit card info should not be saved into
133 Autofill preferences.
134 """
135 invalid_cc_info = {'CREDIT_CARD_NAME': 'Bob Smith',
136 'CREDIT_CARD_NUMBER': '4408 0412 3456 7890',
137 'CREDIT_CARD_EXP_MONTH': '12',
138 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2014'}
139
140 cc_number = invalid_cc_info['CREDIT_CARD_NUMBER']
141 self.assertFalse(self._LuhnCreditCardNumberValidator(cc_number),
142 msg='This test requires an invalid credit card number.')
143 url = self.GetHttpURLForDataPath(
144 os.path.join('autofill', 'autofill_creditcard_form.html'))
145 self.NavigateToURL(url)
146 for key, value in invalid_cc_info.iteritems():
147 script = ('document.getElementById("%s").value = "%s"; '
148 'window.domAutomationController.send("done");') % (key, value)
149 self.ExecuteJavascript(script, 0, 0)
150 js_code = """
151 document.getElementById("cc_submit").submit();
152 window.addEventListener("unload", function() {
153 window.domAutomationController.send("done");
154 });
155 """
156 self.ExecuteJavascript(js_code, 0, 0)
157 # Wait until the form is submitted and the page completes loading.
158 self.WaitUntil(
159 lambda: self.GetDOMValue('document.readyState'),
160 expect_retval='complete')
161 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']
162 self.assertFalse(
163 cc_infobar, msg='Save credit card infobar offered to save CC info.')
164
165 def testWhitespacesAndSeparatorCharsStrippedForValidCCNums(self):
166 """Test whitespaces and separator chars are stripped for valid CC numbers.
167
168 The credit card numbers used in this test pass the Luhn test.
169 For reference: http://www.merriampark.com/anatomycc.htm
170 """
171 credit_card_info = [{'CREDIT_CARD_NAME': 'Bob Smith',
172 'CREDIT_CARD_NUMBER': '4408 0412 3456 7893',
173 'CREDIT_CARD_EXP_MONTH': '12',
174 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2014'},
175 {'CREDIT_CARD_NAME': 'Jane Doe',
176 'CREDIT_CARD_NUMBER': '4417-1234-5678-9113',
177 'CREDIT_CARD_EXP_MONTH': '10',
178 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2013'}]
179
180 url = self.GetHttpURLForDataPath(
181 os.path.join('autofill', 'autofill_creditcard_form.html'))
182 for cc_info in credit_card_info:
183 cc_number = credit_card_info['CREDIT_CARD_NUMBER']
184 self.assertTrue(self._LuhnCreditCardNumberValidator(cc_number),
185 msg='This test requires a valid credit card number.')
186 self.NavigateToURL(url)
187 for key, value in cc_info.iteritems():
188 script = ('document.getElementById("%s").value = "%s"; '
189 'window.domAutomationController.send("done");') % (key, value)
190 self.ExecuteJavascript(script, 0, 0)
191 js_code = """
192 document.getElementById("cc_submit").submit();
193 window.addEventListener("unload", function() {
194 window.domAutomationController.send("done");
195 });
196 """
197 self.ExecuteJavascript(js_code, 0, 0)
198 # Wait until form is submitted and page completes loading.
199 self.WaitUntil(
200 lambda: self.GetDOMValue('document.readyState'),
201 expect_retval='complete')
202 self.PerformActionOnInfobar('accept', infobar_index=0)
203
204 # Verify the filled-in credit card number against the aggregated number.
205 aggregated_cc_1 = (
206 self.GetAutofillProfile()['credit_cards'][0]['CREDIT_CARD_NUMBER'])
207 aggregated_cc_2 = (
208 self.GetAutofillProfile()['credit_cards'][1]['CREDIT_CARD_NUMBER'])
209 self.assertFalse((' ' in aggregated_cc_1 or ' ' in aggregated_cc_2 or
210 '-' in aggregated_cc_1 or '-' in aggregated_cc_2),
211 msg='Whitespaces or separator chars not stripped.')
212
213 def testProfilesNotAggregatedWithNoAddress(self):
214 """Test Autofill does not aggregate profiles with no address info."""
95 profile = {'NAME_FIRST': 'Bob', 215 profile = {'NAME_FIRST': 'Bob',
96 'NAME_LAST': 'Smith', 216 'NAME_LAST': 'Smith',
97 'EMAIL_ADDRESS': 'bsmith@example.com', 217 'EMAIL_ADDRESS': 'bsmith@example.com',
98 'COMPANY_NAME': 'Company X', 218 'COMPANY_NAME': 'Company X',
99 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} 219 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',}
100 url = self.GetHttpURLForDataPath( 220 url = self.GetHttpURLForDataPath(
101 os.path.join('autofill', 'duplicate_profiles_test.html')) 221 os.path.join('autofill', 'duplicate_profiles_test.html'))
102 self.NavigateToURL(url) 222 self.NavigateToURL(url)
103 for key, value in profile.iteritems(): 223 for key, value in profile.iteritems():
104 script = ('document.getElementById("%s").value = "%s"; ' 224 script = ('document.getElementById("%s").value = "%s"; '
105 'window.domAutomationController.send("done");') % (key, value) 225 'window.domAutomationController.send("done");') % (key, value)
106 self.ExecuteJavascript(script, 0, 0) 226 self.ExecuteJavascript(script, 0, 0)
107 js_code = """ 227 js_code = """
108 document.getElementById("merge_dup").submit(); 228 document.getElementById("merge_dup").submit();
109 window.addEventListener("unload", function() { 229 window.addEventListener("unload", function() {
110 window.domAutomationController.send("done"); 230 window.domAutomationController.send("done");
111 }); 231 });
112 """ 232 """
113 self.ExecuteJavascript(js_code, 0, 0) 233 self.ExecuteJavascript(js_code, 0, 0)
114 self.assertEqual([], self.GetAutofillProfile()['profiles']) 234 self.assertFalse(self.GetAutofillProfile()['profiles'],
235 msg='Profile with no address info was aggregated.')
115 236
116 def testFilterMalformedEmailAddresses(self): 237 def testProfilesNotAggregatedWithInvalidEmail(self):
117 """Test Autofill filters out malformed email address during form submit.""" 238 """Test Autofill does not aggregate profiles with an invalid email."""
118 profile = {'NAME_FIRST': 'Bob', 239 profile = {'NAME_FIRST': 'Bob',
119 'NAME_LAST': 'Smith', 240 'NAME_LAST': 'Smith',
120 'EMAIL_ADDRESS': 'garbage', 241 'EMAIL_ADDRESS': 'garbage',
121 'ADDRESS_HOME_LINE1': '1234 H St.', 242 'ADDRESS_HOME_LINE1': '1234 H St.',
122 'ADDRESS_HOME_CITY': 'San Jose', 243 'ADDRESS_HOME_CITY': 'San Jose',
123 'ADDRESS_HOME_STATE': 'CA', 244 'ADDRESS_HOME_STATE': 'CA',
124 'ADDRESS_HOME_ZIP': '95110', 245 'ADDRESS_HOME_ZIP': '95110',
125 'COMPANY_NAME': 'Company X', 246 'COMPANY_NAME': 'Company X',
126 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} 247 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',}
127 url = self.GetHttpURLForDataPath( 248 url = self.GetHttpURLForDataPath(
128 os.path.join('autofill', 'duplicate_profiles_test.html')) 249 os.path.join('autofill', 'duplicate_profiles_test.html'))
129 self.NavigateToURL(url) 250 self.NavigateToURL(url)
130 for key, value in profile.iteritems(): 251 for key, value in profile.iteritems():
131 script = ('document.getElementById("%s").value = "%s"; ' 252 script = ('document.getElementById("%s").value = "%s"; '
132 'window.domAutomationController.send("done");') % (key, value) 253 'window.domAutomationController.send("done");') % (key, value)
133 self.ExecuteJavascript(script, 0, 0) 254 self.ExecuteJavascript(script, 0, 0)
134 js_code = """ 255 js_code = """
135 document.getElementById("merge_dup").submit(); 256 document.getElementById("merge_dup").submit();
136 window.addEventListener("unload", function() { 257 window.addEventListener("unload", function() {
137 window.domAutomationController.send("done"); 258 window.domAutomationController.send("done");
138 }); 259 });
139 """ 260 """
140 self.ExecuteJavascript(js_code, 0, 0) 261 self.ExecuteJavascript(js_code, 0, 0)
141 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: 262 self.assertFalse(self.GetAutofillProfile()['profiles'],
142 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') 263 msg='Profile with invalid email was aggregated.')
143 264
144 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0): 265 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0):
145 """Send key events to populate a web form with Autofill profile data. 266 """Send key events to populate a web form with Autofill profile data.
146 267
147 Args: 268 Args:
148 tab_index: The tab index, default is 0. 269 tab_index: The tab index, default is 0.
149 windex: The window index, default is 0. 270 windex: The window index, default is 0.
150 """ 271 """
151 TAB_KEYPRESS = 0x09 # Tab keyboard key press. 272 TAB_KEYPRESS = 0x09 # Tab keyboard key press.
152 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. 273 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press.
(...skipping 26 matching lines...) Expand all
179 form_values = {} 300 form_values = {}
180 for key, value in profile_expected.iteritems(): 301 for key, value in profile_expected.iteritems():
181 js_returning_field_value = ( 302 js_returning_field_value = (
182 'var field_value = document.getElementById("%s").value;' 303 'var field_value = document.getElementById("%s").value;'
183 'window.domAutomationController.send(field_value);' 304 'window.domAutomationController.send(field_value);'
184 ) % key 305 ) % key
185 form_values[key] = self.ExecuteJavascript( 306 form_values[key] = self.ExecuteJavascript(
186 js_returning_field_value, 0, 0) 307 js_returning_field_value, 0, 0)
187 self.assertEqual( 308 self.assertEqual(
188 form_values[key], value, 309 form_values[key], value,
189 ('Original profile not equal to expected profile at key: "%s"\n' 310 msg=('Original profile not equal to expected profile at key: "%s"\n'
190 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) 311 'Expected: "%s"\nReturned: "%s"' % (
312 key, value, form_values[key])))
191 313
192 def testCCInfoNotStoredWhenAutocompleteOff(self): 314 def testCCInfoNotStoredWhenAutocompleteOff(self):
193 """Test CC info not offered to be saved when autocomplete=off for CC field. 315 """Test CC info not offered to be saved when autocomplete=off for CC field.
194 316
195 If the credit card number field has autocomplete turned off, then the credit 317 If the credit card number field has autocomplete turned off, then the credit
196 card infobar should not offer to save the credit card info. The credit card 318 card infobar should not offer to save the credit card info. The credit card
197 number must be a valid Luhn number. 319 number must be a valid Luhn number.
198 """ 320 """
199 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith', 321 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith',
200 'CREDIT_CARD_NUMBER': '4408041234567893', 322 'CREDIT_CARD_NUMBER': '4408041234567893',
(...skipping 12 matching lines...) Expand all
213 window.addEventListener("unload", function() { 335 window.addEventListener("unload", function() {
214 window.domAutomationController.send("done"); 336 window.domAutomationController.send("done");
215 }); 337 });
216 """ 338 """
217 self.ExecuteJavascript(js_code, 0, 0) 339 self.ExecuteJavascript(js_code, 0, 0)
218 # Wait until form is submitted and page completes loading. 340 # Wait until form is submitted and page completes loading.
219 self.WaitUntil( 341 self.WaitUntil(
220 lambda: self.GetDOMValue('document.readyState'), 342 lambda: self.GetDOMValue('document.readyState'),
221 expect_retval='complete') 343 expect_retval='complete')
222 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] 344 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']
223 self.assertEqual(0, len(cc_infobar), 345 self.assertFalse(cc_infobar,
224 'Save credit card infobar offered to save CC info.') 346 msg='Save credit card infobar offered to save CC info.')
225 347
226 def testNoAutofillForReadOnlyFields(self): 348 def testNoAutofillForReadOnlyFields(self):
227 """Test that Autofill does not fill in read-only fields.""" 349 """Test that Autofill does not fill in read-only fields."""
228 profile = {'NAME_FIRST': 'Bob', 350 profile = {'NAME_FIRST': 'Bob',
229 'NAME_LAST': 'Smith', 351 'NAME_LAST': 'Smith',
230 'EMAIL_ADDRESS': 'bsmith@gmail.com', 352 'EMAIL_ADDRESS': 'bsmith@gmail.com',
231 'ADDRESS_HOME_LINE1': '1234 H St.', 353 'ADDRESS_HOME_LINE1': '1234 H St.',
232 'ADDRESS_HOME_CITY': 'San Jose', 354 'ADDRESS_HOME_CITY': 'San Jose',
233 'ADDRESS_HOME_STATE': 'CA', 355 'ADDRESS_HOME_STATE': 'CA',
234 'ADDRESS_HOME_ZIP': '95110', 356 'ADDRESS_HOME_ZIP': '95110',
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 merged_profile = os.path.join(self.DataDir(), 'autofill', 477 merged_profile = os.path.join(self.DataDir(), 'autofill',
356 'merged-profiles.txt') 478 'merged-profiles.txt')
357 profile_dict = self.GetAutofillProfile()['profiles'] 479 profile_dict = self.GetAutofillProfile()['profiles']
358 output = open(merged_profile, 'wb') 480 output = open(merged_profile, 'wb')
359 pickle.dump(profile_dict, output) 481 pickle.dump(profile_dict, output)
360 output.close() 482 output.close()
361 483
362 484
363 if __name__ == '__main__': 485 if __name__ == '__main__':
364 pyauto_functional.Main() 486 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698