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 | 7 |
| 8 import pickle | |
|
Nirnimesh
2011/02/07 23:26:20
group with os above.
pickle is a system import
dyu1
2011/02/09 19:44:56
Done.
| |
| 8 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
| 9 import pyauto | 10 import pyauto |
| 10 | 11 |
| 11 | 12 |
| 12 class AutoFillTest(pyauto.PyUITest): | 13 class AutoFillTest(pyauto.PyUITest): |
| 13 """Tests that autofill works correctly""" | 14 """Tests that autofill works correctly""" |
| 14 | 15 |
| 15 def Debug(self): | 16 def Debug(self): |
| 16 """Test method for experimentation. | 17 """Test method for experimentation. |
| 17 | 18 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 self.assertEqual([without_invalid], | 87 self.assertEqual([without_invalid], |
| 87 self.GetAutoFillProfile()['profiles']) | 88 self.GetAutoFillProfile()['profiles']) |
| 88 | 89 |
| 89 # Then try credit cards with invalid input. Should strip off all non-digits | 90 # Then try credit cards with invalid input. Should strip off all non-digits |
| 90 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'} | 91 credit_card = {'CREDIT_CARD_NUMBER': 'Not_0123-5Checked'} |
| 91 expected_credit_card = {'CREDIT_CARD_NUMBER': '01235'} | 92 expected_credit_card = {'CREDIT_CARD_NUMBER': '01235'} |
| 92 self.FillAutoFillProfile(credit_cards=[credit_card]) | 93 self.FillAutoFillProfile(credit_cards=[credit_card]) |
| 93 self.assertEqual([expected_credit_card], | 94 self.assertEqual([expected_credit_card], |
| 94 self.GetAutoFillProfile()['credit_cards']) | 95 self.GetAutoFillProfile()['credit_cards']) |
| 95 | 96 |
| 96 def testAutofillCrowdSourcing(self): | 97 def testAutofillCrowdsourcing(self): |
| 97 """Test able to send POST request of web form to crowd source server. | 98 """Test able to send POST request of web form to Autofill server. |
| 98 Require a loop of 1000 submits as the source server only collects 1% of | 99 Require a loop of 1000 submits as the Autofill server only collects 1% of |
| 99 the data posted.""" | 100 the data posted.""" |
| 100 # HTML file needs to be run from a specific http:// url to be able to verify | 101 # 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. | 102 # the results a few days later by visiting the same url. |
| 102 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 103 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
| 103 # Adding crowdsourcing Autofill profile. | 104 # Adding crowdsourcing Autofill profile. |
| 104 file_path = os.path.join(self.DataDir(), 'autofill', | 105 file_path = os.path.join(self.DataDir(), 'autofill', |
| 105 'crowdsource_autofill.txt') | 106 'crowdsource_autofill.txt') |
| 106 profiles = self.EvalDataFrom(file_path) | 107 profiles = self.EvalDataFrom(file_path) |
| 107 self.FillAutoFillProfile(profiles=profiles) | 108 self.FillAutoFillProfile(profiles=profiles) |
| 108 for i in range(1000): | 109 for i in range(1000): |
| 109 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] | 110 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] |
| 110 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] | 111 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] |
| 111 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] | 112 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] |
| 112 # Submit form to collect crowdsourcing data for Autofill. | 113 # Submit form to collect crowdsourcing data for Autofill. |
| 113 self.NavigateToURL(url, 0, 0) | 114 self.NavigateToURL(url, 0, 0) |
| 114 fname_field = 'document.getElementById("fn").value = "%s"; ' \ | 115 fname_field = 'document.getElementById("fn").value = "%s"; ' \ |
| 115 'window.domAutomationController.send("done")' % fname | 116 'window.domAutomationController.send("done")' % fname |
| 116 lname_field = 'document.getElementById("ln").value = "%s"; ' \ | 117 lname_field = 'document.getElementById("ln").value = "%s"; ' \ |
| 117 'window.domAutomationController.send("done")' % lname | 118 'window.domAutomationController.send("done")' % lname |
| 118 email_field = 'document.getElementById("em").value = "%s"; ' \ | 119 email_field = 'document.getElementById("em").value = "%s"; ' \ |
| 119 'window.domAutomationController.send("done")' % email | 120 'window.domAutomationController.send("done")' % email |
| 120 self.ExecuteJavascript(fname_field, 0, 0); | 121 self.ExecuteJavascript(fname_field, 0, 0); |
| 121 self.ExecuteJavascript(lname_field, 0, 0); | 122 self.ExecuteJavascript(lname_field, 0, 0); |
| 122 self.ExecuteJavascript(email_field, 0, 0); | 123 self.ExecuteJavascript(email_field, 0, 0); |
| 123 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' | 124 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' |
| 124 'window.domAutomationController.send("done")', | 125 'window.domAutomationController.send("done")', |
| 125 0, 0) | 126 0, 0) |
| 126 | 127 |
| 128 def testMergeDuplicateProfilesInAutofill(self): | |
| 129 """Test Autofill ability to merge duplicate profiles and throw away junk | |
| 130 profiles. The goal is to submit a couple hundred profiles and see the merge | |
| 131 outcome.""" | |
| 132 # HTML file needs to be run from a http:// url. | |
| 133 url = self.GetHttpURLForDataPath( | |
| 134 os.path.join('autofill', 'dup-profiles-test.html')) | |
| 135 # Add and set Autofill profiles. | |
| 136 file_path = os.path.join(self.DataDir(), 'autofill', | |
| 137 'dataset_duplicate-profiles.txt') | |
|
Nirnimesh
2011/02/07 23:26:20
Why use this precooked file? Why not call the csv
dyu1
2011/02/09 19:44:56
Done.
| |
| 138 profiles = self.EvalDataFrom(file_path) | |
| 139 self.FillAutoFillProfile(profiles=profiles) | |
| 140 for i in range(len(self.GetAutoFillProfile()['profiles'])): | |
| 141 self.NavigateToURL(url) | |
| 142 for key, value in self.GetAutoFillProfile()['profiles'][i].iteritems(): | |
| 143 script = 'document.getElementById("%s").value = "%s"; ' \ | |
| 144 'window.domAutomationController.send("done")' % (key, value) | |
| 145 self.ExecuteJavascript(script, 0, 0) | |
| 146 self.ExecuteJavascript('document.getElementById("merge_dup").submit();' | |
| 147 'window.domAutomationController.send("done")', | |
| 148 0, 0) | |
| 149 # Write profile dictionary to a file. | |
| 150 profile_dict = self.GetAutoFillProfile()['profiles'] | |
| 151 output = open('merged-profile.txt', 'wb') | |
| 152 pickle.dump(profile_dict, output) | |
| 153 output.close() | |
| 154 | |
| 127 | 155 |
| 128 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 129 pyauto_functional.Main() | 157 pyauto_functional.Main() |
| OLD | NEW |