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

Unified 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: Use weakptr. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/input_method/background.js
diff --git a/chrome/test/data/extensions/api_test/input_method/background.js b/chrome/test/data/extensions/api_test/input_method/background.js
index 044779a5a784cb23f5f5e21b272a905d85ce334f..e7a8d50bae4a4e1268454f597907a1c9eed1ec9c 100644
--- a/chrome/test/data/extensions/api_test/input_method/background.js
+++ b/chrome/test/data/extensions/api_test/input_method/background.js
@@ -99,18 +99,14 @@ function getListTest() {
});
}
-function initDictionaryNotLoadedTest() {
- // This test must come first because the dictionary is only lazy loaded after
- // this call is made.
- chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) {
- chrome.test.assertTrue(words === undefined);
- chrome.test.assertTrue(!!chrome.runtime.lastError);
- chrome.test.succeed();
+function fetchDictionaryTests() {
+ var fetchWordsPromise = new Promise(function(resolve, reject) {
+ chrome.inputMethodPrivate.onDictionaryLoaded.addListener(function() {
+ chrome.inputMethodPrivate.fetchAllDictionaryWords(resolve);
+ });
+ chrome.inputMethodPrivate.fetchAllDictionaryWords(resolve);
});
-}
-
-function initDictionaryTests() {
- chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) {
+ fetchWordsPromise.then(function(words) {
chrome.test.assertTrue(words !== undefined);
chrome.test.assertTrue(words.length === 0);
chrome.test.succeed();
@@ -118,17 +114,29 @@ function initDictionaryTests() {
}
function addWordToDictionaryTest() {
- chrome.inputMethodPrivate.addWordToDictionary('helloworld', function() {
+ var wordToAdd = 'helloworld';
+ chrome.inputMethodPrivate.addWordToDictionary(wordToAdd, function() {
chrome.inputMethodPrivate.fetchAllDictionaryWords(function(words) {
chrome.test.assertTrue(words.length === 1);
- chrome.test.assertEq(words[0], 'helloworld');
+ chrome.test.assertEq(words[0], wordToAdd);
chrome.test.succeed();
});
});
}
+function dictionaryChangedTest() {
+ var wordToAdd = 'helloworld2';
+ chrome.inputMethodPrivate.onDictionaryChanged.addListener(
+ function(added, removed) {
+ chrome.test.assertTrue(added.length === 1);
+ chrome.test.assertTrue(removed.length === 0);
+ chrome.test.assertEq(added[0], wordToAdd);
+ chrome.test.succeed();
+ });
+ chrome.inputMethodPrivate.addWordToDictionary(wordToAdd);
+}
+
chrome.test.sendMessage('ready');
chrome.test.runTests(
[initTests, setTest, getTest, observeTest, setInvalidTest, getListTest,
- initDictionaryNotLoadedTest, initDictionaryTests,
- addWordToDictionaryTest]);
+ fetchDictionaryTests, addWordToDictionaryTest, dictionaryChangedTest]);

Powered by Google App Engine
This is Rietveld 408576698