| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 GEN_INCLUDE(['options_browsertest_base.js']); | |
| 6 | |
| 7 /** | |
| 8 * TestFixture for EditDictionaryOverlay WebUI testing. | |
| 9 * @extends {testing.Test} | |
| 10 * @constructor | |
| 11 */ | |
| 12 function EditDictionaryWebUITest() {} | |
| 13 | |
| 14 EditDictionaryWebUITest.prototype = { | |
| 15 __proto__: OptionsBrowsertestBase.prototype, | |
| 16 | |
| 17 /** | |
| 18 * Browse to the edit dictionary page & call our preLoad(). | |
| 19 */ | |
| 20 browsePreload: 'chrome://settings-frame/editDictionary', | |
| 21 | |
| 22 /** | |
| 23 * Register a mock dictionary handler. | |
| 24 */ | |
| 25 preLoad: function() { | |
| 26 this.makeAndRegisterMockHandler( | |
| 27 ['refreshDictionaryWords', | |
| 28 'addDictionaryWord', | |
| 29 'removeDictionaryWord', | |
| 30 ]); | |
| 31 this.mockHandler.stubs().refreshDictionaryWords(). | |
| 32 will(callFunction(function() { | |
| 33 EditDictionaryOverlay.setWordList([]); | |
| 34 })); | |
| 35 this.mockHandler.stubs().addDictionaryWord(ANYTHING); | |
| 36 this.mockHandler.stubs().removeDictionaryWord(ANYTHING); | |
| 37 }, | |
| 38 | |
| 39 /** @override */ | |
| 40 setUp: function() { | |
| 41 OptionsBrowsertestBase.prototype.setUp.call(this); | |
| 42 | |
| 43 // Enable when failure is resolved. | |
| 44 // AX_TEXT_01: http://crbug.com/570556 | |
| 45 this.accessibilityAuditConfig.ignoreSelectors( | |
| 46 'controlsWithoutLabel', | |
| 47 '#language-dictionary-overlay-word-list > .deletable-item > *'); | |
| 48 | |
| 49 var unsupportedAriaAttributeSelectors = [ | |
| 50 '#language-dictionary-overlay-word-list', | |
| 51 '#language-options-list', | |
| 52 ]; | |
| 53 | |
| 54 // Enable when failure is resolved. | |
| 55 // AX_ARIA_10: http://crbug.com/570559 | |
| 56 this.accessibilityAuditConfig.ignoreSelectors( | |
| 57 'unsupportedAriaAttribute', | |
| 58 unsupportedAriaAttributeSelectors); | |
| 59 }, | |
| 60 }; | |
| 61 | |
| 62 // Verify that users can add and remove words in the dictionary. | |
| 63 TEST_F('EditDictionaryWebUITest', 'testAddRemoveWords', function() { | |
| 64 var testWord = 'foo'; | |
| 65 $('language-dictionary-overlay-word-list').querySelector('input').value = | |
| 66 testWord; | |
| 67 | |
| 68 this.mockHandler.expects(once()).addDictionaryWord([testWord]). | |
| 69 will(callFunction(function() { | |
| 70 EditDictionaryOverlay.setWordList([testWord]); | |
| 71 })); | |
| 72 var addWordItem = EditDictionaryOverlay.getWordListForTesting().items[0]; | |
| 73 addWordItem.onEditCommitted_({currentTarget: addWordItem}); | |
| 74 | |
| 75 this.mockHandler.expects(once()).removeDictionaryWord([testWord]). | |
| 76 will(callFunction(function() { | |
| 77 EditDictionaryOverlay.setWordList([]); | |
| 78 })); | |
| 79 EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(0); | |
| 80 }); | |
| 81 | |
| 82 // Verify that users can search words in the dictionary. | |
| 83 TEST_F('EditDictionaryWebUITest', 'testSearch', function() { | |
| 84 EditDictionaryOverlay.setWordList(['foo', 'bar']); | |
| 85 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 86 | |
| 87 /** | |
| 88 * @param {Element} el The element to dispatch an event on. | |
| 89 * @param {string} value The text of the search event. | |
| 90 */ | |
| 91 var fakeSearchEvent = function(el, value) { | |
| 92 el.value = value; | |
| 93 cr.dispatchSimpleEvent(el, 'search'); | |
| 94 }; | |
| 95 var searchField = $('language-dictionary-overlay-search-field'); | |
| 96 fakeSearchEvent(searchField, 'foo'); | |
| 97 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 98 | |
| 99 fakeSearchEvent(searchField, ''); | |
| 100 expectEquals(3, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 101 }); | |
| 102 | |
| 103 TEST_F('EditDictionaryWebUITest', 'testNoCloseOnSearchEnter', function() { | |
| 104 var editDictionaryPage = EditDictionaryOverlay.getInstance(); | |
| 105 assertTrue(editDictionaryPage.visible); | |
| 106 var searchField = $('language-dictionary-overlay-search-field'); | |
| 107 searchField.dispatchEvent(new KeyboardEvent('keydown', { | |
| 108 'bubbles': true, | |
| 109 'cancelable': true, | |
| 110 'key': 'Enter' | |
| 111 })); | |
| 112 assertTrue(editDictionaryPage.visible); | |
| 113 }); | |
| 114 | |
| 115 // Verify that dictionary shows newly added words that arrived in a | |
| 116 // notification, but ignores duplicate add notifications. | |
| 117 TEST_F('EditDictionaryWebUITest', 'testAddNotification', function() { | |
| 118 // Begin with an empty dictionary. | |
| 119 EditDictionaryOverlay.setWordList([]); | |
| 120 expectEquals(1, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 121 | |
| 122 // User adds word 'foo'. | |
| 123 EditDictionaryOverlay.getWordListForTesting().addDictionaryWord_('foo'); | |
| 124 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 125 | |
| 126 // Backend notifies UI that the word 'foo' has been added. UI ignores this | |
| 127 // notification, because the word is displayed immediately after user added | |
| 128 // it. | |
| 129 EditDictionaryOverlay.updateWords(['foo'], []); | |
| 130 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 131 | |
| 132 // Backend notifies UI that the words 'bar' and 'baz' were added. UI shows | |
| 133 // these new words. | |
| 134 EditDictionaryOverlay.updateWords(['bar', 'baz'], []); | |
| 135 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 136 }); | |
| 137 | |
| 138 // Verify that dictionary hides newly removed words that arrived in a | |
| 139 // notification, but ignores duplicate remove notifications. | |
| 140 // TODO(crbug.com/631940): Flaky on Win 7. | |
| 141 GEN('#if defined(OS_WIN)'); | |
| 142 GEN('#define MAYBE_testRemoveNotification DISABLED_testRemoveNotification'); | |
| 143 GEN('#else'); | |
| 144 GEN('#define MAYBE_testRemoveNotification testRemoveNotification'); | |
| 145 GEN('#endif // defined(OS_WIN)'); | |
| 146 TEST_F('EditDictionaryWebUITest', 'MAYBE_testRemoveNotification', function() { | |
| 147 // Begin with a dictionary with words 'foo', 'bar', 'baz', and 'baz'. The | |
| 148 // second instance of 'baz' appears because the user added the word twice. | |
| 149 // The backend keeps only one copy of the word. | |
| 150 EditDictionaryOverlay.setWordList(['foo', 'bar', 'baz', 'baz']); | |
| 151 expectEquals(5, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 152 | |
| 153 // User deletes the second instance of 'baz'. | |
| 154 EditDictionaryOverlay.getWordListForTesting().deleteItemAtIndex(3); | |
| 155 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 156 | |
| 157 // Backend notifies UI that the word 'baz' has been removed. UI ignores this | |
| 158 // notification. | |
| 159 EditDictionaryOverlay.updateWords([], ['baz']); | |
| 160 expectEquals(4, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 161 | |
| 162 // Backend notifies UI that words 'foo' and 'bar' have been removed. UI | |
| 163 // removes these words. | |
| 164 EditDictionaryOverlay.updateWords([], ['foo', 'bar']); | |
| 165 expectEquals(2, EditDictionaryOverlay.getWordListForTesting().items.length); | |
| 166 }); | |
| OLD | NEW |