Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) | |
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 # self.log_error( | 77 # self.log_error( |
| 66 # 'check_process %s' % process, | 78 # 'check_process %s' % process, |
| 67 # 'Process %s running with super-user flag' % | 79 # 'Process %s running with super-user flag' % |
| 68 # process) | 80 # process) |
| 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 |
| 87 | |
|
Zachary Kuznia
2010/11/17 03:17:46
Nit: 2 lines between functions.
timothe
2010/11/17 04:06:57
Done.
| |
| 75 # TODO: Get rid of this function. | 88 # TODO: Get rid of this function. |
| 76 def run_ibusclient(self, options): | 89 def run_ibusclient(self, options): |
| 77 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos') | 90 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos') |
| 78 return utils.system_output(cmd, retain_output=True) | 91 return utils.system_output(cmd, retain_output=True) |
| 79 | 92 |
|
Zachary Kuznia
2010/11/17 03:17:46
Nit: 2 lines between function.
timothe
2010/11/17 04:06:57
Done.
| |
| 80 | |
| 81 # TODO: Make this function talk to chrome directly | 93 # TODO: Make this function talk to chrome directly |
| 82 def preload_engines(self, engine_list): | 94 def preload_engines(self, engine_list): |
| 83 engine_names = string.join(engine_list, " ") | 95 engine_names = string.join(engine_list, " ") |
| 84 out = self.run_ibusclient('preload_engines %s' % engine_names) | 96 out = self.run_ibusclient('preload_engines %s' % engine_names) |
| 85 if not 'OK' in out: | 97 if not 'OK' in out: |
| 86 self.log_error('preload_engines %s' % engine_names, | 98 self.log_error('preload_engines %s' % engine_names, |
| 87 'Failed to preload engines: %s' % engine_names) | 99 'Failed to preload engines: %s' % engine_names) |
| 88 | 100 |
| 89 | 101 |
| 90 # TODO: Make this function talk to chrome directly | 102 # TODO: Make this function talk to chrome directly |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 ax.send_hotkey('Ctrl+t') | 163 ax.send_hotkey('Ctrl+t') |
| 152 time.sleep(1) | 164 time.sleep(1) |
| 153 ax.send_hotkey('Ctrl+l') | 165 ax.send_hotkey('Ctrl+l') |
| 154 time.sleep(1) | 166 time.sleep(1) |
| 155 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' % | 167 ax.send_text('chrome://settings/language#lang=%s,focus=%s\n' % |
| 156 (language, engine)) | 168 (language, engine)) |
| 157 time.sleep(3) | 169 time.sleep(3) |
| 158 | 170 |
| 159 # Toggle the checkbox. | 171 # Toggle the checkbox. |
| 160 ax.send_text(' ') | 172 ax.send_text(' ') |
| 161 time.sleep(1) | 173 time.sleep(2) |
| 162 | 174 |
| 163 # Close the window. | 175 # Close the window. |
| 164 ax.send_hotkey('Ctrl+w') | 176 ax.send_hotkey('Ctrl+w') |
| 165 time.sleep(1) | 177 time.sleep(1) |
| 166 | 178 |
| 167 | 179 |
| 168 def stop_ime_language(self, language): | 180 def stop_ime_language(self, language): |
| 169 """ | 181 """ |
| 170 Remove a language from Chrome's preferred list and disable all its IMEs. | 182 Remove a language from Chrome's preferred list and disable all its IMEs. |
| 171 | 183 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 expected_initial_engine = 'xkb:us::eng' | 256 expected_initial_engine = 'xkb:us::eng' |
| 245 expected_other_engine = 'xkb:us:altgr-intl:eng' | 257 expected_other_engine = 'xkb:us:altgr-intl:eng' |
| 246 | 258 |
| 247 current_engine = self.get_active_engine() | 259 current_engine = self.get_active_engine() |
| 248 if current_engine != expected_initial_engine: | 260 if current_engine != expected_initial_engine: |
| 249 self.log_error('test_keyboard_shortcut', | 261 self.log_error('test_keyboard_shortcut', |
| 250 'Initial engine is %s, expected %s' % | 262 'Initial engine is %s, expected %s' % |
| 251 (current_engine, expected_initial_engine)) | 263 (current_engine, expected_initial_engine)) |
| 252 ax = self.get_autox() | 264 ax = self.get_autox() |
| 253 ax.send_hotkey('Ctrl-l') | 265 ax.send_hotkey('Ctrl-l') |
| 266 # If we don't sleep here sometimes the following keys are not received | |
| 267 time.sleep(1) | |
| 254 ax.send_hotkey('Ctrl-space') | 268 ax.send_hotkey('Ctrl-space') |
| 255 start_time = time.time() | 269 start_time = time.time() |
| 256 while time.time() - start_time < 10: | 270 while time.time() - start_time < 10: |
| 257 current_engine = self.get_active_engine() | 271 current_engine = self.get_active_engine() |
| 258 if current_engine == expected_other_engine: | 272 if current_engine == expected_other_engine: |
| 259 ax.send_hotkey('Ctrl-space') | 273 ax.send_hotkey('Ctrl-space') |
| 260 return | 274 return |
| 261 time.sleep(1) | 275 time.sleep(1) |
| 262 self.log_error('test_keyboard_shortcut', | 276 self.log_error('test_keyboard_shortcut', |
| 263 'Current engine is %s, expected %s' % | 277 'Current engine is %s, expected %s' % |
| 264 (current_engine, expected_other_engine)) | 278 (current_engine, expected_other_engine)) |
| 265 | 279 |
| 266 | 280 |
| 267 def test_engine(self, language, engine_name, input_string, expected_string): | 281 def test_engine(self, language, engine_name, input_string, expected_string): |
| 268 self.start_ime_engine(language, engine_name) | 282 self.start_ime_engine(language, engine_name) |
| 269 self.activate_engine(engine_name) | 283 self.activate_engine(engine_name) |
| 284 self.test_engine_omnibox(language, engine_name, input_string, | |
| 285 expected_string) | |
| 286 self.test_engine_form(language, engine_name, input_string, | |
| 287 expected_string) | |
| 288 self.activate_engine('xkb:us::eng') | |
| 289 self.stop_ime_language(language) | |
| 270 | 290 |
| 291 | |
| 292 def test_engine_omnibox(self, language, engine_name, input_string, | |
| 293 expected_string): | |
| 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)) |
| 311 # Clear the omnibox for future tests. | |
| 312 ax.send_hotkey('BackSpace') | |
| 313 | |
| 314 | |
| 315 def test_engine_form(self, language, engine_name, input_string, | |
| 316 expected_string): | |
| 317 ax = self.get_autox() | |
| 318 # Go to the page containing the form. | |
| 288 self.activate_engine('xkb:us::eng') | 319 self.activate_engine('xkb:us::eng') |
| 289 self.stop_ime_language(language) | 320 ax.send_hotkey("Ctrl+l") |
| 321 time.sleep(1) | |
| 322 ax.send_text("%s \n"%self._test_url) | |
|
Zachary Kuznia
2010/11/17 03:17:46
Nit: Add spaces around '%'
timothe
2010/11/17 04:06:57
Done.
| |
| 323 time.sleep(1) | |
| 324 self.activate_engine(engine_name) | |
| 325 | |
| 326 ax.send_text(input_string) | |
| 327 text = self.get_current_text() | |
| 328 if text != expected_string: | |
| 329 self.log_error( | |
| 330 'test_engine %s in form' % engine_name, | |
| 331 'Engine %s failed : Got %s, expected %s' % ( | |
| 332 engine_name, text, expected_string)) | |
| 290 | 333 |
| 291 | 334 |
| 292 def run_once(self): | 335 def run_once(self): |
| 293 self._failed = [] | 336 self._failed = [] |
| 294 dep = 'ibusclient' | 337 dep = 'ibusclient' |
| 295 dep_dir = os.path.join(self.autodir, 'deps', dep) | 338 dep_dir = os.path.join(self.autodir, 'deps', dep) |
| 296 self.job.install_pkg(dep, 'dep', dep_dir) | 339 self.job.install_pkg(dep, 'dep', dep_dir) |
| 297 | 340 |
| 298 self.exefile = os.path.join(self.autodir, | 341 self.exefile = os.path.join(self.autodir, |
| 299 'deps/ibusclient/ibusclient') | 342 'deps/ibusclient/ibusclient') |
| 300 | 343 |
| 301 # Before we try to activate the options menu, we need to wait for | 344 # Before we try to activate the options menu, we need to wait for |
| 302 # previous actions to complete. Most notable is that keystrokes | 345 # previous actions to complete. Most notable is that keystrokes |
| 303 # immediately after login get lost. | 346 # immediately after login get lost. |
| 304 time.sleep(5) | 347 time.sleep(5) |
| 305 | 348 |
| 306 self.test_ibus_start_process() | 349 self.test_ibus_start_process() |
| 307 | 350 |
| 308 self.check_process('candidate_window', user='chronos') | 351 self.check_process('candidate_window', user='chronos') |
| 309 self.check_process('ibus-daemon', user='chronos') | 352 self.check_process('ibus-daemon', user='chronos') |
| 310 self.check_process('ibus-memconf', user='chronos') | 353 self.check_process('ibus-memconf', user='chronos') |
| 311 | 354 |
| 312 self.test_keyboard_shortcut() | 355 self.test_keyboard_shortcut() |
| 313 self.test_engine('ja', 'mozc', 'nihongo \n', | 356 self.test_engine('ja', 'mozc', 'nihongo \n', |
| 314 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E') | 357 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E') |
| 315 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D') | 358 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D') |
| 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 ', |
| 318 '\xE4\xBD\xA0\xE5\xA5\xBD') | 361 '\xE4\xBD\xA0\xE5\xA5\xBD') |
| 319 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa', '\xE9\x96\x93') | 362 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa ', '\xE9\x96\x93') |
| 320 | 363 |
| 321 self.test_ibus_stop_process() | 364 self.test_ibus_stop_process() |
| 365 | |
| 322 if len(self._failed) != 0: | 366 if len(self._failed) != 0: |
| 323 raise error.TestFail( | 367 raise error.TestFail( |
| 324 'Failed: %s' % ','.join(self._failed)) | 368 'Failed: %s' % ','.join(self._failed)) |
| OLD | NEW |