OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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): |
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 |
(...skipping 73 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 parse correctly from a given profile. | |
156 | |
157 The high level key presses execute the following: Select the first text | |
158 field, invoke the autofill popup list, select the first profile within the | |
159 list, and commit to the profile to populate the form. | |
160 """ | |
161 profile_path = os.path.join(self.DataDir(), 'autofill', | |
162 'phone_pinput_autofill.txt') | |
163 profile_expected_path = os.path.join(self.DataDir(), 'autofill', | |
164 'phone_pexpected_autofill.txt') | |
165 profiles = self.EvalDataFrom(profile_path) | |
166 profiles_expected = self.EvalDataFrom(profile_expected_path) | |
167 self.FillAutofillProfile(profiles=profiles) | |
168 url = self.GetHttpURLForDataPath( | |
169 os.path.join('autofill', 'form_phones.html')) | |
170 for profile_expected in profiles_expected: | |
171 self.NavigateToURL(url) | |
172 # Tab keyboard key press. | |
173 self.SendWebkitKeyEvent(TAB_KEYPRESS, tab_index=0, windex=0) | |
174 # Down arrow keyboard key press. | |
175 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
176 # Down arrow keyboard key press. | |
177 self.SendWebkitKeyEvent(DOWN_KEYPRESS, tab_index=0, windex=0) | |
178 # Return keyboard key press. | |
179 self.SendWebkitKeyEvent(RETURN_KEYPRESS, tab_index=0, windex=0) | |
180 form_values = {} | |
181 for key, value in profile_expected.iteritems(): | |
182 js_returning_field_value = ( | |
183 'var field_value = document.getElementById("%s").value;' | |
184 'window.domAutomationController.send(field_value);' | |
185 ) % key | |
186 form_values[key] = self.ExecuteJavascript( | |
187 js_returning_field_value, 0, 0) | |
188 self.assertEqual( | |
189 form_values[key], value, | |
190 ('Original profile not equal to expected profile at key: "%s"\n' | |
191 'Expected: "%s"\nReturned: "%s"' % (key, value, form_values[key]))) | |
192 | |
193 def FormFillLatencyAfterSubmit(self): | |
194 """Test latency time on form submit with lots of stored Autofill profiles. | |
195 | |
196 This test verifies when a profile is selected from the Autofill dictionary | |
197 that consists of thousands of profiles, the form does not hang after being | |
198 submitted. | |
199 | |
200 The high level key presses execute the following: Select the first text | |
201 field, invoke the autofill popup list, select the first profile within the | |
202 list, and commit to the profile to populate the form. | |
203 | |
204 This test is partially automated. The bulk of the work is done, such as | |
205 generating 1500 plus profiles, inserting those profiles into Autofill, | |
206 selecting a profile from the list. The tester will need to click on the | |
207 submit button and check if the browser hangs. | |
208 """ | |
209 # HTML file needs to be run from a http:// url. | |
210 url = self.GetHttpURLForDataPath( | |
211 os.path.join('autofill', 'latency_after_submit_test.html')) | |
212 # Run the generator script to generate the dictionary list needed for the | |
213 # profiles. | |
214 gen = autofill_dataset_generator.DatasetGenerator( | |
215 logging_level=logging.ERROR) | |
216 list_of_dict = gen.GenerateDataset(num_of_dict_to_generate=1501) | |
217 self.FillAutofillProfile(profiles=list_of_dict) | |
218 self.NavigateToURL(url) | |
219 # Tab keyboard key press. | |
220 self.SendWebkitKeyEvent(TAB_KEYPRESS, windex=0, tab_index=0) | |
221 # Down arrow keyboard key press. | |
222 self.SendWebkitKeyEvent(DOWN_KEYPRESS, windex=0, tab_index=0) | |
223 # Down arrow keyboard key press. | |
224 self.SendWebkitKeyEvent(DOWN_KEYPRESS, windex=0, tab_index=0) | |
225 # Return keyboard key press. | |
226 self.SendWebkitKeyEvent(RETURN_KEYPRESS, windex=0, tab_index=0) | |
227 # Requires manual intervention to test the performance time after submitting | |
228 # the form. | |
229 # TODO: add automated form hang or crash verification. | |
dennis_jeffrey
2011/03/25 21:08:45
Why did you remove the "(dyu@chromium.org)"? It s
dyu1
2011/03/26 04:15:41
Done.
| |
230 raw_input() | |
231 | |
232 | |
150 def AutofillCrowdsourcing(self): | 233 def AutofillCrowdsourcing(self): |
151 """Test able to send POST request of web form to Autofill server. | 234 """Test able to send POST request of web form to Autofill server. |
152 | 235 |
153 The Autofill server processes the data offline, so it can take a few days | 236 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. | 237 for the result to be detectable. Manual verification is required. |
155 """ | 238 """ |
156 # HTML file needs to be run from a specific http:// url to be able to verify | 239 # 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. | 240 # the results a few days later by visiting the same url. |
158 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 241 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
159 # Adding crowdsourcing Autofill profile. | 242 # 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', | 295 merged_profile = os.path.join(self.DataDir(), 'autofill', |
213 'merged-profiles.txt') | 296 'merged-profiles.txt') |
214 profile_dict = self.GetAutofillProfile()['profiles'] | 297 profile_dict = self.GetAutofillProfile()['profiles'] |
215 output = open(merged_profile, 'wb') | 298 output = open(merged_profile, 'wb') |
216 pickle.dump(profile_dict, output) | 299 pickle.dump(profile_dict, output) |
217 output.close() | 300 output.close() |
218 | 301 |
219 | 302 |
220 if __name__ == '__main__': | 303 if __name__ == '__main__': |
221 pyauto_functional.Main() | 304 pyauto_functional.Main() |
OLD | NEW |