Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: client/site_tests/desktopui_ImeTest/desktopui_ImeTest.py

Issue 4698007: Added IME tests for web forms (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: testing IME in web forms with the new settings UI and without the Session object causing timeouts Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os, string, time, gtk 5 import os, string, time, gtk
6 from autotest_lib.client.bin import site_ui_test, test 6 from autotest_lib.client.bin import site_ui_test, test
7 from autotest_lib.client.common_lib import error, site_ui, utils 7 from autotest_lib.client.common_lib import error, site_ui, utils, site_httpd
8 8
9 9
10 class desktopui_ImeTest(site_ui_test.UITest): 10 class desktopui_ImeTest(site_ui_test.UITest):
11 version = 1 11 version = 1
12 preserve_srcdir = True 12 preserve_srcdir = True
13 13
14 def setup(self): 14 def setup(self):
15 # TODO: We shouldn't use ibusclient, we should talk to Chrome directly 15 # TODO: We shouldn't use ibusclient, we should talk to Chrome directly
16 self.job.setup_dep(['ibusclient']) 16 self.job.setup_dep(['ibusclient'])
17 17
18 def initialize(self, creds='$default'):
19 self._test_url = 'http://localhost:8000/interaction_form.html'
20 self._testServer = site_httpd.HTTPListener(8000, docroot=self.bindir)
satorux1 2010/11/17 04:35:38 _test_server per our python style guide.
timothe 2010/11/17 05:04:12 Done.
21 self._testServer.run()
22
23 site_ui_test.UITest.initialize(self, creds)
24
25
26 def cleanup(self):
27 self._testServer.stop()
28 site_ui_test.UITest.cleanup(self)
29
18 30
19 def log_error(self, test_name, message): 31 def log_error(self, test_name, message):
20 self.job.record('ERROR', None, test_name, message) 32 self.job.record('ERROR', None, test_name, message)
21 self._failed.append(test_name) 33 self._failed.append(test_name)
22 34
23 35
24 # TODO(zork) We should share this with platform_ProcessPrivleges. 36 # TODO(zork) We should share this with platform_ProcessPrivleges.
25 # See: crosbug.com/7453 37 # See: crosbug.com/7453
26 def check_process(self, process, user=None): 38 def check_process(self, process, user=None):
27 """Check if the process is running as the specified user / root. 39 """Check if the process is running as the specified user / root.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if 'root' in ps: 81 if 'root' in ps:
70 self.log_error('check_process %s' % process, 82 self.log_error('check_process %s' % process,
71 'Process %s running as root' % process) 83 'Process %s running as root' % process)
72 return 84 return
73 85
74 86
75 # TODO: Get rid of this function. 87 # TODO: Get rid of this function.
76 def run_ibusclient(self, options): 88 def run_ibusclient(self, options):
77 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos') 89 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos')
78 return utils.system_output(cmd, retain_output=True) 90 return utils.system_output(cmd, retain_output=True)
79 91
Zachary Kuznia 2010/11/16 10:22:58 This blank line should go back in.
timothe 2010/11/17 01:47:05 Done.
80
81 # TODO: Make this function talk to chrome directly 92 # TODO: Make this function talk to chrome directly
82 def preload_engines(self, engine_list): 93 def preload_engines(self, engine_list):
83 engine_names = string.join(engine_list, " ") 94 engine_names = string.join(engine_list, " ")
84 out = self.run_ibusclient('preload_engines %s' % engine_names) 95 out = self.run_ibusclient('preload_engines %s' % engine_names)
85 if not 'OK' in out: 96 if not 'OK' in out:
86 self.log_error('preload_engines %s' % engine_names, 97 self.log_error('preload_engines %s' % engine_names,
87 'Failed to preload engines: %s' % engine_names) 98 'Failed to preload engines: %s' % engine_names)
88 99
89 100
90 # TODO: Make this function talk to chrome directly 101 # TODO: Make this function talk to chrome directly
91 def activate_engine(self, engine_name): 102 def activate_engine(self, engine_name):
92 start_time = time.time() 103 start_time = time.time()
93 while time.time() - start_time < 10: 104 while time.time() - start_time < 10:
94 out = self.run_ibusclient('activate_engine %s' % engine_name) 105 out = self.run_ibusclient('activate_engine %s' % engine_name)
95 if 'OK' in out and self.get_active_engine() == engine_name: 106 if 'OK' in out and self.get_active_engine() == engine_name:
96 return 107 return
97 time.sleep(1) 108 time.sleep(1)
98 self.log_error('activate_engine', 109 self.log_error('activate_engine',
99 'Failed to activate engine: %s' % engine_name) 110 'Failed to activate engine: %s' % engine_name)
100 111
101 112
102 def get_active_engine(self): 113 def get_active_engine(self):
103 out = self.run_ibusclient('get_active_engine') 114 out = self.run_ibusclient('get_active_engine')
104 return out.strip() 115 return out.strip()
105 116
106 117
118 # TODO: Make this function set the config value directly, instead of
119 # attempting to navigate the UI.
Zachary Kuznia 2010/11/16 10:22:58 This comment shouldn't be re-added.
timothe 2010/11/17 01:47:05 Done.
107 def toggle_ime_process(self): 120 def toggle_ime_process(self):
108 ax = self.get_autox() 121 ax = self.get_autox()
109 122
110 # Open the config dialog. 123 # Open the config dialog.
111 ax.send_hotkey('Ctrl+t') 124 ax.send_hotkey('Ctrl+t')
112 time.sleep(1) 125 time.sleep(1)
113 ax.send_hotkey('Ctrl+l') 126 ax.send_hotkey('Ctrl+l')
114 time.sleep(1) 127 time.sleep(1)
115 # Navigate to the "Languages and Input" menu. 128 # Navigate to the "Languages and Input" menu.
116 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' % 129 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' %
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 ax.send_hotkey('Ctrl+t') 164 ax.send_hotkey('Ctrl+t')
152 time.sleep(1) 165 time.sleep(1)
153 ax.send_hotkey('Ctrl+l') 166 ax.send_hotkey('Ctrl+l')
154 time.sleep(1) 167 time.sleep(1)
155 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' % 168 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' %
156 (language, engine)) 169 (language, engine))
157 time.sleep(3) 170 time.sleep(3)
158 171
159 # Toggle the checkbox. 172 # Toggle the checkbox.
160 ax.send_text(' ') 173 ax.send_text(' ')
161 time.sleep(1) 174 time.sleep(2)
Zachary Kuznia 2010/11/16 10:22:58 This value shouldn't need to change. Was it faili
timothe 2010/11/17 01:47:05 on my PC sometimes yes, the new language would not
Zachary Kuznia 2010/11/17 03:17:46 Ok. Add a comment to note this.
timothe 2010/11/17 04:06:57 Done.
162 175
163 # Close the window. 176 # Close the window.
164 ax.send_hotkey('Ctrl+w') 177 ax.send_hotkey('Ctrl+w')
165 time.sleep(1) 178 time.sleep(1)
166 179
167 180
168 def stop_ime_language(self, language): 181 def stop_ime_language(self, language):
169 """ 182 """
170 Remove a language from Chrome's preferred list and disable all its IMEs. 183 Remove a language from Chrome's preferred list and disable all its IMEs.
171 184
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 expected_initial_engine = 'xkb:us::eng' 257 expected_initial_engine = 'xkb:us::eng'
245 expected_other_engine = 'xkb:us:altgr-intl:eng' 258 expected_other_engine = 'xkb:us:altgr-intl:eng'
246 259
247 current_engine = self.get_active_engine() 260 current_engine = self.get_active_engine()
248 if current_engine != expected_initial_engine: 261 if current_engine != expected_initial_engine:
249 self.log_error('test_keyboard_shortcut', 262 self.log_error('test_keyboard_shortcut',
250 'Initial engine is %s, expected %s' % 263 'Initial engine is %s, expected %s' %
251 (current_engine, expected_initial_engine)) 264 (current_engine, expected_initial_engine))
252 ax = self.get_autox() 265 ax = self.get_autox()
253 ax.send_hotkey('Ctrl-l') 266 ax.send_hotkey('Ctrl-l')
267 # If we don't sleep here sometimes the following keys are not received
268 time.sleep(1)
254 ax.send_hotkey('Ctrl-space') 269 ax.send_hotkey('Ctrl-space')
255 start_time = time.time() 270 start_time = time.time()
256 while time.time() - start_time < 10: 271 while time.time() - start_time < 10:
257 current_engine = self.get_active_engine() 272 current_engine = self.get_active_engine()
258 if current_engine == expected_other_engine: 273 if current_engine == expected_other_engine:
259 ax.send_hotkey('Ctrl-space') 274 ax.send_hotkey('Ctrl-space')
260 return 275 return
261 time.sleep(1) 276 time.sleep(1)
262 self.log_error('test_keyboard_shortcut', 277 self.log_error('test_keyboard_shortcut',
263 'Current engine is %s, expected %s' % 278 'Current engine is %s, expected %s' %
264 (current_engine, expected_other_engine)) 279 (current_engine, expected_other_engine))
265 280
266 281
267 def test_engine(self, language, engine_name, input_string, expected_string): 282 def test_engine(self, language, engine_name, input_string, expected_string):
268 self.start_ime_engine(language, engine_name) 283 self.start_ime_engine(language, engine_name)
269 self.activate_engine(engine_name) 284 self.activate_engine(engine_name)
285 self.test_engine_omnibox(language, engine_name, input_string,
286 expected_string)
287 self.test_engine_form(language, engine_name, input_string,
288 expected_string)
289 self.activate_engine('xkb:us::eng')
290 self.stop_ime_language(language)
270 291
292
293 def test_engine_omnibox(self, language, engine_name, input_string, expected_ string):
Zachary Kuznia 2010/11/16 10:22:58 nit: 80 characters.
timothe 2010/11/17 01:47:05 Done.
271 ax = self.get_autox() 294 ax = self.get_autox()
272 295
273 # Focus on the omnibox so that we can enter text. 296 # Focus on the omnibox so that we can enter text.
274 ax.send_hotkey('Ctrl-l') 297 ax.send_hotkey('Ctrl-l')
275 298
276 # Sometimes there is a slight delay before input can be received in the 299 # Sometimes there is a slight delay before input can be received in the
277 # omnibox. 300 # omnibox.
278 time.sleep(1) 301 time.sleep(1)
279 302
280 ax.send_text(input_string) 303 ax.send_text(input_string)
281 304
282 text = self.get_current_text() 305 text = self.get_current_text()
283 if text != expected_string: 306 if text != expected_string:
284 self.log_error( 307 self.log_error(
285 'test_engine %s' % engine_name, 308 'test_engine %s in omnibox' % engine_name,
286 'Engine %s failed: Got %s, expected %s' % (engine_name, text, 309 'Engine %s failed : Got %s, expected %s' % (
287 expected_string)) 310 engine_name, text, expected_string))
288 self.activate_engine('xkb:us::eng') 311 #clear the omnibox for future tests
Zachary Kuznia 2010/11/16 10:22:58 Nit: Space after #, capitalize Clear, add a period
timothe 2010/11/17 01:47:05 Done.
289 self.stop_ime_language(language) 312 ax.send_hotkey('BackSpace')
313
314
315 def test_engine_form(self, language, engine_name, input_string, expected_str ing):
Zachary Kuznia 2010/11/16 10:22:58 Nit: 80 characters
timothe 2010/11/17 01:47:05 Done.
316 ax = self.get_autox()
317 # Refresh the page so that the focus gets on the text input widget
318 ax.send_hotkey('Ctrl-r')
Zachary Kuznia 2010/11/16 10:22:58 Navigate to the page here, so that it relies less
timothe 2010/11/17 01:47:05 Done.
319 time.sleep(1)
320 ax.send_text(input_string)
321 text = self.get_current_text()
322 if text != expected_string:
323 self.log_error(
324 'test_engine %s in form' % engine_name,
325 'Engine %s failed : Got %s, expected %s' % (
326 engine_name, text, expected_string))
290 327
291 328
292 def run_once(self): 329 def run_once(self):
293 self._failed = [] 330 self._failed = []
294 dep = 'ibusclient' 331 dep = 'ibusclient'
295 dep_dir = os.path.join(self.autodir, 'deps', dep) 332 dep_dir = os.path.join(self.autodir, 'deps', dep)
296 self.job.install_pkg(dep, 'dep', dep_dir) 333 self.job.install_pkg(dep, 'dep', dep_dir)
297 334
298 self.exefile = os.path.join(self.autodir, 335 self.exefile = os.path.join(self.autodir,
299 'deps/ibusclient/ibusclient') 336 'deps/ibusclient/ibusclient')
300 337
301 # Before we try to activate the options menu, we need to wait for 338 # Before we try to activate the options menu, we need to wait for
302 # previous actions to complete. Most notable is that keystrokes 339 # previous actions to complete. Most notable is that keystrokes
303 # immediately after login get lost. 340 # immediately after login get lost.
304 time.sleep(5) 341 time.sleep(5)
305 342
343 # Navigate to the webpage containing the form
Zachary Kuznia 2010/11/16 10:22:58 See above.
timothe 2010/11/17 01:47:05 Done.
344 ax = self.get_autox()
345 ax.send_hotkey('Ctrl+l')
346 time.sleep(1)
347 ax.send_text("%s \n"%self._test_url)
306 self.test_ibus_start_process() 348 self.test_ibus_start_process()
307 349
308 self.check_process('candidate_window', user='chronos') 350 self.check_process('candidate_window', user='chronos')
309 self.check_process('ibus-daemon', user='chronos') 351 self.check_process('ibus-daemon', user='chronos')
310 self.check_process('ibus-memconf', user='chronos') 352 self.check_process('ibus-memconf', user='chronos')
311 353
312 self.test_keyboard_shortcut() 354 self.test_keyboard_shortcut()
313 self.test_engine('ja', 'mozc', 'nihongo \n', 355 self.test_engine('ja', 'mozc', 'nihongo \n',
314 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E') 356 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E')
315 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D') 357 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D')
358 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa ', '\xE9\x96\x93')
Zachary Kuznia 2010/11/16 10:22:58 Leave these in the original order to minimize your
timothe 2010/11/17 01:47:05 Done.
316 self.test_engine('ko', 'hangul', 'wl ', '\xEC\xA7\x80 ') 359 self.test_engine('ko', 'hangul', 'wl ', '\xEC\xA7\x80 ')
317 self.test_engine('zh-CN', 'pinyin', 'nihao ', 360 self.test_engine('zh-CN', 'pinyin', 'nihao ', '\xE4\xBD\xA0\xE5\xA5\xBD' )
Zachary Kuznia 2010/11/16 10:22:58 nit: 80 characters.
timothe 2010/11/17 01:47:05 Done.
318 '\xE4\xBD\xA0\xE5\xA5\xBD')
319 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa', '\xE9\x96\x93')
320 361
321 self.test_ibus_stop_process() 362 self.test_ibus_stop_process()
363
322 if len(self._failed) != 0: 364 if len(self._failed) != 0:
323 raise error.TestFail( 365 raise error.TestFail(
324 'Failed: %s' % ','.join(self._failed)) 366 'Failed: %s' % ','.join(self._failed))
OLDNEW
« no previous file with comments | « client/site_tests/desktopui_ImeTest/control ('k') | client/site_tests/desktopui_ImeTest/interaction_form.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698