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

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

Issue 2060023002: WebUI: cr-search-field: Remove delegation pattern, use simple event instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@search_box0
Patch Set: Address comments, fix compilation. Created 4 years, 6 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; 10 var field = null;
11 /** @type {?MockSearchFieldDelegate} */ 11
12 var delegate; 12 /** @type {?Array<string>} */
13 var searches = null;
13 14
14 /** @param {string} term */ 15 /** @param {string} term */
15 function simulateSearch(term) { 16 function simulateSearch(term) {
16 field.$.searchInput.bindValue = term; 17 field.$.searchInput.bindValue = term;
17 field.onSearchTermSearch(); 18 field.onSearchTermSearch();
18 } 19 }
19 20
20 /**
21 * @constructor
22 * @implements {SearchFieldDelegate}
23 */
24 function MockSearchFieldDelegate() {
25 /** @type {!Array<string>} */
26 this.searches = [];
27 }
28
29 MockSearchFieldDelegate.prototype = {
30 /** @override */
31 onSearchTermSearch: function(term) {
32 this.searches.push(term);
33 }
34 };
35
36 suiteSetup(function() { 21 suiteSetup(function() {
37 return PolymerTest.importHtml( 22 return PolymerTest.importHtml(
38 'chrome://resources/cr_elements/cr_toolbar/' + 23 'chrome://resources/cr_elements/cr_toolbar/' +
39 'cr_toolbar_search_field.html'); 24 'cr_toolbar_search_field.html');
40 }); 25 });
41 26
42 setup(function() { 27 setup(function() {
43 PolymerTest.clearBody(); 28 PolymerTest.clearBody();
44 // Constructing a new delegate resets the list of searches.
45 delegate = new MockSearchFieldDelegate();
46 field = document.createElement('cr-toolbar-search-field'); 29 field = document.createElement('cr-toolbar-search-field');
47 field.setDelegate(delegate); 30 searches = [];
31 field.addEventListener('search-changed', function(event) {
32 searches.push(event.detail);
33 });
48 document.body.appendChild(field); 34 document.body.appendChild(field);
49 }); 35 });
50 36
51 teardown(function() { 37 teardown(function() {
52 field.remove(); 38 field.remove();
53 field = null; 39 field = null;
54 delegate = null; 40 searches = null;
55 }); 41 });
56 42
57 test('opens and closes correctly', function() { 43 test('opens and closes correctly', function() {
58 assertFalse(field.showingSearch); 44 assertFalse(field.showingSearch);
59 MockInteractions.tap(field); 45 MockInteractions.tap(field);
60 assertTrue(field.showingSearch); 46 assertTrue(field.showingSearch);
61 assertEquals(field.$.searchInput, field.root.activeElement); 47 assertEquals(field.$.searchInput, field.root.activeElement);
62 48
63 MockInteractions.blur(field.$.searchInput); 49 MockInteractions.blur(field.$.searchInput);
64 assertFalse(field.showingSearch); 50 assertFalse(field.showingSearch);
(...skipping 13 matching lines...) Expand all
78 assertEquals('query1', field.getValue()); 64 assertEquals('query1', field.getValue());
79 65
80 MockInteractions.tap(field.$.clearSearch); 66 MockInteractions.tap(field.$.clearSearch);
81 assertFalse(field.showingSearch); 67 assertFalse(field.showingSearch);
82 assertEquals('', field.getValue()); 68 assertEquals('', field.getValue());
83 69
84 simulateSearch('query2'); 70 simulateSearch('query2');
85 // Expecting identical query to be ignored. 71 // Expecting identical query to be ignored.
86 simulateSearch('query2'); 72 simulateSearch('query2');
87 73
88 assertEquals(['query1', '', 'query2'].join(), delegate.searches.join()); 74 assertEquals(['query1', '', 'query2'].join(), searches.join());
89 }); 75 });
90 76
91 test('blur does not close field when a search is active', function() { 77 test('blur does not close field when a search is active', function() {
92 MockInteractions.tap(field); 78 MockInteractions.tap(field);
93 simulateSearch('test'); 79 simulateSearch('test');
94 MockInteractions.blur(field.$.searchInput); 80 MockInteractions.blur(field.$.searchInput);
95 81
96 assertTrue(field.showingSearch); 82 assertTrue(field.showingSearch);
97 }); 83 });
98 }); 84 });
99 } 85 }
100 86
101 return { 87 return {
102 registerTests: registerTests, 88 registerTests: registerTests,
103 }; 89 };
104 }); 90 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698