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

Side by Side Diff: chrome/test/data/webui/cr_elements_browsertest.js

Issue 2017523002: MD WebUI: Add tests for cr-toolbar-search-field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dpapad@ review comments Created 4 years, 7 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 elements. */
dpapad 2016/05/27 01:31:12 Nit: Mention the exact element being tested here.
tsergeant 2016/05/27 03:07:36 Done.
6
7 /** @const {string} Path to source root. */
8 var ROOT_PATH = '../../../../';
9
10 // Polymer BrowserTest fixture.
11 GEN_INCLUDE(
12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
13
14 /**
15 * Test fixture for cr elements
16 * @constructor
17 * @extends {PolymerTest}
18 */
19 function CrElementsBrowserTest() {}
20
21 CrElementsBrowserTest.prototype = {
22 __proto__: PolymerTest.prototype,
23 extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
24 };
25
26 TEST_F('CrElementsBrowserTest', 'CrToolbarSearchFieldTest', function() {
27 suite('cr-toolbar-search-field', function() {
28 /** @type {CrToolbarSearchFieldElement} */
29 var field;
dpapad 2016/05/27 01:31:12 Let's either instantiate both field and delegate t
tsergeant 2016/05/27 03:07:36 Done.
30 /** @type {MockSearchFieldDelegate} */
31 var delegate = null;
32
33 /** @param {string} term */
34 function simulateSearch(term) {
35 field.$.searchInput.bindValue = term;
36 field.onSearchTermSearch_();
37 }
38
39 /**
40 * @constructor
41 * @implements {SearchFieldDelegate}
42 */
43 function MockSearchFieldDelegate() {
44 /** @type {!Array<string>} */
45 this.searches = [];
46 }
47
48 MockSearchFieldDelegate.prototype = {
49 onSearchTermSearch: function(term) {
dpapad 2016/05/27 01:31:12 Nit: @override
tsergeant 2016/05/27 03:07:36 Done.
50 this.searches.push(term);
51 }
52 };
53
54 suiteSetup(function() {
55 return PolymerTest.importHtml(
56 'chrome://resources/cr_elements/cr_toolbar/' +
57 'cr_toolbar_search_field.html');
58 });
59
60 setup(function() {
61 PolymerTest.clearBody();
62 // Constructing a new delegate resets the list of searches.
63 delegate = new MockSearchFieldDelegate();
64 field = document.createElement('cr-toolbar-search-field');
65 field.setDelegate(delegate);
66 document.body.appendChild(field);
67 });
68
69 teardown(function() {
70 field.remove();
71 field = null;
72 delegate = null;
73 });
74
75 test('opens and closes correctly', function() {
76 assertFalse(field.showingSearch);
77 MockInteractions.tap(field);
78 assertTrue(field.showingSearch);
79 assertEquals(field.$.searchInput, field.root.activeElement);
80
81 MockInteractions.blur(field.$.searchInput);
82 assertFalse(field.showingSearch);
83
84 MockInteractions.tap(field);
85 assertEquals(field.$.searchInput, field.root.activeElement);
86
87 MockInteractions.pressAndReleaseKeyOn(
88 field.$.searchInput, 27, '', 'Escape');
89 assertFalse(field.showingSearch, 'Pressing escape closes field.');
90 assertNotEquals(field.$.searchInput, field.root.activeElement);
91 });
92
93 test('passes searches correctly', function() {
94 MockInteractions.tap(field);
95 simulateSearch('test');
96 assertEquals('test', field.getValue());
97
98 MockInteractions.tap(field.$.clearSearch);
99 assertFalse(field.showingSearch);
100 assertEquals('', field.getValue());
101
102 assertEquals(2, delegate.searches.length);
dpapad 2016/05/27 01:31:12 Nit: You can replace all three assertions with a s
tsergeant 2016/05/27 03:07:36 Done.
103 assertEquals('test', delegate.searches[0]);
104 assertEquals('', delegate.searches[1]);
105 });
106
107 test('blur does not close field when a search is active', function() {
108 MockInteractions.tap(field);
109 simulateSearch('test');
110 MockInteractions.blur(field.$.searchInput);
111
112 assertTrue(field.showingSearch);
113 });
114 });
115
116 mocha.run();
117 });
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | ui/webui/resources/cr_elements/cr_search_field/cr_search_field_behavior.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698