Index: chrome/browser/ui/webui/options/edit_dictionary_browsertest.js |
diff --git a/chrome/browser/ui/webui/options/edit_dictionary_browsertest.js b/chrome/browser/ui/webui/options/edit_dictionary_browsertest.js |
index 0e1522149982debd094ed4bc2b05e5f0b4f740db..ad8ce8052cb0af597a5d4cc537b36b144433c779 100644 |
--- a/chrome/browser/ui/webui/options/edit_dictionary_browsertest.js |
+++ b/chrome/browser/ui/webui/options/edit_dictionary_browsertest.js |
@@ -35,6 +35,7 @@ EditDictionaryWebUITest.prototype = { |
}, |
}; |
+// Verify that users can add and remove words in the dictionary. |
TEST_F('EditDictionaryWebUITest', 'testAddRemoveWords', function() { |
var testWord = 'foo'; |
$('language-dictionary-overlay-word-list').querySelector('input').value = |
@@ -54,6 +55,7 @@ TEST_F('EditDictionaryWebUITest', 'testAddRemoveWords', function() { |
EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(0); |
}); |
+// Verify that users can search words in the dictionary. |
TEST_F('EditDictionaryWebUITest', 'testSearch', function() { |
EditDictionaryOverlay.setWordList(['foo', 'bar']); |
expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); |
@@ -73,3 +75,50 @@ TEST_F('EditDictionaryWebUITest', 'testSearch', function() { |
fakeSearchEvent(searchField, ''); |
expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); |
}); |
+ |
+// Verify that dictionary shows newly added words that arrived in a |
+// notification, but ignores duplicate add notifications. |
+TEST_F('EditDictionaryWebUITest', 'testAddNotification', function() { |
+ // Begin with an empty dictionary. |
+ EditDictionaryOverlay.setWordList([]); |
+ expectEquals(1, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // User adds word 'foo'. |
+ EditDictionaryOverlay.getWordListForTesting().addDictionaryWord_('foo'); |
+ expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // Backend notifies UI that the word 'foo' has been added. UI ignores this |
+ // notification, because the word is displayed immediately after user added |
+ // it. |
+ EditDictionaryOverlay.updateWords(['foo'], []); |
+ expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // Backend notifies UI that the words 'bar' and 'baz' were added. UI shows |
+ // these new words. |
+ EditDictionaryOverlay.updateWords(['bar', 'baz'], []); |
+ expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); |
+}); |
+ |
+// Verify that dictionary hides newly removed words that arrived in a |
+// notification, but ignores duplicate remove notifications. |
+TEST_F('EditDictionaryWebUITest', 'testRemoveNotification', function() { |
+ // Begin with a dictionary with words 'foo', 'bar', 'baz', and 'baz'. The |
+ // second instance of 'baz' appears because the user added the word twice. |
+ // The backend keeps only one copy of the word. |
+ EditDictionaryOverlay.setWordList(['foo', 'bar', 'baz', 'baz']); |
+ expectEquals(5, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // User deletes the second instance of 'baz'. |
+ EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(3); |
+ expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // Backend notifies UI that the word 'baz' has been removed. UI ignores this |
+ // notification. |
+ EditDictionaryOverlay.updateWords([], ['baz']); |
+ expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); |
+ |
+ // Backend notifies UI that words 'foo' and 'bar' have been removed. UI |
+ // removes these words. |
+ EditDictionaryOverlay.updateWords([], ['foo', 'bar']); |
+ expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); |
+}); |