Revert "Only store leading 13 bits of password hash."
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / input_method / background.js
blobb9ec5f5726461b1248fba5bb33f644fd0d692a20
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';
9 var testParams = {
10 initialInputMethod: '',
11 newInputMethod: ''
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();
28 });
31 function setTest() {
32 chrome.test.assertTrue(!!testParams.newInputMethod);
33 console.log(
34 'setTest: Changing input method to: ' + testParams.newInputMethod);
35 chrome.inputMethodPrivate.setCurrentInputMethod(testParams.newInputMethod,
36 function() {
37 chrome.test.assertTrue(
38 !chrome.runtime.lastError,
39 chrome.runtime.lastError ? chrome.runtime.lastError.message : '');
40 chrome.test.succeed();
41 });
44 function getTest() {
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();
50 });
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() {
72 console.log(
73 'setInvalidTest: Changing input method to: ' + kInvalidInputMethod);
74 chrome.inputMethodPrivate.setCurrentInputMethod(kInvalidInputMethod,
75 function() {
76 chrome.test.assertTrue(!!chrome.runtime.lastError);
77 chrome.test.succeed();
78 });
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();
99 });
102 chrome.test.sendMessage('ready');
103 chrome.test.runTests(
104 [initTests, setTest, getTest, observeTest, setInvalidTest, getListTest]);