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