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

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

Issue 1967913002: Material WebUI: cr-slider element for intelligent range mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@KeyboardFinish
Patch Set: rebase fix 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /** @fileoverview Suite of tests for cr-toolbar-search-field. */
6 cr.define('cr_toolbar_search_field', function() {
7 function registerTests() {
8 suite('cr-toolbar-search-field', function() {
9 /** @type {?CrToolbarSearchFieldElement} */
10 var field;
11 /** @type {?MockSearchFieldDelegate} */
12 var delegate;
13
14 /** @param {string} term */
15 function simulateSearch(term) {
16 field.$.searchInput.bindValue = term;
17 field.onSearchTermSearch();
18 }
19
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() {
37 return PolymerTest.importHtml(
38 'chrome://resources/cr_elements/cr_toolbar/' +
39 'cr_toolbar_search_field.html');
40 });
41
42 setup(function() {
43 PolymerTest.clearBody();
44 // Constructing a new delegate resets the list of searches.
45 delegate = new MockSearchFieldDelegate();
46 field = document.createElement('cr-toolbar-search-field');
47 field.setDelegate(delegate);
48 document.body.appendChild(field);
49 });
50
51 teardown(function() {
52 field.remove();
53 field = null;
54 delegate = null;
55 });
56
57 test('opens and closes correctly', function() {
58 assertFalse(field.showingSearch);
59 MockInteractions.tap(field);
60 assertTrue(field.showingSearch);
61 assertEquals(field.$.searchInput, field.root.activeElement);
62
63 MockInteractions.blur(field.$.searchInput);
64 assertFalse(field.showingSearch);
65
66 MockInteractions.tap(field);
67 assertEquals(field.$.searchInput, field.root.activeElement);
68
69 MockInteractions.pressAndReleaseKeyOn(
70 field.$.searchInput, 27, '', 'Escape');
71 assertFalse(field.showingSearch, 'Pressing escape closes field.');
72 assertNotEquals(field.$.searchInput, field.root.activeElement);
73 });
74
75 test('passes searches correctly', function() {
76 MockInteractions.tap(field);
77 simulateSearch('test');
78 assertEquals('test', field.getValue());
79
80 MockInteractions.tap(field.$.clearSearch);
81 assertFalse(field.showingSearch);
82 assertEquals('', field.getValue());
83
84 assertEquals(['test', ''].join(), delegate.searches.join());
85 });
86
87 test('blur does not close field when a search is active', function() {
88 MockInteractions.tap(field);
89 simulateSearch('test');
90 MockInteractions.blur(field.$.searchInput);
91
92 assertTrue(field.showingSearch);
93 });
94 });
95 }
96
97 return {
98 registerTests: registerTests,
99 };
100 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_slider_tests.js ('k') | chrome/test/data/webui/cr_elements_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698