Chromium Code Reviews| Index: chrome/test/functional/autofill.py |
| =================================================================== |
| --- chrome/test/functional/autofill.py (revision 75062) |
| +++ chrome/test/functional/autofill.py (working copy) |
| @@ -4,7 +4,9 @@ |
| # found in the LICENSE file. |
| import os |
| +import pickle |
| +import dataset_converter |
| import pyauto_functional # Must be imported before pyauto |
| import pyauto |
| @@ -93,10 +95,59 @@ |
| self.assertEqual([expected_credit_card], |
| self.GetAutoFillProfile()['credit_cards']) |
| - def testAutofillCrowdSourcing(self): |
| - """Test able to send POST request of web form to crowd source server. |
| - Require a loop of 1000 submits as the source server only collects 1% of |
| - the data posted.""" |
| + def testFilterIncompleteAddresses(self): |
| + """Test Autofill filters out profile with incomplete address info.""" |
| + profile = {'NAME_FIRST': 'Bob', |
| + 'NAME_LAST': 'Smith', |
| + 'EMAIL_ADDRESS': 'bsmith@example.com', |
| + 'COMPANY_NAME': 'Company X', |
| + 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} |
| + url = self.GetHttpURLForDataPath( |
| + os.path.join('autofill', 'dup-profiles-test.html')) |
| + self.NavigateToURL(url) |
| + for key, value in profile.iteritems(): |
| + script = ('document.getElementById("%s").value = "%s"; ' |
| + 'window.domAutomationController.send("done")') % (key, value) |
|
dennis_jeffrey
2011/02/16 19:43:29
Indent this line by 1 more space so the strings on
dyu1
2011/02/17 20:38:06
Done.
|
| + self.ExecuteJavascript(script, 0, 0) |
| + js_code = """ |
| + document.getElementById("merge_dup").submit(); |
| + window.addEventListener("unload", function() { |
| + window.domAutomationController.send("done"); |
| + }); |
| + """ |
| + self.ExecuteJavascript(js_code, 0, 0) |
| + self.assertEqual([], self.GetAutoFillProfile()['profiles']) |
| + |
| + def testFilterMalformedEmailAddresses(self): |
| + """Test Autofill filters out malformed email address during form submit.""" |
| + profile = {'NAME_FIRST': 'Bob', |
| + 'NAME_LAST': 'Smith', |
| + 'EMAIL_ADDRESS': 'garbage', |
| + 'ADDRESS_HOME_LINE1': '1234 H St.', |
| + 'ADDRESS_HOME_CITY': 'San Jose', |
| + 'ADDRESS_HOME_STATE': 'CA', |
| + 'ADDRESS_HOME_ZIP': '95110', |
| + 'COMPANY_NAME': 'Company X', |
| + 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} |
| + url = self.GetHttpURLForDataPath( |
| + os.path.join('autofill', 'dup-profiles-test.html')) |
| + self.NavigateToURL(url) |
| + for key, value in profile.iteritems(): |
| + script = ('document.getElementById("%s").value = "%s"; ' |
| + 'window.domAutomationController.send("done")') % (key, value) |
|
dennis_jeffrey
2011/02/16 19:43:29
You might want to put a semicolon after the Javasc
dyu1
2011/02/17 20:38:06
Done.
|
| + self.ExecuteJavascript(script, 0, 0) |
| + js_code = """ |
| + document.getElementById("merge_dup").submit(); |
| + window.addEventListener("unload", function() { |
| + window.domAutomationController.send("done"); |
| + }); |
| + """ |
| + self.ExecuteJavascript(js_code, 0, 0) |
| + if 'EMAIL_ADDRESS' in self.GetAutoFillProfile()['profiles'][0]: |
| + raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') |
| + |
| + def testAutofillCrowdsourcing(self): |
| + """Test able to send POST request of web form to Autofill server.""" |
| # HTML file needs to be run from a specific http:// url to be able to verify |
| # the results a few days later by visiting the same url. |
| url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
| @@ -105,6 +156,7 @@ |
| 'crowdsource_autofill.txt') |
| profiles = self.EvalDataFrom(file_path) |
| self.FillAutoFillProfile(profiles=profiles) |
| + # Autofill server captures 2.5% of the data posted. |
|
dennis_jeffrey
2011/02/16 19:43:29
Is there any verification we can do to check that
dhollowa
2011/02/16 20:34:15
Not really. The Autofill server processes the dat
dennis_jeffrey
2011/02/17 22:58:35
Ok - thanks for the explanation!
|
| for i in range(1000): |
| fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] |
| lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] |
| @@ -124,6 +176,36 @@ |
| 'window.domAutomationController.send("done")', |
|
dennis_jeffrey
2011/02/16 19:43:29
Might want to add a semicolon after the Javascript
dyu1
2011/02/17 20:38:06
Done.
|
| 0, 0) |
| + def testMergeDuplicateProfilesInAutofill(self): |
| + """Test Autofill ability to merge duplicate profiles and throw away junk.""" |
| + # HTML file needs to be run from a http:// url. |
| + url = self.GetHttpURLForDataPath( |
| + os.path.join('autofill', 'duplicate_profiles_test.html')) |
| + # Run the parser script to generate the dictionary list needed for the |
| + # profiles. |
| + c = dataset_converter.DatasetConverter( |
| + os.path.join(self.DataDir(), 'autofill', 'dataset.txt')) |
| + list_of_dict = c.Convert() |
| + for profile in list_of_dict: |
| + self.NavigateToURL(url) |
| + for key, value in profile.iteritems(): |
| + script = ('document.getElementById("%s").value = "%s"; ' |
| + 'window.domAutomationController.send("done")') % (key, value) |
|
dennis_jeffrey
2011/02/16 19:43:29
Same comment as line 110 above.
dyu1
2011/02/17 20:38:06
Done.
|
| + self.ExecuteJavascript(script, 0, 0) |
| + self.ExecuteJavascript('document.getElementById("merge_dup").submit();' |
| + 'window.domAutomationController.send("done")', |
|
dennis_jeffrey
2011/02/16 19:43:29
Might want to add a semicolon after the Javascript
dyu1
2011/02/17 20:38:06
Done.
|
| + 0, 0) |
| + self.assertTrue( |
| + len(list_of_dict) > len(self.GetAutoFillProfile()['profiles'])) |
|
dennis_jeffrey
2011/02/16 19:43:29
Add comment here to indicate why we're doing this
dyu1
2011/02/17 20:38:06
Done.
|
| + # Write profile dictionary to a file. |
| + merged_profile = os.path.join(self.DataDir(), 'autofill', |
| + 'merged-profiles.txt') |
| + profile_dict = self.GetAutoFillProfile()['profiles'] |
| + output = open(merged_profile, 'wb') |
| + pickle.dump(profile_dict, output) |
| + output.close() |
| + |
| + |
| if __name__ == '__main__': |
| pyauto_functional.Main() |