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

Side by Side Diff: chrome/test/data/extensions/api_test/input_method/background.js

Issue 973213003: Adds extension events for custom dictionary load/change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Remove extra braces. Created 5 years, 9 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
OLDNEW
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 kNewInputMethodTemplate = '_comp_ime_{EXT_ID}xkb:fr::fra'; 5 var kNewInputMethodTemplate = '_comp_ime_{EXT_ID}xkb:fr::fra';
6 var kInitialInputMethodRegex = /_comp_ime_([a-z]{32})xkb:us::eng/; 6 var kInitialInputMethodRegex = /_comp_ime_([a-z]{32})xkb:us::eng/;
7 var kInvalidInputMethod = 'xx::xxx'; 7 var kInvalidInputMethod = 'xx::xxx';
8 8
9 var testParams = { 9 var testParams = {
10 initialInputMethod: '', 10 initialInputMethod: '',
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 foundInitialInputMethod = true; 92 foundInitialInputMethod = true;
93 if (inputMethods[i].id == testParams.newInputMethod) 93 if (inputMethods[i].id == testParams.newInputMethod)
94 foundNewInputMethod = true; 94 foundNewInputMethod = true;
95 } 95 }
96 chrome.test.assertTrue(foundInitialInputMethod); 96 chrome.test.assertTrue(foundInitialInputMethod);
97 chrome.test.assertTrue(foundNewInputMethod); 97 chrome.test.assertTrue(foundNewInputMethod);
98 chrome.test.succeed(); 98 chrome.test.succeed();
99 }); 99 });
100 } 100 }
101 101
102 function initDictionaryNotLoadedTest() { 102 function fetchDictionaryTests() {
103 // This test must come first because the dictionary is only lazy loaded after 103 var fetchWordsPromise = new Promise(function(resolve, reject) {
104 // this call is made. 104 chrome.inputMethodPrivate.onDictionaryLoaded.addListener(function() {
105 chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) { 105 chrome.inputMethodPrivate.fetchAllDictionaryWords(resolve);
106 chrome.test.assertTrue(words === undefined); 106 });
107 chrome.test.assertTrue(!!chrome.runtime.lastError); 107 chrome.inputMethodPrivate.fetchAllDictionaryWords(resolve);
108 chrome.test.succeed();
109 }); 108 });
110 } 109 fetchWordsPromise.then(function(words) {
111
112 function initDictionaryTests() {
113 chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) {
114 chrome.test.assertTrue(words !== undefined); 110 chrome.test.assertTrue(words !== undefined);
115 chrome.test.assertTrue(words.length === 0); 111 chrome.test.assertTrue(words.length === 0);
116 chrome.test.succeed(); 112 chrome.test.succeed();
117 }); 113 });
118 } 114 }
119 115
120 function addWordToDictionaryTest() { 116 function addWordToDictionaryTest() {
121 chrome.inputMethodPrivate.addWordToDictionary('helloworld', function() { 117 var wordToAdd = 'helloworld';
118 chrome.inputMethodPrivate.addWordToDictionary(wordToAdd, function() {
122 chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) { 119 chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) {
123 chrome.test.assertTrue(words.length === 1); 120 chrome.test.assertTrue(words.length === 1);
124 chrome.test.assertEq(words[0], 'helloworld'); 121 chrome.test.assertEq(words[0], wordToAdd);
125 chrome.test.succeed(); 122 chrome.test.succeed();
126 }); 123 });
127 }); 124 });
128 } 125 }
129 126
127 function dictionaryChangedTest() {
128 var wordToAdd = 'helloworld2';
129 chrome.inputMethodPrivate.onDictionaryChanged.addListener(
130 function(added, removed) {
131 chrome.test.assertTrue(added.length === 1);
132 chrome.test.assertTrue(removed.length === 0);
133 chrome.test.assertEq(added[0], wordToAdd);
134 chrome.test.succeed();
135 });
136 chrome.inputMethodPrivate.addWordToDictionary(wordToAdd);
137 }
138
130 chrome.test.sendMessage('ready'); 139 chrome.test.sendMessage('ready');
131 chrome.test.runTests( 140 chrome.test.runTests(
132 [initTests, setTest, getTest, observeTest, setInvalidTest, getListTest, 141 [initTests, setTest, getTest, observeTest, setInvalidTest, getListTest,
133 initDictionaryNotLoadedTest, initDictionaryTests, 142 fetchDictionaryTests, addWordToDictionaryTest, dictionaryChangedTest]);
134 addWordToDictionaryTest]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698