OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 var kNewInputMethod = "fr::fra"; | 5 var kOldInputMethod = "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng"; |
| 6 var kNewInputMethod = "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:fr::fra"; |
| 7 var kInvalidInputMethod = "xx::xxx"; |
6 | 8 |
7 function setAndGetTest() { | 9 // The tests needs to be executed in order. |
8 console.log('Changing input method to: ' + kNewInputMethod); | 10 |
9 chrome.test.sendMessage('setInputMethod:' + kNewInputMethod, | 11 function setTest() { |
10 function (response) { | 12 console.log('setTest: Changing input method to: ' + kNewInputMethod); |
11 chrome.test.assertEq('done', response); | 13 chrome.inputMethodPrivate.setCurrentInputMethod(kNewInputMethod, |
12 console.log('Getting current input method.'); | 14 function(success) { |
13 chrome.inputMethodPrivate.get(function (inputMethod) { | 15 chrome.test.assertTrue(success); |
14 chrome.test.assertEq(kNewInputMethod, inputMethod); | 16 chrome.test.succeed(); |
15 chrome.test.succeed(); | 17 }); |
16 } | 18 } |
17 ); | 19 |
| 20 function getTest() { |
| 21 console.log('getTest: Getting current input method.'); |
| 22 chrome.inputMethodPrivate.getCurrentInputMethod(function(inputMethod) { |
| 23 chrome.test.assertEq(kNewInputMethod, inputMethod); |
18 }); | 24 }); |
19 } | 25 } |
20 | 26 |
21 function setAndObserveTest() { | 27 function observeTest() { |
22 console.log('Adding input method event listener.'); | 28 console.log('observeTest: Adding input method event listener.'); |
23 chrome.inputMethodPrivate.onChanged.addListener( | 29 chrome.inputMethodPrivate.onChanged.addListener(function(subfix) { |
24 function(newInputMethod) { | 30 chrome.test.assertEq('us::eng', subfix); |
25 chrome.test.assertEq(kNewInputMethod, newInputMethod); | 31 chrome.test.succeed(); |
| 32 }); |
| 33 console.log('observeTest: Changing input method to: ' + kOldInputMethod); |
| 34 chrome.inputMethodPrivate.setCurrentInputMethod(kOldInputMethod); |
| 35 } |
| 36 |
| 37 |
| 38 function setInvalidTest() { |
| 39 console.log( |
| 40 'setInvalidTest: Changing input method to: ' + kInvalidInputMethod); |
| 41 chrome.inputMethodPrivate.setCurrentInputMethod(kInvalidInputMethod, |
| 42 function(success) { |
| 43 chrome.test.assertFalse(success); |
26 chrome.test.succeed(); | 44 chrome.test.succeed(); |
| 45 }); |
| 46 } |
| 47 |
| 48 function getListTest() { |
| 49 console.log('getListTest: Getting input method list.'); |
| 50 chrome.inputMethodPrivate.getInputMethods(function(inputMethods) { |
| 51 chrome.test.assertEq(6, inputMethods.length); |
| 52 var foundOldInputMethod = false; |
| 53 var foundNewInputMethod = false; |
| 54 for (var i = 0; i < inputMethods.length; ++i) { |
| 55 if (inputMethods[i].id == kOldInputMethod) |
| 56 foundOldInputMethod = true; |
| 57 if (inputMethods[i].id == kNewInputMethod) |
| 58 foundNewInputMethod = true; |
27 } | 59 } |
28 ); | 60 chrome.test.assertTrue(foundOldInputMethod); |
29 console.log('Changing input method to: ' + kNewInputMethod); | 61 chrome.test.assertTrue(foundNewInputMethod); |
30 chrome.test.sendMessage('setInputMethod:' + kNewInputMethod, | 62 chrome.test.succeed(); |
31 function (response) { | 63 }); |
32 chrome.test.assertEq('done', response); | |
33 } | |
34 ); | |
35 } | 64 } |
36 | 65 |
37 chrome.test.sendMessage('ready'); | 66 chrome.test.sendMessage('ready'); |
38 chrome.test.runTests([setAndGetTest, setAndObserveTest]); | 67 chrome.test.runTests( |
| 68 [setTest, getTest, observeTest, setInvalidTest, getListTest]); |
OLD | NEW |