1 // Copyright (c) 2011 The Chromium 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.
5 var kNewInputMethodTemplate = '_comp_ime_{EXT_ID}xkb:fr::fra';
6 var kInitialInputMethodRegex = /_comp_ime_([a-z]{32})xkb:us::eng/;
7 var kInvalidInputMethod = 'xx::xxx';
10 initialInputMethod: '',
14 // The tests needs to be executed in order.
16 function initTests() {
17 console.log('initTest: Getting initial inputMethod');
18 chrome.inputMethodPrivate.getCurrentInputMethod(function(inputMethod) {
19 testParams.initialInputMethod = inputMethod;
21 var match = inputMethod.match(kInitialInputMethodRegex);
22 chrome.test.assertTrue(!!match);
23 chrome.test.assertEq(2, match.length);
24 var extensionId = match[1];
25 testParams.newInputMethod =
26 kNewInputMethodTemplate.replace('{EXT_ID}', extensionId);
27 chrome.test.succeed();
32 chrome.test.assertTrue(!!testParams.newInputMethod);
34 'setTest: Changing input method to: ' + testParams.newInputMethod);
35 chrome.inputMethodPrivate.setCurrentInputMethod(testParams.newInputMethod,
37 chrome.test.assertTrue(
38 !chrome.runtime.lastError,
39 chrome.runtime.lastError ? chrome.runtime.lastError.message : '');
40 chrome.test.succeed();
45 chrome.test.assertTrue(!!testParams.newInputMethod);
46 console.log('getTest: Getting current input method.');
47 chrome.inputMethodPrivate.getCurrentInputMethod(function(inputMethod) {
48 chrome.test.assertEq(testParams.newInputMethod, inputMethod);
49 chrome.test.succeed();
53 function observeTest() {
54 chrome.test.assertTrue(!!testParams.initialInputMethod);
55 console.log('observeTest: Adding input method event listener.');
57 var listener = function(subfix) {
58 chrome.inputMethodPrivate.onChanged.removeListener(listener);
59 chrome.test.assertEq('us::eng', subfix);
60 chrome.test.succeed();
62 chrome.inputMethodPrivate.onChanged.addListener(listener);
64 console.log('observeTest: Changing input method to: ' +
65 testParams.initialInputMethod);
66 chrome.inputMethodPrivate.setCurrentInputMethod(
67 testParams.initialInputMethod);
71 function setInvalidTest() {
73 'setInvalidTest: Changing input method to: ' + kInvalidInputMethod);
74 chrome.inputMethodPrivate.setCurrentInputMethod(kInvalidInputMethod,
76 chrome.test.assertTrue(!!chrome.runtime.lastError);
77 chrome.test.succeed();
81 function getListTest() {
82 chrome.test.assertTrue(!!testParams.initialInputMethod);
83 chrome.test.assertTrue(!!testParams.newInputMethod);
84 console.log('getListTest: Getting input method list.');
86 chrome.inputMethodPrivate.getInputMethods(function(inputMethods) {
87 chrome.test.assertEq(6, inputMethods.length);
88 var foundInitialInputMethod = false;
89 var foundNewInputMethod = false;
90 for (var i = 0; i < inputMethods.length; ++i) {
91 if (inputMethods[i].id == testParams.initialInputMethod)
92 foundInitialInputMethod = true;
93 if (inputMethods[i].id == testParams.newInputMethod)
94 foundNewInputMethod = true;
96 chrome.test.assertTrue(foundInitialInputMethod);
97 chrome.test.assertTrue(foundNewInputMethod);
98 chrome.test.succeed();
102 chrome.test.sendMessage('ready');
103 chrome.test.runTests(
104 [initTests, setTest, getTest, observeTest, setInvalidTest, getListTest]);