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 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 |
| 14 | 15 |
| 15 class AutoFillTest(pyauto.PyUITest): | 16 class AutoFillTest(pyauto.PyUITest): |
| 16 """Tests that autofill works correctly""" | 17 """Tests that autofill works correctly""" |
| 17 | 18 |
| 18 def Debug(self): | 19 def Debug(self): |
| 19 """Test method for experimentation. | 20 """Test method for experimentation. |
| 20 | 21 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 js_code = """ | 141 js_code = """ |
| 141 document.getElementById("merge_dup").submit(); | 142 document.getElementById("merge_dup").submit(); |
| 142 window.addEventListener("unload", function() { | 143 window.addEventListener("unload", function() { |
| 143 window.domAutomationController.send("done"); | 144 window.domAutomationController.send("done"); |
| 144 }); | 145 }); |
| 145 """ | 146 """ |
| 146 self.ExecuteJavascript(js_code, 0, 0) | 147 self.ExecuteJavascript(js_code, 0, 0) |
| 147 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: | 148 if 'EMAIL_ADDRESS' in self.GetAutofillProfile()['profiles'][0]: |
| 148 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') | 149 raise KeyError('TEST FAIL: Malformed email address is saved in profiles.') |
| 149 | 150 |
| 151 def testComparePhoneNumbers(self): | |
| 152 """Test phone fields parses correctly from a given profile.""" | |
| 153 profile_path = os.path.join(self.DataDir(), 'autofill', | |
| 154 'phone_pinput_autofill.txt') | |
| 155 profile_expected_path = os.path.join(self.DataDir(), 'autofill', | |
| 156 'phone_pexpected_autofill.txt') | |
| 157 profiles = self.EvalDataFrom(profile_path) | |
| 158 profiles_expected = self.EvalDataFrom(profile_expected_path) | |
| 159 tab_keypress=0x09 | |
| 160 down_keypress=0x28 | |
| 161 return_keypress=0x0D | |
|
dennis_jeffrey
2011/03/18 21:44:01
I think the above 3 lines are better declared as n
dyu1
2011/03/21 18:42:35
Done.
| |
| 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 self.SendKeyEvent(tab_keypress, windex=0, tab_index=0) | |
|
dennis_jeffrey
2011/03/18 21:44:01
Could you add a comment to explain what you're doi
dyu1
2011/03/21 18:42:35
I thought the named variables was self explanatory
| |
| 168 self.SendKeyEvent(down_keypress, windex=0, tab_index=0) | |
| 169 self.SendKeyEvent(down_keypress, windex=0, tab_index=0) | |
| 170 self.SendKeyEvent(return_keypress, windex=0, tab_index=0) | |
| 171 raw_input() | |
|
dennis_jeffrey
2011/03/18 21:44:01
This line shouldn't be here in an automated test,
dyu1
2011/03/21 18:42:35
Left it in for debugging but removed it in my last
| |
| 172 form_values = {} | |
| 173 for key, value in profile_expected.iteritems(): | |
| 174 js_returning_field_value = ( | |
| 175 'var field_value = document.getElementById("%s").value;' | |
| 176 'window.domAutomationController.send(field_value);' | |
| 177 ) % key | |
| 178 form_values[key] = self.ExecuteJavascript( | |
| 179 js_returning_field_value, 0, 0) | |
| 180 self.assertEqual( | |
| 181 form_values[key], value, | |
| 182 'Original profile not equal to expected profile at key: "%s" \ | |
| 183 \nExpected: "%s"\nReturned: "%s"' % (key, value, form_values[key])) | |
|
dennis_jeffrey
2011/03/18 21:44:01
Rather than using "\" to continue the string onto
dyu1
2011/03/21 18:42:35
Done.
| |
| 184 | |
| 185 def FormFillLatencyAfterSubmit(self): | |
|
dennis_jeffrey
2011/03/18 21:44:01
Shouldn't this function name begin with the substr
dyu1
2011/03/21 18:42:35
Since this test is only partially automated I didn
| |
| 186 """Test latency time on form submit with lots of stored Autofill profiles. | |
| 187 | |
| 188 This test verifies when a profile is selected from the Autofill dictionary, | |
|
dennis_jeffrey
2011/03/18 21:44:01
Remove the comma at the end of this line.
dyu1
2011/03/21 18:42:35
Done.
| |
| 189 that consists of thousands of profiles, the form does not hang after being | |
| 190 submitted. | |
| 191 """ | |
| 192 # HTML file needs to be run from a http:// url. | |
| 193 url = self.GetHttpURLForDataPath( | |
| 194 os.path.join('autofill', 'latency_after_submit_test.html')) | |
| 195 # Run the generator script to generate the dictionary list needed for the | |
| 196 # profiles. | |
| 197 gen = autofill_dataset_generator.DatasetGenerator( | |
| 198 logging_level=logging.ERROR) # Set verbosity to INFO, WARNING, ERROR. | |
| 199 list_of_dict = gen.GenerateDataset(num_of_records_to_generate=50) | |
|
dennis_jeffrey
2011/03/18 21:44:01
Does this mean you're generating 50 profiles? The
dyu1
2011/03/21 18:42:35
Only left 50 for testing purposes. Will change to
| |
| 200 self.FillAutofillProfile(profiles=list_of_dict) | |
| 201 tab_keypress=0x09 | |
| 202 down_keypress=0x28 | |
| 203 return_keypress=0x0D | |
|
dennis_jeffrey
2011/03/18 21:44:01
Perhaps better as constants defined at the top of
dyu1
2011/03/21 18:42:35
Done.
| |
| 204 self.NavigateToURL(url) | |
| 205 self.SendKeyEvent(tab_keypress, windex=0, tab_index=0) | |
|
dennis_jeffrey
2011/03/18 21:44:01
Add a comment to describe what this sequence of ke
dyu1
2011/03/21 18:42:35
Done.
| |
| 206 self.SendKeyEvent(down_keypress, windex=0, tab_index=0) | |
| 207 self.SendKeyEvent(down_keypress, windex=0, tab_index=0) | |
| 208 self.SendKeyEvent(return_keypress, windex=0, tab_index=0) | |
| 209 # Requires manual intervention to test the performance time after submitted | |
|
dennis_jeffrey
2011/03/18 21:44:01
"submitted" --> "submitting"
dyu1
2011/03/21 18:42:35
Done.
| |
| 210 # the form. | |
| 211 raw_input() | |
|
dennis_jeffrey
2011/03/18 21:44:01
Is it considered acceptable to check in PyAuto tes
dyu1
2011/03/21 18:42:35
Yes, should be fine as Nir approved of two other t
| |
| 212 | |
| 213 | |
| 150 def AutofillCrowdsourcing(self): | 214 def AutofillCrowdsourcing(self): |
| 151 """Test able to send POST request of web form to Autofill server. | 215 """Test able to send POST request of web form to Autofill server. |
| 152 | 216 |
| 153 The Autofill server processes the data offline, so it can take a few days | 217 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. | 218 for the result to be detectable. Manual verification is required. |
| 155 """ | 219 """ |
| 156 # HTML file needs to be run from a specific http:// url to be able to verify | 220 # 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. | 221 # the results a few days later by visiting the same url. |
| 158 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' | 222 url = 'http://www.corp.google.com/~dyu/autofill/crowdsourcing-test.html' |
| 159 # Adding crowdsourcing Autofill profile. | 223 # 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', | 276 merged_profile = os.path.join(self.DataDir(), 'autofill', |
| 213 'merged-profiles.txt') | 277 'merged-profiles.txt') |
| 214 profile_dict = self.GetAutofillProfile()['profiles'] | 278 profile_dict = self.GetAutofillProfile()['profiles'] |
| 215 output = open(merged_profile, 'wb') | 279 output = open(merged_profile, 'wb') |
| 216 pickle.dump(profile_dict, output) | 280 pickle.dump(profile_dict, output) |
| 217 output.close() | 281 output.close() |
| 218 | 282 |
| 219 | 283 |
| 220 if __name__ == '__main__': | 284 if __name__ == '__main__': |
| 221 pyauto_functional.Main() | 285 pyauto_functional.Main() |
| OLD | NEW |