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 profiles with incomplete address info |
98 Require a loop of 1000 submits as the source server only collects 1% of | 100 during form submission and aggregation steps. Regression test for |
101 bug 71710.""" | |
dennisjeffrey
2011/02/11 00:53:17
The first line of this comment should be a 1-line
dyu1
2011/02/16 03:17:31
Done.
On 2011/02/11 00:53:17, dennisjeffrey wrote
| |
102 profiles = [{'NAME_FIRST': 'Bob', | |
103 'NAME_LAST': 'Smith', | |
104 'EMAIL_ADDRESS': 'bsmith@example.com', | |
105 'COMPANY_NAME': 'Company X', | |
106 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',}] | |
107 url = self.GetHttpURLForDataPath( | |
108 os.path.join('autofill', 'dup-profiles-test.html')) | |
109 for p in profiles: | |
dennisjeffrey
2011/02/11 00:53:17
This test case seems to use just a single profile,
dyu1
2011/02/16 03:17:31
Done. Changed the array to a dict.
On 2011/02/11
| |
110 self.NavigateToURL(url) | |
111 for key, value in p.iteritems(): | |
112 script = 'document.getElementById("%s").value = "%s"; ' \ | |
113 'window.domAutomationController.send("done")' % (key, value) | |
dennisjeffrey
2011/02/11 00:53:17
Python will automatically concatenate strings on m
dyu1
2011/02/16 03:17:31
Done.
| |
114 self.ExecuteJavascript(script, 0, 0) | |
115 self.ExecuteJavascript('document.getElementById("merge_dup").submit();' | |
116 'window.addEventListener("unload", function(){' | |
117 'window.domAutomationController.send("done");});', | |
118 0, 0) | |
dennisjeffrey
2011/02/11 00:53:17
I think it might look neater to put the code into
dyu1
2011/02/16 03:17:31
Done.
| |
119 self.assertEqual([], self.GetAutoFillProfile()['profiles']) | |
120 | |
121 def testFilterMalformedEmailAddresses(self): | |
122 """Test Autofill filters out malformed email addresses when form is | |
123 submitted. Regression test for bug 73654.""" | |
dennisjeffrey
2011/02/11 00:53:17
The first line of this comment should be a 1-line
dyu1
2011/02/16 03:17:31
Done.
| |
124 profiles = [{'NAME_FIRST': 'Bob', | |
125 'NAME_LAST': 'Smith', | |
126 'EMAIL_ADDRESS': 'garbage', | |
127 'ADDRESS_HOME_LINE1': '1234 H St.', | |
128 'ADDRESS_HOME_CITY': 'San Jose', | |
129 'ADDRESS_HOME_STATE': 'CA', | |
130 'ADDRESS_HOME_ZIP': '95110', | |
131 'COMPANY_NAME': 'Company X', | |
132 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',}] | |
133 url = self.GetHttpURLForDataPath( | |
134 os.path.join('autofill', 'dup-profiles-test.html')) | |
135 for p in profiles: | |
dennisjeffrey
2011/02/11 00:53:17
It also looks like there's only 1 profile here, so
dyu1
2011/02/16 03:17:31
Done.
| |
136 self.NavigateToURL(url) | |
137 for key, value in p.iteritems(): | |
138 script = 'document.getElementById("%s").value = "%s"; ' \ | |
139 'window.domAutomationController.send("done")' % (key, value) | |
dennisjeffrey
2011/02/11 00:53:17
Same comment as line 113 above.
dyu1
2011/02/16 03:17:31
Done.
| |
140 self.ExecuteJavascript(script, 0, 0) | |
141 self.ExecuteJavascript('document.getElementById("merge_dup").submit();' | |
142 'window.addEventListener("unload", function(){' | |
143 'window.domAutomationController.send("done");});', | |
144 0, 0) | |
dennisjeffrey
2011/02/11 00:53:17
Same comment as line 118 above.
dyu1
2011/02/16 03:17:31
Done.
| |
145 if 'EMAIL_ADDRESS' in self.GetAutoFillProfile()['profiles'][0]: | |
146 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | |
147 else: | |
148 print 'TEST PASS: Malformed email address is not saved in profiles.' | |
dennisjeffrey
2011/02/11 00:53:17
I think we can remove lines 147-148. Probably no
dyu1
2011/02/16 03:17:31
Done.
| |
149 | |
150 def testAutofillCrowdsourcing(self): | |
151 """Test able to send POST request of web form to Autofill server. | |
152 Require a loop of 1000 submits as the Autofill server only collects 1% of | |
dennisjeffrey
2011/02/11 00:53:17
The first line of this comment should be a 1-line
dyu1
2011/02/16 03:17:31
Done.
| |
99 the data posted.""" | 153 the data posted.""" |
100 # HTML file needs to be run from a specific http:// url to be able to verify | 154 # 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. | 155 # the results a few days later by visiting the same url. |
102 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 156 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
103 # Adding crowdsourcing Autofill profile. | 157 # Adding crowdsourcing Autofill profile. |
104 file_path = os.path.join(self.DataDir(), 'autofill', | 158 file_path = os.path.join(self.DataDir(), 'autofill', |
105 'crowdsource_autofill.txt') | 159 'crowdsource_autofill.txt') |
106 profiles = self.EvalDataFrom(file_path) | 160 profiles = self.EvalDataFrom(file_path) |
107 self.FillAutoFillProfile(profiles=profiles) | 161 self.FillAutoFillProfile(profiles=profiles) |
108 for i in range(1000): | 162 for i in range(1000): |
109 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] | 163 fname = self.GetAutoFillProfile()['profiles'][0]['NAME_FIRST'] |
110 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] | 164 lname = self.GetAutoFillProfile()['profiles'][0]['NAME_LAST'] |
111 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] | 165 email = self.GetAutoFillProfile()['profiles'][0]['EMAIL_ADDRESS'] |
112 # Submit form to collect crowdsourcing data for Autofill. | 166 # Submit form to collect crowdsourcing data for Autofill. |
113 self.NavigateToURL(url, 0, 0) | 167 self.NavigateToURL(url, 0, 0) |
114 fname_field = 'document.getElementById("fn").value = "%s"; ' \ | 168 fname_field = 'document.getElementById("fn").value = "%s"; ' \ |
115 'window.domAutomationController.send("done")' % fname | 169 'window.domAutomationController.send("done")' % fname |
116 lname_field = 'document.getElementById("ln").value = "%s"; ' \ | 170 lname_field = 'document.getElementById("ln").value = "%s"; ' \ |
117 'window.domAutomationController.send("done")' % lname | 171 'window.domAutomationController.send("done")' % lname |
118 email_field = 'document.getElementById("em").value = "%s"; ' \ | 172 email_field = 'document.getElementById("em").value = "%s"; ' \ |
119 'window.domAutomationController.send("done")' % email | 173 'window.domAutomationController.send("done")' % email |
120 self.ExecuteJavascript(fname_field, 0, 0); | 174 self.ExecuteJavascript(fname_field, 0, 0); |
121 self.ExecuteJavascript(lname_field, 0, 0); | 175 self.ExecuteJavascript(lname_field, 0, 0); |
122 self.ExecuteJavascript(email_field, 0, 0); | 176 self.ExecuteJavascript(email_field, 0, 0); |
123 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' | 177 self.ExecuteJavascript('document.getElementById("frmsubmit").submit();' |
124 'window.domAutomationController.send("done")', | 178 'window.domAutomationController.send("done")', |
125 0, 0) | 179 0, 0) |
126 | 180 |
181 def testMergeDuplicateProfilesInAutofill(self): | |
182 """Test Autofill ability to merge duplicate profiles and throw away junk | |
183 profiles. The goal is to submit a couple hundred profiles and see the merge | |
184 outcome.""" | |
dennisjeffrey
2011/02/11 00:53:17
The first line of this comment should be a 1-line
dyu1
2011/02/16 03:17:31
Done.
| |
185 # HTML file needs to be run from a http:// url. | |
186 url = self.GetHttpURLForDataPath( | |
187 os.path.join('autofill', 'duplicate_profiles_test.html')) | |
188 # Run the parser script to generate the dictionary list needed for the | |
189 # profiles. | |
190 c = dataset_converter.DatasetConverter(os.path.join( | |
191 self.DataDir(), 'autofill', 'dataset.txt')) | |
dennisjeffrey
2011/02/11 00:53:17
Move the "os.path.join(" down to the next line:
c
dyu1
2011/02/16 03:17:31
Done.
| |
192 list_of_dict = c.Convert() | |
193 | |
194 for profile in list_of_dict: | |
195 self.NavigateToURL(url) | |
196 for key, value in profile.iteritems(): | |
197 script = 'document.getElementById("%s").value = "%s"; ' \ | |
198 'window.domAutomationController.send("done")' % (key, value) | |
dennisjeffrey
2011/02/11 00:53:17
Same comment as line 113 above.
dyu1
2011/02/16 03:17:31
Done.
| |
199 self.ExecuteJavascript(script, 0, 0) | |
200 self.ExecuteJavascript('document.getElementById("merge_dup").submit();' | |
201 'window.domAutomationController.send("done")', | |
202 0, 0) | |
203 # Write profile dictionary to a file. | |
204 profile_dict = self.GetAutoFillProfile()['profiles'] | |
205 output = open('merged-profile.txt', 'wb') | |
206 pickle.dump(profile_dict, output) | |
207 output.close() | |
dennisjeffrey
2011/02/11 00:53:17
Shouldn't the test do some kind of verification he
dyu1
2011/02/16 03:17:31
I added a test to compare the number of input prof
dennis_jeffrey
2011/02/16 19:43:29
If the only thing we need to verify is that the to
| |
208 | |
127 | 209 |
128 if __name__ == '__main__': | 210 if __name__ == '__main__': |
129 pyauto_functional.Main() | 211 pyauto_functional.Main() |
OLD | NEW |