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

Side by Side Diff: chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.js

Issue 2586803002: MD Settings: Fix label visibility in subpage search fields (Closed)
Patch Set: Rebase Created 3 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 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 /** @fileoverview Suite of tests for cr-toolbar-search-field. */ 5 /** @fileoverview Suite of tests for cr-toolbar-search-field. */
6 cr.define('cr_toolbar_search_field', function() { 6 cr.define('cr_toolbar_search_field', function() {
7 function registerTests() { 7 function registerTests() {
8 suite('cr-toolbar-search-field', function() { 8 suite('cr-toolbar-search-field', function() {
9 /** @type {?CrToolbarSearchFieldElement} */ 9 /** @type {?CrToolbarSearchFieldElement} */
10 var field = null; 10 var field = null;
11 11
12 /** @type {?Array<string>} */ 12 /** @type {?Array<string>} */
13 var searches = null; 13 var searches = null;
14 14
15 /** @param {string} term */ 15 /** @param {string} term */
16 function simulateSearch(term) { 16 function simulateSearch(term) {
17 field.$.searchInput.value = term; 17 field.$.searchInput.value = term;
18 field.onSearchInput_(); 18 field.onSearchTermInput();
19 field.onSearchTermSearch(); 19 field.onSearchTermSearch();
20 } 20 }
21 21
22 setup(function() { 22 setup(function() {
23 PolymerTest.clearBody(); 23 PolymerTest.clearBody();
24 field = document.createElement('cr-toolbar-search-field'); 24 field = document.createElement('cr-toolbar-search-field');
25 searches = []; 25 searches = [];
26 field.addEventListener('search-changed', function(event) { 26 field.addEventListener('search-changed', function(event) {
27 searches.push(event.detail); 27 searches.push(event.detail);
28 }); 28 });
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 MockInteractions.pressAndReleaseKeyOn( 67 MockInteractions.pressAndReleaseKeyOn(
68 field.$.searchInput, 27, '', 'Escape'); 68 field.$.searchInput, 27, '', 'Escape');
69 assertFalse(field.showingSearch, 'Pressing escape closes field.'); 69 assertFalse(field.showingSearch, 'Pressing escape closes field.');
70 assertNotEquals(field.$.searchInput, field.root.activeElement); 70 assertNotEquals(field.$.searchInput, field.root.activeElement);
71 }); 71 });
72 72
73 test('clear search button clears and refocuses input', function() { 73 test('clear search button clears and refocuses input', function() {
74 MockInteractions.tap(field); 74 MockInteractions.tap(field);
75 simulateSearch('query1'); 75 simulateSearch('query1');
76 Polymer.dom.flush(); 76 Polymer.dom.flush();
77 assertTrue(field.hasSearchText);
77 78
78 var clearSearch = field.$$('#clearSearch'); 79 var clearSearch = field.$$('#clearSearch');
79 clearSearch.focus(); 80 clearSearch.focus();
80 MockInteractions.tap(clearSearch); 81 MockInteractions.tap(clearSearch);
81 assertTrue(field.showingSearch); 82 assertTrue(field.showingSearch);
82 assertEquals('', field.getValue()); 83 assertEquals('', field.getValue());
83 assertEquals(field.$.searchInput, field.root.activeElement); 84 assertEquals(field.$.searchInput, field.root.activeElement);
85 assertFalse(field.hasSearchText);
84 }); 86 });
85 87
86 test('notifies on new searches', function() { 88 test('notifies on new searches', function() {
87 MockInteractions.tap(field); 89 MockInteractions.tap(field);
88 simulateSearch('query1'); 90 simulateSearch('query1');
89 Polymer.dom.flush(); 91 Polymer.dom.flush();
90 assertEquals('query1', field.getValue()); 92 assertEquals('query1', field.getValue());
91 93
92 MockInteractions.tap(field.$$('#clearSearch')); 94 MockInteractions.tap(field.$$('#clearSearch'));
93 assertTrue(field.showingSearch); 95 assertTrue(field.showingSearch);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 simulateSearch('test'); 143 simulateSearch('test');
142 MockInteractions.blur(field.$.searchInput); 144 MockInteractions.blur(field.$.searchInput);
143 145
144 assertTrue(field.showingSearch); 146 assertTrue(field.showingSearch);
145 }); 147 });
146 148
147 test('opens when value is changed', function() { 149 test('opens when value is changed', function() {
148 // Change search value without explicity opening the field first. 150 // Change search value without explicity opening the field first.
149 // Similar to what happens when pasting or dragging into the input 151 // Similar to what happens when pasting or dragging into the input
150 // field. 152 // field.
153 assertFalse(field.hasSearchText);
151 simulateSearch('test'); 154 simulateSearch('test');
155 assertTrue(field.hasSearchText);
152 Polymer.dom.flush(); 156 Polymer.dom.flush();
153 157
154 var clearSearch = field.$$('#clearSearch'); 158 var clearSearch = field.$$('#clearSearch');
155 assertFalse(clearSearch.hidden); 159 assertFalse(clearSearch.hidden);
156 assertTrue(field.showingSearch); 160 assertTrue(field.showingSearch);
157 }); 161 });
162
163 test('closes when value is cleared while unfocused', function() {
164 MockInteractions.focus(field.$.searchInput);
165 simulateSearch('test');
166 Polymer.dom.flush();
167
168 // Does not close the field if it is focused when cleared.
169 assertTrue(field.showingSearch);
170 field.setValue('');
171 assertTrue(field.showingSearch);
172
173 // Does close the field if it is blurred before being cleared.
174 simulateSearch('test');
175 MockInteractions.blur(field.$.searchInput);
176 field.setValue('');
177 assertFalse(field.showingSearch);
178 });
179
158 }); 180 });
159 } 181 }
160 182
161 return { 183 return {
162 registerTests: registerTests, 184 registerTests: registerTests,
163 }; 185 };
164 }); 186 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698