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

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

Issue 3391007: Add autotests to check that the IME works. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git
Patch Set: Comment the sleeps. Created 10 years, 3 months 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
« no previous file with comments | « client/site_tests/desktopui_ImeTest/control ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import os, string, time, gtk
6 from autotest_lib.client.bin import site_ui_test, test
7 from autotest_lib.client.common_lib import error, site_ui, utils
8
9
10 class desktopui_ImeTest(site_ui_test.UITest):
11 version = 1
12 preserve_srcdir = True
13
14 def setup(self):
15 # TODO: We shouldn't use ibusclient, we should talk to Chrome directly
16 self.job.setup_dep(['ibusclient'])
17
18
19 # TODO: Get rid of this function.
20 def run_ibusclient(self, options):
21 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos')
22 return utils.system_output(cmd, retain_output=True)
23
24
25 # TODO: Make this function talk to chrome directly
26 def preload_engines(self, engine_list):
27 engine_names = string.join(engine_list, " ")
28 out = self.run_ibusclient('preload_engines %s' % engine_names)
29 if not 'OK' in out:
30 raise error.TestFail('Failed to preload engines: %s' % engine_names)
31
32 # ibus takes some time to preload the engines, and they can't be
33 # activated until they are done loading. Since we don't get notified
34 # when they are ready, we have to wait here to give them time.
35 time.sleep(2)
36
37
38 # TODO: Make this function talk to chrome directly
39 def activate_engine(self, engine_name):
40 out = self.run_ibusclient('activate_engine %s' % engine_name)
41 if not 'OK' in out:
42 raise error.TestFail('Failed to activate engine: %s' % engine_name)
43
44
45 # TODO: Make this function set the config value directly, instead of
46 # attempting to navigate the UI.
47 def toggle_ime_process(self):
48 # Before we try to activate the options menu, we need to wait for
49 # previous actions to complete. Most notably is that pressing F5
50 # immediately after login gets lost.
51 time.sleep(3)
52 ax = self.get_autox()
53
54 # Open the config dialog.
55 ax.send_hotkey('F5')
56 time.sleep(2)
57
58 # Select the "Languages and Input" button.
59 ax.send_text('\t\t\t\t\t\t\t\t\t\t\t ')
60
61 # Select the "International keyboard" checkbox.
62 ax.send_text('\t\t\t\t\t\t ')
63
64 # Close the window.
65 ax.send_hotkey('Ctrl+w')
66 time.sleep(1)
67
68
69 def get_current_text(self):
70 # Because there can be a slight delay between entering text and the
71 # output from the ime being received, we need to sleep here.
72 time.sleep(1)
73 ax = self.get_autox()
74
75 # Select all the text so that it can be accessed via the clipboard.
76 ax.send_hotkey('Ctrl-a')
77 time.sleep(1)
78
79 # The DISPLAY environment variable isn't set, so we have to manually get
80 # the proper display.
81 display = gtk.gdk.Display(":0.0")
82
83 clip = gtk.Clipboard(display, "PRIMARY")
84 return clip.wait_for_text()
85
86
87 def test_ibus_start_process(self):
88 # Check that enabling the IME launches ibus.
89 self.toggle_ime_process()
90 success = False
91 start_time = time.time()
92 while time.time() - start_time < 10:
93 if os.system('pgrep ^ibus-daemon$') == 0:
94 success = True
95 break
96 time.sleep(1)
97 if not success:
98 raise error.TestFail('ibus-daemon did not start via config')
99
100
101 def test_ibus_stop_process(self):
102 # Check that disabling the IME stops ibus.
103 self.toggle_ime_process()
104 success = False
105 start_time = time.time()
106 while time.time() - start_time < 10:
107 if os.system('pgrep ^ibus-daemon$') != 0:
108 success = True
109 break
110 time.sleep(1)
111 if not success:
112 raise error.TestFail('ibus-daemon did not stop via config')
113
114
115 def test_engine(self, engine_name, input_string, expected_string):
116 self.preload_engines([engine_name])
117 self.activate_engine(engine_name)
118
119 ax = self.get_autox()
120
121 # Focus on the omnibox so that we can enter text.
122 ax.send_hotkey('Ctrl-l')
123
124 ax.send_text(input_string)
125
126 text = self.get_current_text()
127 if text != expected_string:
128 raise error.TestFail(
129 'Engine %s failed: Got %s, expected %s' % (engine_name, text,
130 expected_string))
131
132
133 def run_once(self):
134 dep = 'ibusclient'
135 dep_dir = os.path.join(self.autodir, 'deps', dep)
136 self.job.install_pkg(dep, 'dep', dep_dir)
137
138 self.exefile = os.path.join(self.autodir,
139 'deps/ibusclient/ibusclient')
140
141 self.test_ibus_start_process()
142 self.test_engine('mozc', 'nihongo \n',
143 '\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E')
144 self.test_engine('chewing', 'hol \n', '\xE6\x93\x8D')
145 self.test_engine('hangul', 'wl ', '\xEC\xA7\x80 ')
146 self.test_engine('pinyin', 'nihao ', '\xE4\xBD\xA0\xE5\xA5\xBD')
147 self.test_ibus_stop_process()
OLDNEW
« no previous file with comments | « client/site_tests/desktopui_ImeTest/control ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698