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]); |