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

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 os 7 import os
8 import pickle 8 import pickle
9 9
10 import autofill_dataset_converter 10 import autofill_dataset_converter
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 'ADDRESS_HOME_ZIP': 'my_zip', 83 'ADDRESS_HOME_ZIP': 'my_zip',
84 'ADDRESS_HOME_COUNTRY': 'United States'} 84 'ADDRESS_HOME_COUNTRY': 'United States'}
85 # Add some invalid fields. 85 # Add some invalid fields.
86 with_invalid = without_invalid.copy() 86 with_invalid = without_invalid.copy()
87 with_invalid['PHONE_HOME_WHOLE_NUMBER'] = 'Invalid_Phone_Number' 87 with_invalid['PHONE_HOME_WHOLE_NUMBER'] = 'Invalid_Phone_Number'
88 with_invalid['PHONE_FAX_WHOLE_NUMBER'] = 'Invalid_Fax_Number' 88 with_invalid['PHONE_FAX_WHOLE_NUMBER'] = 'Invalid_Fax_Number'
89 self.FillAutofillProfile(profiles=[with_invalid]) 89 self.FillAutofillProfile(profiles=[with_invalid])
90 self.assertEqual([without_invalid], 90 self.assertEqual([without_invalid],
91 self.GetAutofillProfile()['profiles']) 91 self.GetAutofillProfile()['profiles'])
92 92
93 def testFilterIncompleteAddresses(self): 93 def testAutofillPrefsStringSavedAsIs(self):
94 """Test Autofill filters out profile with incomplete address info.""" 94 """Test invalid credit card numbers typed in prefs should be saved as-is."""
95 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'}
96 self.FillAutofillProfile(credit_cards=[credit_card])
97 self.assertEqual([credit_card],
98 self.GetAutofillProfile()['credit_cards'],
99 msg='Credit card number in prefs not saved as-is.')
100
101 def _LuhnCreditCardNumberValidator(self, number):
102 """Validates whether a number is valid or invalid using the Luhn test.
103
104 Validation steps:
105 1. Reverse the order of the digits in the number.
106 2. Take the first, third, and every other odd digit and sum them up to
107 form sum s1.
108 3. Take the second, fourth, and every even digit, multiply each digit by
109 two and sum the digits if the answer is greater than nine.
110 4. Sum the partial sums of the even digits to form s2.
111 5. If s1 + s2 ends in zero then the number is valid.
112
113 Args:
114 number: the credit card number being validated.
Nirnimesh 2011/04/15 05:29:45 Add: "as a string"
dyu1 2011/04/15 21:43:51 Done.
115
116 Return:
117 boolean whether the credit card number is true or false.
118 """
119 reverse = [int(ch) for ch in str(number)][::-1]
120 # The divmod of the function splits a number into two digits, ready for
121 # summing.
122 return ((
Nirnimesh 2011/04/15 05:29:45 you don't really need 3 lines here.
dyu1 2011/04/15 21:43:51 Done.
123 sum(reverse[0::2]) + sum(sum(divmod(d*2, 10)) for d in reverse[1::2])) %
124 10 == 0)
125
126 def testInvalidCreditCardNumberIsNotAggregated(self):
127 """Test credit card info with an invalid number is not aggregated.
128
129 When filling out a form with an invalid credit card number (one that
130 does not pass the Luhn test) the credit card info should not be saved into
131 Autofill preferences.
132 """
133 invalid_cc_info = {'CREDIT_CARD_NAME': 'Bob Smith',
134 'CREDIT_CARD_NUMBER': '4408 0412 3456 7890',
135 'CREDIT_CARD_EXP_MONTH': '12',
136 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2014'}
137
138 # Strip the white spaces from the number.
139 cc_number = invalid_cc_info['CREDIT_CARD_NUMBER'].replace(' ', '')
140 if self._LuhnCreditCardNumberValidator(cc_number) == False:
Nirnimesh 2011/04/15 05:29:45 Don't do an if. Do an assert.
dyu1 2011/04/15 21:43:51 Done.
141 url = self.GetHttpURLForDataPath(
142 os.path.join('autofill', 'autofill_creditcard_form.html'))
143 self.NavigateToURL(url)
144 for key, value in invalid_cc_info.iteritems():
145 script = ('document.getElementById("%s").value = "%s"; '
146 'window.domAutomationController.send("done");') % (key, value)
147 self.ExecuteJavascript(script, 0, 0)
148 js_code = """
149 document.getElementById("cc_submit").submit();
150 window.addEventListener("unload", function() {
151 window.domAutomationController.send("done");
152 });
153 """
154 self.ExecuteJavascript(js_code, 0, 0)
155 # Wait until the form is submitted and the page completes loading.
156 self.WaitUntil(
157 lambda: self.GetDOMValue('document.readyState'),
158 expect_retval='complete')
159 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']
160 self.assertFalse(
161 cc_infobar, msg='Save credit card infobar offered to save CC info.')
162 else:
Nirnimesh 2011/04/15 05:29:45 remove the else
dyu1 2011/04/15 21:43:51 Done.
163 raise Error('This test requires an invalid credit card number.')
164
165 def testWhitespacesAndSeparatorCharsStrippedForValidCCNums(self):
166 """Test whitespaces and separator chars are stripped for valid CC numbers.
167
168 The credit card number used in this test passes 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 self.NavigateToURL(url)
184 for key, value in cc_info.iteritems():
185 script = ('document.getElementById("%s").value = "%s"; '
186 'window.domAutomationController.send("done");') % (key, value)
187 self.ExecuteJavascript(script, 0, 0)
188 js_code = """
189 document.getElementById("cc_submit").submit();
190 window.addEventListener("unload", function() {
191 window.domAutomationController.send("done");
192 });
193 """
194 self.ExecuteJavascript(js_code, 0, 0)
195 # Wait until form is submitted and page completes loading.
196 self.WaitUntil(
197 lambda: self.GetDOMValue('document.readyState'),
198 expect_retval='complete')
199 self.PerformActionOnInfobar('accept', infobar_index=0)
200
201 # Verify the filled in credit card number against the aggregated number.
202 aggregated_cc_1 = (
203 self.GetAutofillProfile()['credit_cards'][0]['CREDIT_CARD_NUMBER'])
204 aggregated_cc_2 = (
205 self.GetAutofillProfile()['credit_cards'][1]['CREDIT_CARD_NUMBER'])
206 print aggregated_cc_1
Nirnimesh 2011/04/15 05:29:45 why print?
dyu1 2011/04/15 21:43:51 Forgot to remove this while I was debugging.
207 if (' ' in aggregated_cc_1 or ' ' in aggregated_cc_2 or '-' in
208 aggregated_cc_1 or '-' in aggregated_cc_2):
209 print 'Whitespaces or separator chars not stripped.'
Nirnimesh 2011/04/15 05:29:45 why print? why not assert?
dyu1 2011/04/15 21:43:51 Done.
210
211 def testProfilesNotAggregatedWithNoAddress(self):
212 """Test Autofill does not aggregate profiles with no address info."""
95 profile = {'NAME_FIRST': 'Bob', 213 profile = {'NAME_FIRST': 'Bob',
96 'NAME_LAST': 'Smith', 214 'NAME_LAST': 'Smith',
97 'EMAIL_ADDRESS': 'bsmith@example.com', 215 'EMAIL_ADDRESS': 'bsmith@example.com',
98 'COMPANY_NAME': 'Company X', 216 'COMPANY_NAME': 'Company X',
99 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} 217 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',}
100 url = self.GetHttpURLForDataPath( 218 url = self.GetHttpURLForDataPath(
101 os.path.join('autofill', 'duplicate_profiles_test.html')) 219 os.path.join('autofill', 'duplicate_profiles_test.html'))
102 self.NavigateToURL(url) 220 self.NavigateToURL(url)
103 for key, value in profile.iteritems(): 221 for key, value in profile.iteritems():
104 script = ('document.getElementById("%s").value = "%s"; ' 222 script = ('document.getElementById("%s").value = "%s"; '
105 'window.domAutomationController.send("done");') % (key, value) 223 'window.domAutomationController.send("done");') % (key, value)
106 self.ExecuteJavascript(script, 0, 0) 224 self.ExecuteJavascript(script, 0, 0)
107 js_code = """ 225 js_code = """
108 document.getElementById("merge_dup").submit(); 226 document.getElementById("merge_dup").submit();
109 window.addEventListener("unload", function() { 227 window.addEventListener("unload", function() {
110 window.domAutomationController.send("done"); 228 window.domAutomationController.send("done");
111 }); 229 });
112 """ 230 """
113 self.ExecuteJavascript(js_code, 0, 0) 231 self.ExecuteJavascript(js_code, 0, 0)
114 self.assertEqual([], self.GetAutofillProfile()['profiles']) 232 self.assertEqual([], self.GetAutofillProfile()['profiles'],
233 msg='Profile with no address info was aggregated.')
115 234
116 def testFilterMalformedEmailAddresses(self): 235 def testProfilesNotAggregatedWithInvalidEmail(self):
117 """Test Autofill filters out malformed email address during form submit.""" 236 """Test Autofill does not aggregate profiles with an invalid email."""
118 profile = {'NAME_FIRST': 'Bob', 237 profile = {'NAME_FIRST': 'Bob',
119 'NAME_LAST': 'Smith', 238 'NAME_LAST': 'Smith',
120 'EMAIL_ADDRESS': 'garbage', 239 'EMAIL_ADDRESS': 'garbage',
121 'ADDRESS_HOME_LINE1': '1234 H St.', 240 'ADDRESS_HOME_LINE1': '1234 H St.',
122 'ADDRESS_HOME_CITY': 'San Jose', 241 'ADDRESS_HOME_CITY': 'San Jose',
123 'ADDRESS_HOME_STATE': 'CA', 242 'ADDRESS_HOME_STATE': 'CA',
124 'ADDRESS_HOME_ZIP': '95110', 243 'ADDRESS_HOME_ZIP': '95110',
125 'COMPANY_NAME': 'Company X', 244 'COMPANY_NAME': 'Company X',
126 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} 245 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',}
127 url = self.GetHttpURLForDataPath( 246 url = self.GetHttpURLForDataPath(
128 os.path.join('autofill', 'duplicate_profiles_test.html')) 247 os.path.join('autofill', 'duplicate_profiles_test.html'))
129 self.NavigateToURL(url) 248 self.NavigateToURL(url)
130 for key, value in profile.iteritems(): 249 for key, value in profile.iteritems():
131 script = ('document.getElementById("%s").value = "%s"; ' 250 script = ('document.getElementById("%s").value = "%s"; '
132 'window.domAutomationController.send("done");') % (key, value) 251 'window.domAutomationController.send("done");') % (key, value)
133 self.ExecuteJavascript(script, 0, 0) 252 self.ExecuteJavascript(script, 0, 0)
134 js_code = """ 253 js_code = """
135 document.getElementById("merge_dup").submit(); 254 document.getElementById("merge_dup").submit();
136 window.addEventListener("unload", function() { 255 window.addEventListener("unload", function() {
137 window.domAutomationController.send("done"); 256 window.domAutomationController.send("done");
138 }); 257 });
139 """ 258 """
140 self.ExecuteJavascript(js_code, 0, 0) 259 self.ExecuteJavascript(js_code, 0, 0)
141 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: 260 self.assertEqual([], self.GetAutofillProfile()['profiles'],
Nirnimesh 2011/04/15 05:29:45 use assertFalse
dyu1 2011/04/15 21:47:40 Done.
142 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') 261 msg='Profile with invalid email was aggregated.')
143 262
144 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0): 263 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0):
145 """Send key events to populate a web form with Autofill profile data. 264 """Send key events to populate a web form with Autofill profile data.
146 265
147 Args: 266 Args:
148 tab_index: The tab index, default is 0. 267 tab_index: The tab index, default is 0.
149 windex: The window index, default is 0. 268 windex: The window index, default is 0.
150 """ 269 """
151 TAB_KEYPRESS = 0x09 # Tab keyboard key press. 270 TAB_KEYPRESS = 0x09 # Tab keyboard key press.
152 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. 271 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press.
(...skipping 26 matching lines...) Expand all
179 form_values = {} 298 form_values = {}
180 for key, value in profile_expected.iteritems(): 299 for key, value in profile_expected.iteritems():
181 js_returning_field_value = ( 300 js_returning_field_value = (
182 'var field_value = document.getElementById("%s").value;' 301 'var field_value = document.getElementById("%s").value;'
183 'window.domAutomationController.send(field_value);' 302 'window.domAutomationController.send(field_value);'
184 ) % key 303 ) % key
185 form_values[key] = self.ExecuteJavascript( 304 form_values[key] = self.ExecuteJavascript(
186 js_returning_field_value, 0, 0) 305 js_returning_field_value, 0, 0)
187 self.assertEqual( 306 self.assertEqual(
188 form_values[key], value, 307 form_values[key], value,
189 ('Original profile not equal to expected profile at key: "%s"\n' 308 msg=('Original profile not equal to expected profile at key: "%s"\n'
190 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) 309 'Expected: "%s"\nReturned: "%s"' % (
310 key, value, form_values[key])))
191 311
192 def testCCInfoNotStoredWhenAutocompleteOff(self): 312 def testCCInfoNotStoredWhenAutocompleteOff(self):
193 """Test CC info not offered to be saved when autocomplete=off for CC field. 313 """Test CC info not offered to be saved when autocomplete=off for CC field.
194 314
195 If the credit card number field has autocomplete turned off, then the credit 315 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 316 card infobar should not offer to save the credit card info. The credit card
197 number must be a valid Luhn number. 317 number must be a valid Luhn number.
198 """ 318 """
199 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith', 319 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith',
200 'CREDIT_CARD_NUMBER': '4408041234567893', 320 'CREDIT_CARD_NUMBER': '4408041234567893',
(...skipping 12 matching lines...) Expand all
213 window.addEventListener("unload", function() { 333 window.addEventListener("unload", function() {
214 window.domAutomationController.send("done"); 334 window.domAutomationController.send("done");
215 }); 335 });
216 """ 336 """
217 self.ExecuteJavascript(js_code, 0, 0) 337 self.ExecuteJavascript(js_code, 0, 0)
218 # Wait until form is submitted and page completes loading. 338 # Wait until form is submitted and page completes loading.
219 self.WaitUntil( 339 self.WaitUntil(
220 lambda: self.GetDOMValue('document.readyState'), 340 lambda: self.GetDOMValue('document.readyState'),
221 expect_retval='complete') 341 expect_retval='complete')
222 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] 342 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']
223 self.assertEqual(0, len(cc_infobar), 343 self.assertFalse(cc_infobar,
224 'Save credit card infobar offered to save CC info.') 344 msg='Save credit card infobar offered to save CC info.')
225 345
226 def testNoAutofillForReadOnlyFields(self): 346 def testNoAutofillForReadOnlyFields(self):
227 """Test that Autofill does not fill in read-only fields.""" 347 """Test that Autofill does not fill in read-only fields."""
228 profile = {'NAME_FIRST': 'Bob', 348 profile = {'NAME_FIRST': 'Bob',
229 'NAME_LAST': 'Smith', 349 'NAME_LAST': 'Smith',
230 'EMAIL_ADDRESS': 'bsmith@gmail.com', 350 'EMAIL_ADDRESS': 'bsmith@gmail.com',
231 'ADDRESS_HOME_LINE1': '1234 H St.', 351 'ADDRESS_HOME_LINE1': '1234 H St.',
232 'ADDRESS_HOME_CITY': 'San Jose', 352 'ADDRESS_HOME_CITY': 'San Jose',
233 'ADDRESS_HOME_STATE': 'CA', 353 'ADDRESS_HOME_STATE': 'CA',
234 'ADDRESS_HOME_ZIP': '95110', 354 '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', 475 merged_profile = os.path.join(self.DataDir(), 'autofill',
356 'merged-profiles.txt') 476 'merged-profiles.txt')
357 profile_dict = self.GetAutofillProfile()['profiles'] 477 profile_dict = self.GetAutofillProfile()['profiles']
358 output = open(merged_profile, 'wb') 478 output = open(merged_profile, 'wb')
359 pickle.dump(profile_dict, output) 479 pickle.dump(profile_dict, output)
360 output.close() 480 output.close()
361 481
362 482
363 if __name__ == '__main__': 483 if __name__ == '__main__':
364 pyauto_functional.Main() 484 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