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

Side by Side Diff: chrome/browser/ui/webui/options/edit_dictionary_browsertest.js

Issue 11968050: Show dictionary changes in chrome://settings/editDictionary as changes come in (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * TestFixture for EditDictionaryOverlay WebUI testing. 6 * TestFixture for EditDictionaryOverlay WebUI testing.
7 * @extends {testing.Test} 7 * @extends {testing.Test}
8 * @constructor 8 * @constructor
9 **/ 9 **/
10 function EditDictionaryWebUITest() {} 10 function EditDictionaryWebUITest() {}
(...skipping 17 matching lines...) Expand all
28 ]); 28 ]);
29 this.mockHandler.stubs().refreshDictionaryWords(). 29 this.mockHandler.stubs().refreshDictionaryWords().
30 will(callFunction(function() { 30 will(callFunction(function() {
31 EditDictionaryOverlay.setWordList([]); 31 EditDictionaryOverlay.setWordList([]);
32 })); 32 }));
33 this.mockHandler.stubs().addDictionaryWord(ANYTHING); 33 this.mockHandler.stubs().addDictionaryWord(ANYTHING);
34 this.mockHandler.stubs().removeDictionaryWord(ANYTHING); 34 this.mockHandler.stubs().removeDictionaryWord(ANYTHING);
35 }, 35 },
36 }; 36 };
37 37
38 // Verify that users can add and remove words in the dictionary.
38 TEST_F('EditDictionaryWebUITest', 'testAddRemoveWords', function() { 39 TEST_F('EditDictionaryWebUITest', 'testAddRemoveWords', function() {
39 var testWord = 'foo'; 40 var testWord = 'foo';
40 $('language-dictionary-overlay-word-list').querySelector('input').value = 41 $('language-dictionary-overlay-word-list').querySelector('input').value =
41 testWord; 42 testWord;
42 43
43 this.mockHandler.expects(once()).addDictionaryWord([testWord]). 44 this.mockHandler.expects(once()).addDictionaryWord([testWord]).
44 will(callFunction(function() { 45 will(callFunction(function() {
45 EditDictionaryOverlay.setWordList([testWord]); 46 EditDictionaryOverlay.setWordList([testWord]);
46 })); 47 }));
47 var addWordItem = EditDictionaryOverlay.getWordListForTesting().items[0]; 48 var addWordItem = EditDictionaryOverlay.getWordListForTesting().items[0];
48 addWordItem.onEditCommitted_({currentTarget: addWordItem}); 49 addWordItem.onEditCommitted_({currentTarget: addWordItem});
49 50
50 this.mockHandler.expects(once()).removeDictionaryWord([testWord]). 51 this.mockHandler.expects(once()).removeDictionaryWord([testWord]).
51 will(callFunction(function() { 52 will(callFunction(function() {
52 EditDictionaryOverlay.setWordList([]); 53 EditDictionaryOverlay.setWordList([]);
53 })); 54 }));
54 EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(0); 55 EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(0);
55 }); 56 });
56 57
58 // Verify that users can search words in the dictionary.
57 TEST_F('EditDictionaryWebUITest', 'testSearch', function() { 59 TEST_F('EditDictionaryWebUITest', 'testSearch', function() {
58 EditDictionaryOverlay.setWordList(['foo', 'bar']); 60 EditDictionaryOverlay.setWordList(['foo', 'bar']);
59 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); 61 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length);
60 62
61 /** 63 /**
62 * @param {Element} el The element to dispatch an event on. 64 * @param {Element} el The element to dispatch an event on.
63 * @param {string} value The text of the search event. 65 * @param {string} value The text of the search event.
64 */ 66 */
65 var fakeSearchEvent = function(el, value) { 67 var fakeSearchEvent = function(el, value) {
66 el.value = value; 68 el.value = value;
67 cr.dispatchSimpleEvent(el, 'search'); 69 cr.dispatchSimpleEvent(el, 'search');
68 }; 70 };
69 var searchField = $('language-dictionary-overlay-search-field'); 71 var searchField = $('language-dictionary-overlay-search-field');
70 fakeSearchEvent(searchField, 'foo'); 72 fakeSearchEvent(searchField, 'foo');
71 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); 73 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length);
72 74
73 fakeSearchEvent(searchField, ''); 75 fakeSearchEvent(searchField, '');
74 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); 76 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length);
75 }); 77 });
78
79 // Verify that dictionary shows newly added words that arrived in a
80 // notification, but ignores duplicate add notifications.
81 TEST_F('EditDictionaryWebUITest', 'testAddNotification', function() {
82 // Begin with an empty dictionary.
83 EditDictionaryOverlay.setWordList([]);
84 expectEquals(1, EditDictionaryOverlay.getWordListForTesting().items.length);
85
86 // User adds word 'foo'.
87 EditDictionaryOverlay.getWordListForTesting().addDictionaryWord_('foo');
88 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length);
89
90 // Backend notifies UI that the word 'foo' has been added. UI ignores this
91 // notification, because the word is displayed immediately after user added
92 // it.
93 EditDictionaryOverlay.updateWords(['foo'], []);
94 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length);
95
96 // Backend notifies UI that the words 'bar' and 'baz' were added. UI shows
97 // these new words.
98 EditDictionaryOverlay.updateWords(['bar', 'baz'], []);
99 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length);
100 });
101
102 // Verify that dictionary hides newly removed words that arrived in a
103 // notification, but ignores duplicate remove notifications.
104 TEST_F('EditDictionaryWebUITest', 'testRemoveNotification', function() {
105 // Begin with a dictionary with words 'foo', 'bar', 'baz', and 'baz'. The
106 // second instance of 'baz' appears because the user added the word twice.
107 // The backend keeps only one copy of the word.
108 EditDictionaryOverlay.setWordList(['foo', 'bar', 'baz', 'baz']);
109 expectEquals(5, EditDictionaryOverlay.getWordListForTesting().items.length);
110
111 // User deletes the second instance of 'baz'.
112 EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(3);
113 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length);
114
115 // Backend notifies UI that the word 'baz' has been removed. UI ignores this
116 // notification.
117 EditDictionaryOverlay.updateWords([], ['baz']);
118 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length);
119
120 // Backend notifies UI that words 'foo' and 'bar' have been removed. UI
121 // removes these words.
122 EditDictionaryOverlay.updateWords([], ['foo', 'bar']);
123 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length);
124 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698