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

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

Issue 2458113003: Prevent bogus 'search-changed' event firing from cr_search_field_behavior.js. (Closed)
Patch Set: Created 4 years, 1 month 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;
(...skipping 16 matching lines...) Expand all
27 }); 27 });
28 document.body.appendChild(field); 28 document.body.appendChild(field);
29 }); 29 });
30 30
31 teardown(function() { 31 teardown(function() {
32 field.remove(); 32 field.remove();
33 field = null; 33 field = null;
34 searches = null; 34 searches = null;
35 }); 35 });
36 36
37 // Test that no bogus 'search-changed' event is fired during construction
Dan Beam 2016/10/28 20:54:06 s/bogus/initial
dpapad 2016/10/28 21:12:13 Done.
38 // and initialization of the cr-toolbar-search-field element.
39 test('no bogus search-changed event', function() {
40 var didFire = false;
41 var onSearchChanged = function () { didFire = true; };
42
43 // Need to attach listener event before the element is created, to catch
44 // the bogus event.
45 document.body.addEventListener('search-changed', onSearchChanged);
46 document.body.innerHTML =
47 '<cr-toolbar-search-field></cr-toolbar-search-field>';
48 // Remove event listener on |body| so that other tests are not affected.
49 document.body.removeEventListener('search-changed', onSearchChanged);
50
51 assertFalse(didFire, 'Should not have fired search-changed event');
52 });
53
37 test('opens and closes correctly', function() { 54 test('opens and closes correctly', function() {
38 assertFalse(field.showingSearch); 55 assertFalse(field.showingSearch);
39 MockInteractions.tap(field); 56 MockInteractions.tap(field);
40 assertTrue(field.showingSearch); 57 assertTrue(field.showingSearch);
41 assertEquals(field.$.searchInput, field.root.activeElement); 58 assertEquals(field.$.searchInput, field.root.activeElement);
42 59
43 MockInteractions.blur(field.$.searchInput); 60 MockInteractions.blur(field.$.searchInput);
44 assertFalse(field.showingSearch); 61 assertFalse(field.showingSearch);
45 62
46 MockInteractions.tap(field); 63 MockInteractions.tap(field);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 assertFalse(clearSearch.hidden); 146 assertFalse(clearSearch.hidden);
130 assertTrue(field.showingSearch); 147 assertTrue(field.showingSearch);
131 }); 148 });
132 }); 149 });
133 } 150 }
134 151
135 return { 152 return {
136 registerTests: registerTests, 153 registerTests: registerTests,
137 }; 154 };
138 }); 155 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698