Chromium Code Reviews| 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 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 expected_credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'} | |
|
dennis_jeffrey
2011/04/14 21:53:03
Since "credit_card" is identical to "expected_cred
dyu1
2011/04/15 00:06:09
Done.
| |
| 97 self.FillAutofillProfile(credit_cards=[credit_card]) | |
| 98 self.assertEqual([expected_credit_card], | |
| 99 self.GetAutofillProfile()['credit_cards'], | |
| 100 msg='Credit card number in prefs not saved as-is.') | |
|
dennis_jeffrey
2011/04/14 21:53:03
Indent by 1 fewer space.
dyu1
2011/04/15 00:06:09
Done.
| |
| 101 | |
| 102 def testInvalidCreditCardNumberIsNotAggregated(self): | |
| 103 """Test credit card info with an invalid cc number is not aggregated. | |
|
dennis_jeffrey
2011/04/14 21:53:03
Remove "cc"; I think it's already implied within t
dyu1
2011/04/15 00:06:09
Done.
| |
| 104 | |
| 105 When filling out a form with an invalid CC number, one that does not pass | |
|
dennis_jeffrey
2011/04/14 21:53:03
"cc" --> "credit card" (for clarity).
dyu1
2011/04/15 00:06:09
Done.
| |
| 106 the Luhn test, the credit card info is not saved into Autofill preferences. | |
|
dennis_jeffrey
2011/04/14 21:53:03
Instead of using commas around "one that does not
dennis_jeffrey
2011/04/14 21:53:03
"is not saved" --> "should not be saved"
dyu1
2011/04/15 00:06:09
Done.
dyu1
2011/04/15 00:06:09
Done.
| |
| 107 """ | |
| 108 invalid_cc_info = {'CREDIT_CARD_NAME': 'Bob Smith', | |
| 109 'CREDIT_CARD_NUMBER': '4408 0412 3456 7890', | |
|
dennis_jeffrey
2011/04/14 21:53:03
Would it be easy to add a brief comment to explain
dyu1
2011/04/15 00:06:09
I added a helper function instead to do the checki
| |
| 110 'CREDIT_CARD_EXP_MONTH': '12', | |
| 111 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2014'} | |
| 112 url = self.GetHttpURLForDataPath( | |
| 113 os.path.join('autofill', 'autofill_creditcard_form.html')) | |
| 114 self.NavigateToURL(url) | |
| 115 for key, value in invalid_cc_info.iteritems(): | |
| 116 script = ('document.getElementById("%s").value = "%s"; ' | |
| 117 'window.domAutomationController.send("done");') % (key, value) | |
| 118 self.ExecuteJavascript(script, 0, 0) | |
| 119 js_code = """ | |
| 120 document.getElementById("cc_submit").submit(); | |
| 121 window.addEventListener("unload", function() { | |
| 122 window.domAutomationController.send("done"); | |
| 123 }); | |
| 124 """ | |
| 125 self.ExecuteJavascript(js_code, 0, 0) | |
| 126 # Wait until form is submitted and page completes loading. | |
|
dennis_jeffrey
2011/04/14 21:53:03
"form" --> "the form"
"page" --> "the page"
dyu1
2011/04/15 00:06:09
Done.
| |
| 127 self.WaitUntil( | |
| 128 lambda: self.GetDOMValue('document.readyState'), | |
| 129 expect_retval='complete') | |
| 130 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | |
| 131 self.assertFalse(cc_infobar, | |
| 132 msg='Save credit card infobar offered to save CC info.') | |
| 133 | |
| 134 def testWhiteSpacesStrippedForValidCCNums(self): | |
| 135 """Test whitespaces are stripped for valid CC numbers. | |
|
dennis_jeffrey
2011/04/14 21:53:03
"CC" --> "credit card"
dyu1
2011/04/15 00:06:09
Done.
| |
| 136 | |
| 137 Credit Card Number entered must pass the Luhn test. For reference: | |
|
dennis_jeffrey
2011/04/14 21:53:03
"The credit card number used in this test passes t
dyu1
2011/04/15 00:06:09
Done.
| |
| 138 http://www.merriampark.com/anatomycc.htm | |
| 139 """ | |
| 140 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith', | |
| 141 'CREDIT_CARD_NUMBER': '4408 0412 3456 7893', | |
| 142 'CREDIT_CARD_EXP_MONTH': '12', | |
| 143 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2014'} | |
| 144 | |
| 145 url = self.GetHttpURLForDataPath( | |
| 146 os.path.join('autofill', 'autofill_creditcard_form.html')) | |
| 147 self.NavigateToURL(url) | |
| 148 for key, value in credit_card_info.iteritems() : | |
|
dennis_jeffrey
2011/04/14 21:53:03
Remove the space before the ':'
dyu1
2011/04/15 00:06:09
Done.
| |
| 149 script = ('document.getElementById("%s").value = "%s"; ' | |
| 150 'window.domAutomationController.send("done");') % (key, value) | |
| 151 self.ExecuteJavascript(script, 0, 0) | |
| 152 js_code = """ | |
| 153 document.getElementById("cc_submit").submit(); | |
| 154 window.addEventListener("unload", function() { | |
| 155 window.domAutomationController.send("done"); | |
| 156 }); | |
| 157 """ | |
| 158 self.ExecuteJavascript(js_code, 0, 0) | |
| 159 # Wait until form is submitted and page completes loading. | |
|
dennis_jeffrey
2011/04/14 21:53:03
"form" --> "the form"
"page" --> "the page"
dyu1
2011/04/15 00:06:09
Done.
| |
| 160 self.WaitUntil( | |
| 161 lambda: self.GetDOMValue('document.readyState'), | |
| 162 expect_retval='complete') | |
| 163 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | |
| 164 self.PerformActionOnInfobar('accept', infobar_index=0) | |
| 165 cc_expected = credit_card_info['CREDIT_CARD_NUMBER'].replace(' ', '') | |
| 166 self.assertEqual( | |
| 167 cc_expected, | |
| 168 self.GetAutofillProfile()['credit_cards'][0]['CREDIT_CARD_NUMBER'], | |
| 169 msg='White spaces not stripped from a valid cc number.') | |
|
dennis_jeffrey
2011/04/14 21:53:03
"White spaces" --> "Whitespaces"
dyu1
2011/04/15 00:06:09
Done.
| |
| 170 | |
| 171 def testCharSeparatorsStrippedForValidCCNums(self): | |
| 172 """Test char seperators are stripped for valid CC numbers. | |
|
dennis_jeffrey
2011/04/14 21:53:03
"seperators" --> "separators"
dennis_jeffrey
2011/04/14 21:53:03
"CC" --> "credit card"
dyu1
2011/04/15 00:06:09
Done.
dyu1
2011/04/15 00:06:09
Done.
| |
| 173 | |
| 174 Credit Card Number entered must pass the Luhn test. For reference: | |
|
dennis_jeffrey
2011/04/14 21:53:03
Same comment as line 137 above.
dyu1
2011/04/15 00:06:09
Done.
| |
| 175 http://www.merriampark.com/anatomycc.htm | |
| 176 """ | |
| 177 credit_card_info = {'CREDIT_CARD_NAME': 'Jane Doe', | |
| 178 'CREDIT_CARD_NUMBER': '4417-1234-5678-9112', | |
| 179 'CREDIT_CARD_EXP_MONTH': '10', | |
| 180 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2013'} | |
| 181 | |
| 182 url = self.GetHttpURLForDataPath( | |
| 183 os.path.join('autofill', 'autofill_creditcard_form.html')) | |
| 184 self.NavigateToURL(url) | |
| 185 for key, value in credit_card_info.iteritems() : | |
|
dennis_jeffrey
2011/04/14 21:53:03
Remove space before ':'
dyu1
2011/04/15 00:06:09
Done.
| |
| 186 script = ('document.getElementById("%s").value = "%s"; ' | |
| 187 'window.domAutomationController.send("done");') % (key, value) | |
| 188 self.ExecuteJavascript(script, 0, 0) | |
| 189 js_code = """ | |
| 190 document.getElementById("cc_submit").submit(); | |
| 191 window.addEventListener("unload", function() { | |
| 192 window.domAutomationController.send("done"); | |
| 193 }); | |
| 194 """ | |
| 195 self.ExecuteJavascript(js_code, 0, 0) | |
| 196 # Wait until form is submitted and page completes loading. | |
|
dennis_jeffrey
2011/04/14 21:53:03
"form" --> "the form"
"page" --> "the page"
dyu1
2011/04/15 00:06:09
Done.
| |
| 197 self.WaitUntil( | |
| 198 lambda: self.GetDOMValue('document.readyState'), | |
| 199 expect_retval='complete') | |
| 200 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | |
| 201 self.PerformActionOnInfobar('accept', infobar_index=0) | |
| 202 cc_expected = credit_card_info['CREDIT_CARD_NUMBER'].replace('-', '') | |
| 203 self.assertEqual( | |
| 204 cc_expected, | |
| 205 self.GetAutofillProfile()['credit_cards'][0]['CREDIT_CARD_NUMBER'], | |
| 206 msg='Character separators not stripped from a valid cc number.') | |
| 207 | |
| 208 def testProfilesNotAggregatedWithNoAddress(self): | |
| 209 """Test Autofill does not aggregate profiles with no address info.""" | |
| 95 profile = {'NAME_FIRST': 'Bob', | 210 profile = {'NAME_FIRST': 'Bob', |
| 96 'NAME_LAST': 'Smith', | 211 'NAME_LAST': 'Smith', |
| 97 'EMAIL_ADDRESS': 'bsmith@example.com', | 212 'EMAIL_ADDRESS': 'bsmith@example.com', |
| 98 'COMPANY_NAME': 'Company X', | 213 'COMPANY_NAME': 'Company X', |
| 99 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} | 214 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} |
| 100 url = self.GetHttpURLForDataPath( | 215 url = self.GetHttpURLForDataPath( |
| 101 os.path.join('autofill', 'duplicate_profiles_test.html')) | 216 os.path.join('autofill', 'duplicate_profiles_test.html')) |
| 102 self.NavigateToURL(url) | 217 self.NavigateToURL(url) |
| 103 for key, value in profile.iteritems(): | 218 for key, value in profile.iteritems(): |
| 104 script = ('document.getElementById("%s").value = "%s"; ' | 219 script = ('document.getElementById("%s").value = "%s"; ' |
| 105 'window.domAutomationController.send("done");') % (key, value) | 220 'window.domAutomationController.send("done");') % (key, value) |
| 106 self.ExecuteJavascript(script, 0, 0) | 221 self.ExecuteJavascript(script, 0, 0) |
| 107 js_code = """ | 222 js_code = """ |
| 108 document.getElementById("merge_dup").submit(); | 223 document.getElementById("merge_dup").submit(); |
| 109 window.addEventListener("unload", function() { | 224 window.addEventListener("unload", function() { |
| 110 window.domAutomationController.send("done"); | 225 window.domAutomationController.send("done"); |
| 111 }); | 226 }); |
| 112 """ | 227 """ |
| 113 self.ExecuteJavascript(js_code, 0, 0) | 228 self.ExecuteJavascript(js_code, 0, 0) |
| 114 self.assertEqual([], self.GetAutofillProfile()['profiles']) | 229 self.assertEqual([], self.GetAutofillProfile()['profiles']) |
|
dennis_jeffrey
2011/04/14 21:53:03
Add a msg='...' in case this assertion fails.
dyu1
2011/04/15 00:06:09
Done.
| |
| 115 | 230 |
| 116 def testFilterMalformedEmailAddresses(self): | 231 def testProfilesNotAggregatedWithInvalidEmail(self): |
| 117 """Test Autofill filters out malformed email address during form submit.""" | 232 """Test Autofill does not aggregate profiles with an invalid Email.""" |
|
dennis_jeffrey
2011/04/14 21:53:03
"Email" --> "email"
dyu1
2011/04/15 00:06:09
Done.
| |
| 118 profile = {'NAME_FIRST': 'Bob', | 233 profile = {'NAME_FIRST': 'Bob', |
| 119 'NAME_LAST': 'Smith', | 234 'NAME_LAST': 'Smith', |
| 120 'EMAIL_ADDRESS': 'garbage', | 235 'EMAIL_ADDRESS': 'garbage', |
| 121 'ADDRESS_HOME_LINE1': '1234 H St.', | 236 'ADDRESS_HOME_LINE1': '1234 H St.', |
| 122 'ADDRESS_HOME_CITY': 'San Jose', | 237 'ADDRESS_HOME_CITY': 'San Jose', |
| 123 'ADDRESS_HOME_STATE': 'CA', | 238 'ADDRESS_HOME_STATE': 'CA', |
| 124 'ADDRESS_HOME_ZIP': '95110', | 239 'ADDRESS_HOME_ZIP': '95110', |
| 125 'COMPANY_NAME': 'Company X', | 240 'COMPANY_NAME': 'Company X', |
| 126 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} | 241 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} |
| 127 url = self.GetHttpURLForDataPath( | 242 url = self.GetHttpURLForDataPath( |
| 128 os.path.join('autofill', 'duplicate_profiles_test.html')) | 243 os.path.join('autofill', 'duplicate_profiles_test.html')) |
| 129 self.NavigateToURL(url) | 244 self.NavigateToURL(url) |
| 130 for key, value in profile.iteritems(): | 245 for key, value in profile.iteritems(): |
| 131 script = ('document.getElementById("%s").value = "%s"; ' | 246 script = ('document.getElementById("%s").value = "%s"; ' |
| 132 'window.domAutomationController.send("done");') % (key, value) | 247 'window.domAutomationController.send("done");') % (key, value) |
| 133 self.ExecuteJavascript(script, 0, 0) | 248 self.ExecuteJavascript(script, 0, 0) |
| 134 js_code = """ | 249 js_code = """ |
| 135 document.getElementById("merge_dup").submit(); | 250 document.getElementById("merge_dup").submit(); |
| 136 window.addEventListener("unload", function() { | 251 window.addEventListener("unload", function() { |
| 137 window.domAutomationController.send("done"); | 252 window.domAutomationController.send("done"); |
| 138 }); | 253 }); |
| 139 """ | 254 """ |
| 140 self.ExecuteJavascript(js_code, 0, 0) | 255 self.ExecuteJavascript(js_code, 0, 0) |
| 141 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: | 256 self.assertEqual([], self.GetAutofillProfile()['profiles']) |
|
dennis_jeffrey
2011/04/14 21:53:03
Add a msg='...' in case this assertion fails.
dyu1
2011/04/15 00:06:09
Done.
| |
| 142 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | |
| 143 | 257 |
| 144 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0): | 258 def _SendKeyEventsToPopulateForm(self, tab_index=0, windex=0): |
| 145 """Send key events to populate a web form with Autofill profile data. | 259 """Send key events to populate a web form with Autofill profile data. |
| 146 | 260 |
| 147 Args: | 261 Args: |
| 148 tab_index: The tab index, default is 0. | 262 tab_index: The tab index, default is 0. |
| 149 windex: The window index, default is 0. | 263 windex: The window index, default is 0. |
| 150 """ | 264 """ |
| 151 TAB_KEYPRESS = 0x09 # Tab keyboard key press. | 265 TAB_KEYPRESS = 0x09 # Tab keyboard key press. |
| 152 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. | 266 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 179 form_values = {} | 293 form_values = {} |
| 180 for key, value in profile_expected.iteritems(): | 294 for key, value in profile_expected.iteritems(): |
| 181 js_returning_field_value = ( | 295 js_returning_field_value = ( |
| 182 'var field_value = document.getElementById("%s").value;' | 296 'var field_value = document.getElementById("%s").value;' |
| 183 'window.domAutomationController.send(field_value);' | 297 'window.domAutomationController.send(field_value);' |
| 184 ) % key | 298 ) % key |
| 185 form_values[key] = self.ExecuteJavascript( | 299 form_values[key] = self.ExecuteJavascript( |
| 186 js_returning_field_value, 0, 0) | 300 js_returning_field_value, 0, 0) |
| 187 self.assertEqual( | 301 self.assertEqual( |
| 188 form_values[key], value, | 302 form_values[key], value, |
| 189 ('Original profile not equal to expected profile at key: "%s"\n' | 303 msg=('Original profile not equal to expected profile at key: "%s"\n' |
| 190 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) | 304 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) |
|
dennis_jeffrey
2011/04/14 21:53:03
Indent this line 4 more spaces.
dyu1
2011/04/15 00:06:09
Done.
| |
| 191 | 305 |
| 192 def testCCInfoNotStoredWhenAutocompleteOff(self): | 306 def testCCInfoNotStoredWhenAutocompleteOff(self): |
| 193 """Test CC info not offered to be saved when autocomplete=off for CC field. | 307 """Test CC info not offered to be saved when autocomplete=off for CC field. |
| 194 | 308 |
| 195 If the credit card number field has autocomplete turned off, then the credit | 309 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 | 310 card infobar should not offer to save the credit card info. The credit card |
| 197 number must be a valid Luhn number. | 311 number must be a valid Luhn number. |
| 198 """ | 312 """ |
| 199 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith', | 313 credit_card_info = {'CREDIT_CARD_NAME': 'Bob Smith', |
| 200 'CREDIT_CARD_NUMBER': '4408041234567893', | 314 'CREDIT_CARD_NUMBER': '4408041234567893', |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 213 window.addEventListener("unload", function() { | 327 window.addEventListener("unload", function() { |
| 214 window.domAutomationController.send("done"); | 328 window.domAutomationController.send("done"); |
| 215 }); | 329 }); |
| 216 """ | 330 """ |
| 217 self.ExecuteJavascript(js_code, 0, 0) | 331 self.ExecuteJavascript(js_code, 0, 0) |
| 218 # Wait until form is submitted and page completes loading. | 332 # Wait until form is submitted and page completes loading. |
| 219 self.WaitUntil( | 333 self.WaitUntil( |
| 220 lambda: self.GetDOMValue('document.readyState'), | 334 lambda: self.GetDOMValue('document.readyState'), |
| 221 expect_retval='complete') | 335 expect_retval='complete') |
| 222 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | 336 cc_infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] |
| 223 self.assertEqual(0, len(cc_infobar), | 337 self.assertFalse(cc_infobar, |
| 224 'Save credit card infobar offered to save CC info.') | 338 msg='Save credit card infobar offered to save CC info.') |
| 225 | 339 |
| 226 def testNoAutofillForReadOnlyFields(self): | 340 def testNoAutofillForReadOnlyFields(self): |
| 227 """Test that Autofill does not fill in read-only fields.""" | 341 """Test that Autofill does not fill in read-only fields.""" |
| 228 profile = {'NAME_FIRST': 'Bob', | 342 profile = {'NAME_FIRST': 'Bob', |
| 229 'NAME_LAST': 'Smith', | 343 'NAME_LAST': 'Smith', |
| 230 'EMAIL_ADDRESS': 'bsmith@gmail.com', | 344 'EMAIL_ADDRESS': 'bsmith@gmail.com', |
| 231 'ADDRESS_HOME_LINE1': '1234 H St.', | 345 'ADDRESS_HOME_LINE1': '1234 H St.', |
| 232 'ADDRESS_HOME_CITY': 'San Jose', | 346 'ADDRESS_HOME_CITY': 'San Jose', |
| 233 'ADDRESS_HOME_STATE': 'CA', | 347 'ADDRESS_HOME_STATE': 'CA', |
| 234 'ADDRESS_HOME_ZIP': '95110', | 348 'ADDRESS_HOME_ZIP': '95110', |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 merged_profile = os.path.join(self.DataDir(), 'autofill', | 469 merged_profile = os.path.join(self.DataDir(), 'autofill', |
| 356 'merged-profiles.txt') | 470 'merged-profiles.txt') |
| 357 profile_dict = self.GetAutofillProfile()['profiles'] | 471 profile_dict = self.GetAutofillProfile()['profiles'] |
| 358 output = open(merged_profile, 'wb') | 472 output = open(merged_profile, 'wb') |
| 359 pickle.dump(profile_dict, output) | 473 pickle.dump(profile_dict, output) |
| 360 output.close() | 474 output.close() |
| 361 | 475 |
| 362 | 476 |
| 363 if __name__ == '__main__': | 477 if __name__ == '__main__': |
| 364 pyauto_functional.Main() | 478 pyauto_functional.Main() |
| OLD | NEW |