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._test_server = site_httpd.HTTPListener(8000, docroot=self.bindir) |
| 21 self._test_server.run() |
| 22 |
| 23 site_ui_test.UITest.initialize(self, creds) |
| 24 |
| 25 |
| 26 def cleanup(self): |
| 27 self._test_server.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 123 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 # The toggling can take longer than 1 sec. |
| 174 time.sleep(2) |
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 Loading... |
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, |
| 294 expected_string): |
271 ax = self.get_autox() | 295 ax = self.get_autox() |
272 | 296 |
273 # Focus on the omnibox so that we can enter text. | 297 # Focus on the omnibox so that we can enter text. |
274 ax.send_hotkey('Ctrl-l') | 298 ax.send_hotkey('Ctrl-l') |
275 | 299 |
276 # Sometimes there is a slight delay before input can be received in the | 300 # Sometimes there is a slight delay before input can be received in the |
277 # omnibox. | 301 # omnibox. |
278 time.sleep(1) | 302 time.sleep(1) |
279 | 303 |
280 ax.send_text(input_string) | 304 ax.send_text(input_string) |
281 | 305 |
282 text = self.get_current_text() | 306 text = self.get_current_text() |
283 if text != expected_string: | 307 if text != expected_string: |
284 self.log_error( | 308 self.log_error( |
285 'test_engine %s' % engine_name, | 309 'test_engine %s in omnibox' % engine_name, |
286 'Engine %s failed: Got %s, expected %s' % (engine_name, text, | 310 'Engine %s failed : Got %s, expected %s' % ( |
287 expected_string)) | 311 engine_name, text, expected_string)) |
| 312 # Clear the omnibox for future tests. |
| 313 ax.send_hotkey('BackSpace') |
| 314 |
| 315 |
| 316 def test_engine_form(self, language, engine_name, input_string, |
| 317 expected_string): |
| 318 ax = self.get_autox() |
| 319 # Go to the page containing the form. |
288 self.activate_engine('xkb:us::eng') | 320 self.activate_engine('xkb:us::eng') |
289 self.stop_ime_language(language) | 321 ax.send_hotkey("Ctrl+l") |
| 322 time.sleep(1) |
| 323 ax.send_text("%s \n" % self._test_url) |
| 324 time.sleep(1) |
| 325 self.activate_engine(engine_name) |
| 326 |
| 327 ax.send_text(input_string) |
| 328 text = self.get_current_text() |
| 329 if text != expected_string: |
| 330 self.log_error( |
| 331 'test_engine %s in form' % engine_name, |
| 332 'Engine %s failed : Got %s, expected %s' % ( |
| 333 engine_name, text, expected_string)) |
290 | 334 |
291 | 335 |
292 def run_once(self): | 336 def run_once(self): |
293 self._failed = [] | 337 self._failed = [] |
294 dep = 'ibusclient' | 338 dep = 'ibusclient' |
295 dep_dir = os.path.join(self.autodir, 'deps', dep) | 339 dep_dir = os.path.join(self.autodir, 'deps', dep) |
296 self.job.install_pkg(dep, 'dep', dep_dir) | 340 self.job.install_pkg(dep, 'dep', dep_dir) |
297 | 341 |
298 self.exefile = os.path.join(self.autodir, | 342 self.exefile = os.path.join(self.autodir, |
299 'deps/ibusclient/ibusclient') | 343 'deps/ibusclient/ibusclient') |
300 | 344 |
301 # Before we try to activate the options menu, we need to wait for | 345 # Before we try to activate the options menu, we need to wait for |
302 # previous actions to complete. Most notable is that keystrokes | 346 # previous actions to complete. Most notable is that keystrokes |
303 # immediately after login get lost. | 347 # immediately after login get lost. |
304 time.sleep(5) | 348 time.sleep(5) |
305 | 349 |
306 self.test_ibus_start_process() | 350 self.test_ibus_start_process() |
307 | 351 |
308 self.check_process('candidate_window', user='chronos') | 352 self.check_process('candidate_window', user='chronos') |
309 self.check_process('ibus-daemon', user='chronos') | 353 self.check_process('ibus-daemon', user='chronos') |
310 self.check_process('ibus-memconf', user='chronos') | 354 self.check_process('ibus-memconf', user='chronos') |
311 | 355 |
312 self.test_keyboard_shortcut() | 356 self.test_keyboard_shortcut() |
313 self.test_engine('ja', 'mozc', 'nihongo \n', | 357 self.test_engine('ja', 'mozc', 'nihongo \n', |
314 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E') | 358 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E') |
315 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D') | 359 self.test_engine('zh-TW', 'chewing', 'hol \n', '\xE6\x93\x8D') |
316 self.test_engine('ko', 'hangul', 'wl ', '\xEC\xA7\x80 ') | 360 self.test_engine('ko', 'hangul', 'wl ', '\xEC\xA7\x80 ') |
317 self.test_engine('zh-CN', 'pinyin', 'nihao ', | 361 self.test_engine('zh-CN', 'pinyin', 'nihao ', |
318 '\xE4\xBD\xA0\xE5\xA5\xBD') | 362 '\xE4\xBD\xA0\xE5\xA5\xBD') |
319 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa', '\xE9\x96\x93') | 363 self.test_engine('zh-TW', 'm17n:zh:quick', 'aa ', '\xE9\x96\x93') |
320 | 364 |
321 self.test_ibus_stop_process() | 365 self.test_ibus_stop_process() |
| 366 |
322 if len(self._failed) != 0: | 367 if len(self._failed) != 0: |
323 raise error.TestFail( | 368 raise error.TestFail( |
324 'Failed: %s' % ','.join(self._failed)) | 369 'Failed: %s' % ','.join(self._failed)) |
OLD | NEW |