| 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 logging, os, re, string, time | 5 import logging, os, re, string, time |
| 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 |
| 8 | 8 |
| 9 def wait_for_ibus_daemon_or_die(timeout=10): | |
| 10 # Wait until ibus-daemon starts. ibus-daemon starts after a user | |
| 11 # logs in (see src/platform/init for details), hence it's not | |
| 12 # guaranteed that ibus-daemon is running when the test starts. | |
| 13 start_time = time.time() | |
| 14 while time.time() - start_time < timeout: | |
| 15 if os.system('pgrep ^ibus-daemon$') == 0: # Returns 0 on success. | |
| 16 return | |
| 17 time.sleep(1) | |
| 18 raise error.TestFail('ibus-daemon is not running') | |
| 19 | |
| 20 | |
| 21 class desktopui_IBusTest(site_ui_test.UITest): | 9 class desktopui_IBusTest(site_ui_test.UITest): |
| 22 version = 1 | 10 version = 1 |
| 23 preserve_srcdir = True | 11 preserve_srcdir = True |
| 24 | 12 |
| 25 def setup(self): | 13 def setup(self): |
| 14 self._ibus_job = None |
| 15 self._candidate_window_job = None |
| 26 self.job.setup_dep(['ibusclient']) | 16 self.job.setup_dep(['ibusclient']) |
| 27 | 17 |
| 28 | 18 |
| 29 def run_ibusclient(self, options): | 19 def run_ibusclient(self, options): |
| 30 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos') | 20 cmd = site_ui.xcommand_as('%s %s' % (self.exefile, options), 'chronos') |
| 31 return utils.system_output(cmd, retain_output=True) | 21 return utils.system_output(cmd, retain_output=True) |
| 32 | 22 |
| 33 | 23 |
| 34 def test_reachable(self): | 24 def test_reachable(self): |
| 35 out = self.run_ibusclient('check_reachable') | 25 out = self.run_ibusclient('check_reachable') |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 out = self.run_ibusclient('unset_config') | 60 out = self.run_ibusclient('unset_config') |
| 71 if not 'OK' in out: | 61 if not 'OK' in out: |
| 72 raise error.TestFail('Failed to unset %s value from ' | 62 raise error.TestFail('Failed to unset %s value from ' |
| 73 'the ibus config service' % type_name) | 63 'the ibus config service' % type_name) |
| 74 # TODO(yusukes): Add a get_config test here to make sure the value is | 64 # TODO(yusukes): Add a get_config test here to make sure the value is |
| 75 # actually removed. See also http://crosbug.com/2801/. | 65 # actually removed. See also http://crosbug.com/2801/. |
| 76 | 66 |
| 77 | 67 |
| 78 def test_check_unused_ibus_values(self): | 68 def test_check_unused_ibus_values(self): |
| 79 engine_list = ['hangul', 'pinyin', 'mozc', 'chewing'] | 69 engine_list = ['hangul', 'pinyin', 'mozc', 'chewing'] |
| 80 expected_unread = set([# TODO: Uncomment these when mozc loads config | 70 expected_unread = set(['engine/PinyinCorrectPinyin_UEN_UN', |
| 71 'engine/PinyinFuzzyPinyin_Z_ZH', |
| 72 'engine/PinyinFuzzyPinyin_CH_C', |
| 73 'engine/PinyinFuzzyPinyin_S_SH', |
| 74 'engine/PinyinFuzzyPinyin_EN_ENG', |
| 75 'engine/PinyinFuzzyPinyin_AN_ANG', |
| 76 'engine/PinyinFuzzyPinyin_IANG_IAN', |
| 77 'engine/PinyinSpecialPhrases', |
| 78 'engine/PinyinFuzzyPinyin_UAN_UANG', |
| 79 'engine/PinyinFuzzyPinyin_IN_ING', |
| 80 'engine/PinyinFuzzyPinyin_G_K', |
| 81 'engine/PinyinCorrectPinyin_UEI_UI', |
| 82 'engine/PinyinCorrectPinyin_UE_VE', |
| 83 'engine/PinyinFuzzyPinyin_F_H', |
| 84 'engine/PinyinFuzzyPinyin_SH_S', |
| 85 'engine/PinyinIncompletePinyin', |
| 86 'engine/PinyinFuzzyPinyin_L_R', |
| 87 'engine/PinyinFuzzyPinyin_K_G', |
| 88 'engine/PinyinFuzzyPinyin_ANG_AN', |
| 89 'engine/PinyinFuzzyPinyin_C_CH', |
| 90 'engine/PinyinCorrectPinyin_MG_NG', |
| 91 'engine/PinyinLookupTableOrientation', |
| 92 'engine/PinyinFuzzyPinyin_L_N', |
| 93 'engine/PinyinFuzzyPinyin_ING_IN', |
| 94 'engine/PinyinFuzzyPinyin_IAN_IANG', |
| 95 'engine/PinyinFuzzyPinyin_N_L', |
| 96 'engine/PinyinCorrectPinyin_IOU_IU', |
| 97 'engine/PinyinFuzzyPinyin_ENG_EN', |
| 98 'engine/PinyinCorrectPinyin_VE_UE', |
| 99 'engine/PinyinCorrectPinyin_V_U', |
| 100 'engine/PinyinFuzzyPinyin_UANG_UAN', |
| 101 'engine/PinyinDoublePinyinShowRaw', |
| 102 'engine/PinyinFuzzyPinyin_H_F', |
| 103 'engine/PinyinFuzzyPinyin_ZH_Z', |
| 104 'engine/PinyinFuzzyPinyin_R_L', |
| 105 |
| 106 # TODO: Uncomment these when mozc loads config |
| 81 # values from ibus. | 107 # values from ibus. |
| 82 'engine/Mozchistory_learning_level', | 108 'engine/Mozchistory_learning_level', |
| 83 'engine/Mozcincognito_mode', | 109 'engine/Mozcincognito_mode', |
| 84 'engine/Mozcnumpad_character_form', | 110 'engine/Mozcnumpad_character_form', |
| 85 'engine/Mozcpreedit_method', | 111 'engine/Mozcpreedit_method', |
| 86 'engine/Mozcpunctuation_method', | 112 'engine/Mozcpunctuation_method', |
| 87 'engine/Mozcsession_keymap', | 113 'engine/Mozcsession_keymap', |
| 88 'engine/Mozcshift_key_mode_switch', | 114 'engine/Mozcshift_key_mode_switch', |
| 89 'engine/Mozcspace_character_form', | 115 'engine/Mozcspace_character_form', |
| 90 'engine/Mozcsuggestions_size', | 116 'engine/Mozcsuggestions_size', |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 173 |
| 148 # These preferences are actually read, but | 174 # These preferences are actually read, but |
| 149 # ibus-daemon reads them before chrome | 175 # ibus-daemon reads them before chrome |
| 150 # connects, so they show up as a false | 176 # connects, so they show up as a false |
| 151 # failure. | 177 # failure. |
| 152 'general/hotkeynext_engine_in_menu', | 178 'general/hotkeynext_engine_in_menu', |
| 153 'general/hotkeyprevious_engine', | 179 'general/hotkeyprevious_engine', |
| 154 'generalglobal_engine', | 180 'generalglobal_engine', |
| 155 | 181 |
| 156 # We don't set these prefernces. | 182 # We don't set these prefernces. |
| 157 'general/hotkeynext_engine', | |
| 158 'general/hotkeyprev_engine', | |
| 159 'general/hotkeytrigger', | 183 'general/hotkeytrigger', |
| 160 'generalembed_preedit_text', | 184 'generalembed_preedit_text', |
| 161 'generalenable_by_default', | 185 'generalenable_by_default', |
| 162 'generalpreload_engines', | 186 'generalpreload_engines', |
| 163 'generaluse_global_engine', | 187 'generaluse_global_engine', |
| 164 'generaluse_system_keyboard_layout']) | 188 'generaluse_system_keyboard_layout']) |
| 165 | 189 |
| 166 self.preload_engines(engine_list) | 190 self.preload_engines(engine_list) |
| 167 | 191 |
| 192 # ibus takes some time to preload the engines, and they can't be |
| 193 # activated until they are done loading. Since we don't get notified |
| 194 # when they are ready, we have to wait here to give them time. |
| 195 time.sleep(2) |
| 196 |
| 168 # Send a ctrl+l to enter a text field. | 197 # Send a ctrl+l to enter a text field. |
| 169 ax = self.get_autox() | 198 ax = self.get_autox() |
| 170 ax.send_hotkey('Ctrl-l') | 199 ax.send_hotkey('Ctrl-l') |
| 171 | 200 |
| 172 for engine_name in engine_list: | 201 for engine_name in engine_list: |
| 173 self.activate_engine(engine_name) | 202 self.activate_engine(engine_name) |
| 174 | 203 |
| 175 out = self.run_ibusclient('get_unused') | 204 out = self.run_ibusclient('get_unused') |
| 176 match = re.match(r"Unread:(.*)Unwritten:(.*)", out, re.DOTALL) | 205 match = re.match(r"Unread:(.*)Unwritten:(.*)", out, re.DOTALL) |
| 177 if not match: | 206 if not match: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 raise error.TestFail('Failed to preload engines: %s' % engine_names) | 242 raise error.TestFail('Failed to preload engines: %s' % engine_names) |
| 214 | 243 |
| 215 | 244 |
| 216 def activate_engine(self, engine_name): | 245 def activate_engine(self, engine_name): |
| 217 out = self.run_ibusclient('activate_engine %s' % engine_name) | 246 out = self.run_ibusclient('activate_engine %s' % engine_name) |
| 218 if not 'OK' in out: | 247 if not 'OK' in out: |
| 219 raise error.TestFail('Failed to activate engine: %s' % engine_name) | 248 raise error.TestFail('Failed to activate engine: %s' % engine_name) |
| 220 | 249 |
| 221 | 250 |
| 222 def run_once(self): | 251 def run_once(self): |
| 223 wait_for_ibus_daemon_or_die() | 252 self.start_ibus_daemon_or_die() |
| 224 dep = 'ibusclient' | 253 dep = 'ibusclient' |
| 225 dep_dir = os.path.join(self.autodir, 'deps', dep) | 254 dep_dir = os.path.join(self.autodir, 'deps', dep) |
| 226 self.job.install_pkg(dep, 'dep', dep_dir) | 255 self.job.install_pkg(dep, 'dep', dep_dir) |
| 227 | 256 |
| 228 self.exefile = os.path.join(self.autodir, | 257 self.exefile = os.path.join(self.autodir, |
| 229 'deps/ibusclient/ibusclient') | 258 'deps/ibusclient/ibusclient') |
| 230 self.test_reachable() | 259 self.test_reachable() |
| 231 self.test_supported_engines() | 260 self.test_supported_engines() |
| 232 for type_name in ['boolean', 'int', 'double', 'string', 'boolean_list', | 261 for type_name in ['boolean', 'int', 'double', 'string', 'boolean_list', |
| 233 'int_list', 'double_list', 'string_list']: | 262 'int_list', 'double_list', 'string_list']: |
| 234 self.test_config(type_name) | 263 self.test_config(type_name) |
| 235 | 264 |
| 236 self.test_check_unused_ibus_values() | 265 self.test_check_unused_ibus_values() |
| 266 self._ibus_job = None |
| 267 self._candidate_window_job = None |
| 268 utils.system_output("kill -9 `pgrep ^ibus-daemon$`") |
| 269 |
| 270 |
| 271 def start_ibus_daemon_or_die(self, timeout=10): |
| 272 self._ibus_job = utils.BgJob( |
| 273 "su chronos -c '%s'" % |
| 274 "/usr/bin/ibus-daemon --panel=disable --cache=none --restart") |
| 275 time.sleep(2) |
| 276 self._candidate_window_job = utils.BgJob( |
| 277 "su chronos -c '/opt/google/chrome/candidate_window'") |
| 278 start_time = time.time() |
| 279 while time.time() - start_time < timeout: |
| 280 if os.system('pgrep ^ibus-daemon$') == 0: |
| 281 return |
| 282 time.sleep(1) |
| 283 raise error.TestFail('ibus-daemon is not running') |
| OLD | NEW |