Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 os | 6 import os |
| 7 import pickle | |
| 7 | 8 |
| 9 import dataset_converter | |
| 8 import pyauto_functional # Must be imported before pyauto | 10 import pyauto_functional # Must be imported before pyauto |
| 9 import pyauto | 11 import pyauto |
| 10 | 12 |
| 11 | 13 |
| 12 class AutoFillTest(pyauto.PyUITest): | 14 class AutoFillTest(pyauto.PyUITest): |
| 13 """Tests that autofill works correctly""" | 15 """Tests that autofill works correctly""" |
| 14 | 16 |
| 15 def Debug(self): | 17 def Debug(self): |
| 16 """Test method for experimentation. | 18 """Test method for experimentation. |
| 17 | 19 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 self.assertEqual([without_invalid], | 88 self.assertEqual([without_invalid], |
| 87 self.GetAutoFillProfile()['profiles']) | 89 self.GetAutoFillProfile()['profiles']) |
| 88 | 90 |
| 89 # Then try credit cards with invalid input. Should strip off all non-digits | 91 # Then try credit cards with invalid input. Should strip off all non-digits |
| 90 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'} | 92 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'} |
| 91 expected_credit_card = {'CREDIT_CARD_NUMBER': '01235'} | 93 expected_credit_card = {'CREDIT_CARD_NUMBER': '01235'} |
| 92 self.FillAutoFillProfile(credit_cards=[credit_card]) | 94 self.FillAutoFillProfile(credit_cards=[credit_card]) |
| 93 self.assertEqual([expected_credit_card], | 95 self.assertEqual([expected_credit_card], |
| 94 self.GetAutoFillProfile()['credit_cards']) | 96 self.GetAutoFillProfile()['credit_cards']) |
| 95 | 97 |
| 96 def testAutofillCrowdSourcing(self): | 98 def testFilterIncompleteAddresses(self): |
| 97 """Test able to send POST request of web form to crowd source server. | 99 """Test Autofill filters out profile with incomplete address info.""" |
| 98 Require a loop of 1000 submits as the source server only collects 1% of | 100 profile = {'NAME_FIRST': 'Bob', |
| 99 the data posted.""" | 101 'NAME_LAST': 'Smith', |
| 102 'EMAIL_ADDRESS': 'bsmith@example.com', | |
| 103 'COMPANY_NAME': 'Company X', | |
| 104 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} | |
| 105 url = self.GetHttpURLForDataPath( | |
| 106 os.path.join('autofill', 'dup-profiles-test.html')) | |
| 107 self.NavigateToURL(url) | |
| 108 for key, value in profile.iteritems(): | |
| 109 script = ('document.getElementById("%s").value = "%s"; ' | |
| 110 '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.
| |
| 111 self.ExecuteJavascript(script, 0, 0) | |
| 112 js_code = """ | |
| 113 document.getElementById("merge_dup").submit(); | |
| 114 window.addEventListener("unload", function() { | |
| 115 window.domAutomationController.send("done"); | |
| 116 }); | |
| 117 """ | |
| 118 self.ExecuteJavascript(js_code, 0, 0) | |
| 119 self.assertEqual([], self.GetAutoFillProfile()['profiles']) | |
| 120 | |
| 121 def testFilterMalformedEmailAddresses(self): | |
| 122 """Test Autofill filters out malformed email address during form submit.""" | |
| 123 profile = {'NAME_FIRST': 'Bob', | |
| 124 'NAME_LAST': 'Smith', | |
| 125 'EMAIL_ADDRESS': 'garbage', | |
| 126 'ADDRESS_HOME_LINE1': '1234 H St.', | |
| 127 'ADDRESS_HOME_CITY': 'San Jose', | |
| 128 'ADDRESS_HOME_STATE': 'CA', | |
| 129 'ADDRESS_HOME_ZIP': '95110', | |
| 130 'COMPANY_NAME': 'Company X', | |
| 131 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} | |
| 132 url = self.GetHttpURLForDataPath( | |
| 133 os.path.join('autofill', 'dup-profiles-test.html')) | |
| 134 self.NavigateToURL(url) | |
| 135 for key, value in profile.iteritems(): | |
| 136 script = ('document.getElementById("%s").value = "%s"; ' | |
| 137 '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.
| |
| 138 self.ExecuteJavascript(script, 0, 0) | |
| 139 js_code = """ | |
| 140 document.getElementById("merge_dup").submit(); | |
| 141 window.addEventListener("unload", function() { | |
| 142 window.domAutomationController.send("done"); | |
| 143 }); | |
| 144 """ | |
| 145 self.ExecuteJavascript(js_code, 0, 0) | |
| 146 if 'EMAIL_ADDRESS' in self.GetAutoFillProfile()['profiles'][0]: | |
| 147 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | |
| 148 | |
| 149 def testAutofillCrowdsourcing(self): | |
| 150 """Test able to send POST request of web form to Autofill server.""" | |
| 100 # HTML file needs to be run from a specific http:// url to be able to verify | 151 # HTML file needs to be run from a specific http:// url to be able to verify |
| 101 # the results a few days later by visiting the same url. | 152 # the results a few days later by visiting the same url. |
| 102 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 153 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
| 103 # Adding crowdsourcing Autofill profile. | 154 # Adding crowdsourcing Autofill profile. |
| 104 file_path = os.path.join(self.DataDir(), 'autofill', | 155 file_path = os.path.join(self.DataDir(), 'autofill', |
| 105 'crowdsource_autofill.txt') | 156 'crowdsource_autofill.txt') |
| 106 profiles = self.EvalDataFrom(file_path) | 157 profiles = self.EvalDataFrom(file_path) |
| 107 self.FillAutoFillProfile(profiles=profiles) | 158 self.FillAutoFillProfile(profiles=profiles) |
| 159 # 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!
| |
| 108 for i in range(1000): | 160 for i in range(1000): |
| 109 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] | 161 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] |
| 110 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] | 162 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] |
| 111 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] | 163 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] |
| 112 # Submit form to collect crowdsourcing data for Autofill. | 164 # Submit form to collect crowdsourcing data for Autofill. |
| 113 self.NavigateToURL(url, 0, 0) | 165 self.NavigateToURL(url, 0, 0) |
| 114 fname_field = 'document.getElementById("fn").value = "%s"; ' \ | 166 fname_field = 'document.getElementById("fn").value = "%s"; ' \ |
| 115 'window.domAutomationController.send("done")' % fname | 167 'window.domAutomationController.send("done")' % fname |
| 116 lname_field = 'document.getElementById("ln").value = "%s"; ' \ | 168 lname_field = 'document.getElementById("ln").value = "%s"; ' \ |
| 117 'window.domAutomationController.send("done")' % lname | 169 'window.domAutomationController.send("done")' % lname |
| 118 email_field = 'document.getElementById("em").value = "%s"; ' \ | 170 email_field = 'document.getElementById("em").value = "%s"; ' \ |
| 119 'window.domAutomationController.send("done")' % email | 171 'window.domAutomationController.send("done")' % email |
|
dennis_jeffrey
2011/02/16 19:43:29
In lines 166-171 above, use Python's ability to co
dyu1
2011/02/17 20:38:06
Done.
| |
| 120 self.ExecuteJavascript(fname_field, 0, 0); | 172 self.ExecuteJavascript(fname_field, 0, 0); |
| 121 self.ExecuteJavascript(lname_field, 0, 0); | 173 self.ExecuteJavascript(lname_field, 0, 0); |
| 122 self.ExecuteJavascript(email_field, 0, 0); | 174 self.ExecuteJavascript(email_field, 0, 0); |
| 123 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' | 175 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' |
| 124 'window.domAutomationController.send("done")', | 176 '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.
| |
| 125 0, 0) | 177 0, 0) |
| 126 | 178 |
| 179 def testMergeDuplicateProfilesInAutofill(self): | |
| 180 """Test Autofill ability to merge duplicate profiles and throw away junk.""" | |
| 181 # HTML file needs to be run from a http:// url. | |
| 182 url = self.GetHttpURLForDataPath( | |
| 183 os.path.join('autofill', 'duplicate_profiles_test.html')) | |
| 184 # Run the parser script to generate the dictionary list needed for the | |
| 185 # profiles. | |
| 186 c = dataset_converter.DatasetConverter( | |
| 187 os.path.join(self.DataDir(), 'autofill', 'dataset.txt')) | |
| 188 list_of_dict = c.Convert() | |
| 189 | |
| 190 for profile in list_of_dict: | |
| 191 self.NavigateToURL(url) | |
| 192 for key, value in profile.iteritems(): | |
| 193 script = ('document.getElementById("%s").value = "%s"; ' | |
| 194 '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.
| |
| 195 self.ExecuteJavascript(script, 0, 0) | |
| 196 self.ExecuteJavascript('document.getElementById("merge_dup").submit();' | |
| 197 '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.
| |
| 198 0, 0) | |
| 199 self.assertTrue( | |
| 200 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.
| |
| 201 # Write profile dictionary to a file. | |
| 202 merged_profile = os.path.join(self.DataDir(), 'autofill', | |
| 203 'merged-profiles.txt') | |
| 204 profile_dict = self.GetAutoFillProfile()['profiles'] | |
| 205 output = open(merged_profile, 'wb') | |
| 206 pickle.dump(profile_dict, output) | |
| 207 output.close() | |
| 208 | |
| 127 | 209 |
| 128 if __name__ == '__main__': | 210 if __name__ == '__main__': |
| 129 pyauto_functional.Main() | 211 pyauto_functional.Main() |
| OLD | NEW |