OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 cr.define('settings_search_engines_page', function() { | 5 cr.define('settings_search_engines_page', function() { |
6 /** | 6 /** |
7 * @param {boolean} canBeDefault | 7 * @param {boolean} canBeDefault |
8 * @param {boolean} canBeEdited | 8 * @param {boolean} canBeEdited |
9 * @param {boolean} canBeRemoved | 9 * @param {boolean} canBeRemoved |
10 * @return {!SearchEngine} | 10 * @return {!SearchEngine} |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return browserProxy.whenCalled('searchEngineEditStarted').then( | 81 return browserProxy.whenCalled('searchEngineEditStarted').then( |
82 function() { | 82 function() { |
83 MockInteractions.tap(dialog.$.cancel); | 83 MockInteractions.tap(dialog.$.cancel); |
84 return browserProxy.whenCalled('searchEngineEditCancelled'); | 84 return browserProxy.whenCalled('searchEngineEditCancelled'); |
85 }); | 85 }); |
86 }); | 86 }); |
87 | 87 |
88 // Tests the dialog to add a new search engine. Specifically | 88 // Tests the dialog to add a new search engine. Specifically |
89 // - paper-input elements are empty initially. | 89 // - paper-input elements are empty initially. |
90 // - action button initially disabled. | 90 // - action button initially disabled. |
91 // - validation is triggered on 'focus'. 'change' is not teted because | 91 // - validation is triggered on 'input' event. |
92 // MockInteractions does not currently provide a way to trigger such | |
93 // events. | |
94 // - action button is enabled when all fields are valid. | 92 // - action button is enabled when all fields are valid. |
95 // - action button triggers appropriate browser signal when tapped. | 93 // - action button triggers appropriate browser signal when tapped. |
96 test('DialogAddSearchEngine', function() { | 94 test('DialogAddSearchEngine', function() { |
97 /** | 95 /** |
98 * Focuses the given paper-input element and checks that validation is | 96 * Triggers an 'input' event on the paper-input element and checks that |
99 * triggered. | 97 * validation is triggered. |
100 * @param {string} inputId | 98 * @param {string} inputId |
101 * @return {!Promise} | 99 * @return {!Promise} |
102 */ | 100 */ |
103 var focusAndValidate = function(inputId) { | 101 var inputAndValidate = function(inputId) { |
| 102 var inputElement = dialog.$[inputId]; |
104 browserProxy.resetResolver('validateSearchEngineInput'); | 103 browserProxy.resetResolver('validateSearchEngineInput'); |
105 MockInteractions.focus(dialog.$[inputId]); | 104 inputElement.fire('input'); |
106 return browserProxy.whenCalled('validateSearchEngineInput'); | 105 return inputElement.value != '' ? |
| 106 // Expeting validation only on non-empty values. |
| 107 browserProxy.whenCalled('validateSearchEngineInput') : |
| 108 Promise.resolve(); |
107 }; | 109 }; |
108 | 110 |
109 assertEquals('', dialog.$.searchEngine.value); | 111 assertEquals('', dialog.$.searchEngine.value); |
110 assertEquals('', dialog.$.keyword.value); | 112 assertEquals('', dialog.$.keyword.value); |
111 assertEquals('', dialog.$.queryUrl.value); | 113 assertEquals('', dialog.$.queryUrl.value); |
112 var actionButton = dialog.$.actionButton; | 114 var actionButton = dialog.$.actionButton; |
113 assertTrue(actionButton.disabled); | 115 assertTrue(actionButton.disabled); |
114 | 116 |
115 return focusAndValidate('searchEngine').then(function() { | 117 return inputAndValidate('searchEngine').then(function() { |
116 return focusAndValidate('keyword'); | 118 return inputAndValidate('keyword'); |
117 }).then(function() { | 119 }).then(function() { |
118 return focusAndValidate('queryUrl'); | 120 return inputAndValidate('queryUrl'); |
119 }).then(function() { | 121 }).then(function() { |
120 // Manually set the text to a non-empty string for all fields. | 122 // Manually set the text to a non-empty string for all fields. |
121 dialog.$.searchEngine.value = 'foo'; | 123 dialog.$.searchEngine.value = 'foo'; |
122 dialog.$.keyword.value = 'bar'; | 124 dialog.$.keyword.value = 'bar'; |
123 dialog.$.queryUrl.value = 'baz'; | 125 dialog.$.queryUrl.value = 'baz'; |
124 | 126 |
125 // MockInteractions does not provide a way to trigger a 'change' event | 127 return inputAndValidate('searchEngine'); |
126 // yet. Triggering the 'focus' event instead, to update the state of | |
127 // the action button. | |
128 return focusAndValidate('searchEngine'); | |
129 }).then(function() { | 128 }).then(function() { |
130 // Assert that the action button has been enabled now that all input | 129 // Assert that the action button has been enabled now that all input |
131 // is valid and non-empty. | 130 // is valid and non-empty. |
132 assertFalse(actionButton.disabled); | 131 assertFalse(actionButton.disabled); |
133 MockInteractions.tap(actionButton); | 132 MockInteractions.tap(actionButton); |
134 return browserProxy.whenCalled('searchEngineEditCompleted'); | 133 return browserProxy.whenCalled('searchEngineEditCompleted'); |
135 }); | 134 }); |
136 }); | 135 }); |
137 | 136 |
138 }); | 137 }); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 358 |
360 return { | 359 return { |
361 registerTests: function() { | 360 registerTests: function() { |
362 registerDialogTests(); | 361 registerDialogTests(); |
363 registerSearchEngineEntryTests(); | 362 registerSearchEngineEntryTests(); |
364 registerOmniboxExtensionEntryTests(); | 363 registerOmniboxExtensionEntryTests(); |
365 registerPageTests(); | 364 registerPageTests(); |
366 }, | 365 }, |
367 }; | 366 }; |
368 }); | 367 }); |
OLD | NEW |