OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 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 logging | 6 import logging |
7 import os | 7 import os |
8 import pickle | 8 import pickle |
9 | 9 |
10 import autofill_dataset_converter | 10 import autofill_dataset_converter |
11 import autofill_dataset_generator | |
11 import pyauto_functional # Must be imported before pyauto | 12 import pyauto_functional # Must be imported before pyauto |
12 import pyauto | 13 import pyauto |
13 | 14 |
15 TAB_KEYPRESS = 0x09 # Tab keyboard key press. | |
16 DOWN_KEYPRESS = 0x28 # Down arrow keyboard key press. | |
17 RETURN_KEYPRESS = 0x0D # Return keyboard key press. | |
14 | 18 |
15 class AutofillTest(pyauto.PyUITest): | 19 class AutoFillTest(pyauto.PyUITest): |
Ilya Sherman
2011/03/22 04:08:58
nit: This should be "AutofillTest" -- see http://c
dyu1
2011/03/24 19:46:51
Done.
| |
16 """Tests that autofill works correctly""" | 20 """Tests that autofill works correctly""" |
17 | 21 |
18 def Debug(self): | 22 def Debug(self): |
19 """Test method for experimentation. | 23 """Test method for experimentation. |
20 | 24 |
21 This method will not run automatically. | 25 This method will not run automatically. |
22 """ | 26 """ |
23 import pprint | 27 import pprint |
24 pp = pprint.PrettyPrinter(indent=2) | 28 pp = pprint.PrettyPrinter(indent=2) |
25 while True: | 29 while True: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 self.GetAutofillProfile()['credit_cards']) | 101 self.GetAutofillProfile()['credit_cards']) |
98 | 102 |
99 def testFilterIncompleteAddresses(self): | 103 def testFilterIncompleteAddresses(self): |
100 """Test Autofill filters out profile with incomplete address info.""" | 104 """Test Autofill filters out profile with incomplete address info.""" |
101 profile = {'NAME_FIRST': 'Bob', | 105 profile = {'NAME_FIRST': 'Bob', |
102 'NAME_LAST': 'Smith', | 106 'NAME_LAST': 'Smith', |
103 'EMAIL_ADDRESS': 'bsmith@example.com', | 107 'EMAIL_ADDRESS': 'bsmith@example.com', |
104 'COMPANY_NAME': 'Company X', | 108 'COMPANY_NAME': 'Company X', |
105 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} | 109 'PHONE_HOME_WHOLE_NUMBER': '650-123-4567',} |
106 url = self.GetHttpURLForDataPath( | 110 url = self.GetHttpURLForDataPath( |
107 os.path.join('autofill', 'dup-profiles-test.html')) | 111 os.path.join('autofill', 'duplicate_profiles_test.html')) |
108 self.NavigateToURL(url) | 112 self.NavigateToURL(url) |
109 for key, value in profile.iteritems(): | 113 for key, value in profile.iteritems(): |
110 script = ('document.getElementById("%s").value = "%s"; ' | 114 script = ('document.getElementById("%s").value = "%s"; ' |
111 'window.domAutomationController.send("done");') % (key, value) | 115 'window.domAutomationController.send("done");') % (key, value) |
112 self.ExecuteJavascript(script, 0, 0) | 116 self.ExecuteJavascript(script, 0, 0) |
113 js_code = """ | 117 js_code = """ |
114 document.getElementById("merge_dup").submit(); | 118 document.getElementById("merge_dup").submit(); |
115 window.addEventListener("unload", function() { | 119 window.addEventListener("unload", function() { |
116 window.domAutomationController.send("done"); | 120 window.domAutomationController.send("done"); |
117 }); | 121 }); |
118 """ | 122 """ |
119 self.ExecuteJavascript(js_code, 0, 0) | 123 self.ExecuteJavascript(js_code, 0, 0) |
120 self.assertEqual([], self.GetAutofillProfile()['profiles']) | 124 self.assertEqual([], self.GetAutofillProfile()['profiles']) |
121 | 125 |
122 def testFilterMalformedEmailAddresses(self): | 126 def testFilterMalformedEmailAddresses(self): |
123 """Test Autofill filters out malformed email address during form submit.""" | 127 """Test Autofill filters out malformed email address during form submit.""" |
124 profile = {'NAME_FIRST': 'Bob', | 128 profile = {'NAME_FIRST': 'Bob', |
125 'NAME_LAST': 'Smith', | 129 'NAME_LAST': 'Smith', |
126 'EMAIL_ADDRESS': 'garbage', | 130 'EMAIL_ADDRESS': 'garbage', |
127 'ADDRESS_HOME_LINE1': '1234 H St.', | 131 'ADDRESS_HOME_LINE1': '1234 H St.', |
128 'ADDRESS_HOME_CITY': 'San Jose', | 132 'ADDRESS_HOME_CITY': 'San Jose', |
129 'ADDRESS_HOME_STATE': 'CA', | 133 'ADDRESS_HOME_STATE': 'CA', |
130 'ADDRESS_HOME_ZIP': '95110', | 134 'ADDRESS_HOME_ZIP': '95110', |
131 'COMPANY_NAME': 'Company X', | 135 'COMPANY_NAME': 'Company X', |
132 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} | 136 'PHONE_HOME_WHOLE_NUMBER': '408-123-4567',} |
133 url = self.GetHttpURLForDataPath( | 137 url = self.GetHttpURLForDataPath( |
134 os.path.join('autofill', 'dup-profiles-test.html')) | 138 os.path.join('autofill', 'duplicate_profiles_test.html')) |
135 self.NavigateToURL(url) | 139 self.NavigateToURL(url) |
136 for key, value in profile.iteritems(): | 140 for key, value in profile.iteritems(): |
137 script = ('document.getElementById("%s").value = "%s"; ' | 141 script = ('document.getElementById("%s").value = "%s"; ' |
138 'window.domAutomationController.send("done");') % (key, value) | 142 'window.domAutomationController.send("done");') % (key, value) |
139 self.ExecuteJavascript(script, 0, 0) | 143 self.ExecuteJavascript(script, 0, 0) |
140 js_code = """ | 144 js_code = """ |
141 document.getElementById("merge_dup").submit(); | 145 document.getElementById("merge_dup").submit(); |
142 window.addEventListener("unload", function() { | 146 window.addEventListener("unload", function() { |
143 window.domAutomationController.send("done"); | 147 window.domAutomationController.send("done"); |
144 }); | 148 }); |
145 """ | 149 """ |
146 self.ExecuteJavascript(js_code, 0, 0) | 150 self.ExecuteJavascript(js_code, 0, 0) |
147 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: | 151 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: |
148 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | 152 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') |
149 | 153 |
154 def testComparePhoneNumbers(self): | |
155 """Test phone fields parses correctly from a given profile.""" | |
dennis_jeffrey
2011/03/22 23:28:53
"fields parses" --> "fields parse"
dyu1
2011/03/24 19:46:51
Done.
| |
156 profile_path = os.path.join(self.DataDir(), 'autofill', | |
157 'phone_pinput_autofill.txt') | |
158 profile_expected_path = os.path.join(self.DataDir(), 'autofill', | |
159 'phone_pexpected_autofill.txt') | |
160 profiles = self.EvalDataFrom(profile_path) | |
161 profiles_expected = self.EvalDataFrom(profile_expected_path) | |
162 self.FillAutofillProfile(profiles=profiles) | |
163 url = self.GetHttpURLForDataPath( | |
164 os.path.join('autofill', 'form_phones.html')) | |
165 for profile_expected in profiles_expected: | |
166 self.NavigateToURL(url) | |
167 # Tab keyboard key press. | |
168 self.SendWebkitKeyEvent(TAB_KEYPRESS, tab_index=0, windex=0) | |
169 # Down arrow keyboard key press. | |
170 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
171 # Down arrow keyboard key press. | |
172 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
173 # Return keyboard key press. | |
dennis_jeffrey
2011/03/22 23:28:53
Sorry I wasn't clear before: when I asked for comm
dyu1
2011/03/24 19:46:51
I added the high level steps in the description.
| |
174 self.SendWebkitKeyEvent(RETURN_KEYPRESS, tab_index=0, windex=0) | |
175 form_values = {} | |
176 for key, value in profile_expected.iteritems(): | |
177 js_returning_field_value = ( | |
178 'var field_value = document.getElementById("%s").value;' | |
179 'window.domAutomationController.send(field_value);' | |
180 ) % key | |
181 form_values[key] = self.ExecuteJavascript( | |
182 js_returning_field_value, 0, 0) | |
183 self.assertEqual( | |
184 form_values[key], value, | |
185 ('Original profile not equal to expected profile at key: "%s"\n' | |
186 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) | |
187 | |
188 def FormFillLatencyAfterSubmit(self): | |
189 """Test latency time on form submit with lots of stored Autofill profiles. | |
190 | |
191 This test verifies when a profile is selected from the Autofill dictionary | |
192 that consists of thousands of profiles, the form does not hang after being | |
193 submitted. | |
dennis_jeffrey
2011/03/22 23:28:53
Should probably also mention here that this test i
dyu1
2011/03/24 19:46:51
Done.
| |
194 """ | |
195 # HTML file needs to be run from a http:// url. | |
196 url = self.GetHttpURLForDataPath( | |
197 os.path.join('autofill', 'latency_after_submit_test.html')) | |
198 # Run the generator script to generate the dictionary list needed for the | |
199 # profiles. | |
200 gen = autofill_dataset_generator.DatasetGenerator( | |
201 logging_level=logging.ERROR) | |
202 list_of_dict = gen.GenerateDataset(num_of_dict_to_generate=1501) | |
dennis_jeffrey
2011/03/22 23:28:53
1501 is a bit of a weird number! Just curious if
dyu1
2011/03/24 19:46:51
Wanted more than 1500 profiles based on the bug. B
dennis_jeffrey
2011/03/25 16:56:14
What?!?! That's like an ice cream shop advertisin
| |
203 self.FillAutofillProfile(profiles=list_of_dict) | |
204 self.NavigateToURL(url) | |
205 # Tab keyboard key press. | |
206 self.SendWebkitKeyEvent(TAB_KEYPRESS, windex=0, tab_index=0) | |
207 # Down arrow keyboard key press. | |
208 self.SendWebkitKeyEvent(DOWN_KEYPRESS, windex=0, tab_index=0) | |
209 # Down arrow keyboard key press. | |
210 self.SendWebkitKeyEvent(DOWN_KEYPRESS, windex=0, tab_index=0) | |
211 # Return keyboard key press. | |
dennis_jeffrey
2011/03/22 23:28:53
Similar comment as the one above at line 173.
dyu1
2011/03/24 19:46:51
Done.
| |
212 self.SendWebkitKeyEvent(RETURN_KEYPRESS, windex=0, tab_index=0) | |
213 # Requires manual intervention to test the performance time after submitting | |
214 # the form. | |
215 raw_input() | |
216 | |
217 | |
150 def AutofillCrowdsourcing(self): | 218 def AutofillCrowdsourcing(self): |
151 """Test able to send POST request of web form to Autofill server. | 219 """Test able to send POST request of web form to Autofill server. |
152 | 220 |
153 The Autofill server processes the data offline, so it can take a few days | 221 The Autofill server processes the data offline, so it can take a few days |
154 for the result to be detectable. Manual verification is required. | 222 for the result to be detectable. Manual verification is required. |
155 """ | 223 """ |
156 # HTML file needs to be run from a specific http:// url to be able to verify | 224 # HTML file needs to be run from a specific http:// url to be able to verify |
157 # the results a few days later by visiting the same url. | 225 # the results a few days later by visiting the same url. |
158 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 226 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
159 # Adding crowdsourcing Autofill profile. | 227 # Adding crowdsourcing Autofill profile. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 merged_profile = os.path.join(self.DataDir(), 'autofill', | 280 merged_profile = os.path.join(self.DataDir(), 'autofill', |
213 'merged-profiles.txt') | 281 'merged-profiles.txt') |
214 profile_dict = self.GetAutofillProfile()['profiles'] | 282 profile_dict = self.GetAutofillProfile()['profiles'] |
215 output = open(merged_profile, 'wb') | 283 output = open(merged_profile, 'wb') |
216 pickle.dump(profile_dict, output) | 284 pickle.dump(profile_dict, output) |
217 output.close() | 285 output.close() |
218 | 286 |
219 | 287 |
220 if __name__ == '__main__': | 288 if __name__ == '__main__': |
221 pyauto_functional.Main() | 289 pyauto_functional.Main() |
OLD | NEW |