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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/cr_elements_browsertest.js
diff --git a/chrome/test/data/webui/cr_elements_browsertest.js b/chrome/test/data/webui/cr_elements_browsertest.js
new file mode 100644
index 0000000000000000000000000000000000000000..bee6e1023775228270ffb9e227a136b02d912ed8
--- /dev/null
+++ b/chrome/test/data/webui/cr_elements_browsertest.js
@@ -0,0 +1,112 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview Suite of tests for cr elements. */
+
+/** @const {string} Path to source root. */
+var ROOT_PATH = '../../../../';
+
+// Polymer BrowserTest fixture.
+GEN_INCLUDE(
+ [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
+
+/**
+ * Test fixture for cr elements
+ * @constructor
+ * @extends {PolymerTest}
+ */
+function CrElementsBrowserTest() {}
+
+CrElementsBrowserTest.prototype = {
+ __proto__: PolymerTest.prototype,
+ extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
+};
+
+TEST_F('CrElementsBrowserTest', 'CrToolbarSearchFieldTest', function() {
+ suite('cr-toolbar-search-field', function() {
+ /** @type {CrToolbarSearchFieldElement} */
+ var field;
+ /** @type {Array<string>} */
+ var searches;
dpapad 2016/05/26 21:43:36 How about making this field a member variable of t
tsergeant 2016/05/27 01:20:13 Done.
+
+ /** @param {string} term */
+ function mockSearch(term) {
dpapad 2016/05/26 21:43:37 "mock" is an overloaded term IMO. Personally I thi
tsergeant 2016/05/27 01:20:13 Done.
+ field.$.searchInput.bindValue = term;
+ field.onSearchTermSearch_();
+ }
+
+ /**
+ * @constructor
+ * @implements {SearchFieldDelegate}
+ */
+ function MockSearchFieldDelegate() {
dpapad 2016/05/26 21:43:36 /** * @constructor * @implements {SearchFieldD
dpapad 2016/05/26 21:44:47 Small correction on my previous suggestion: this.s
tsergeant 2016/05/27 01:20:13 Done.
+ }
+
+ MockSearchFieldDelegate.prototype = {
+ onSearchTermSearch: function(term) {
+ searches.push(term);
+ }
+ };
+
+ suiteSetup(function() {
+ return PolymerTest.importHtml(
+ 'chrome://resources/cr_elements/cr_toolbar/' +
+ 'cr_toolbar_search_field.html');
+ });
+
+ setup(function() {
+ PolymerTest.clearBody();
+ searches = [];
dpapad 2016/05/26 21:43:36 // no need to instantiate both "searches" and a ne
tsergeant 2016/05/27 01:20:13 Done.
+ field = document.createElement('cr-toolbar-search-field');
+ document.body.appendChild(field);
+ field.setDelegate(new MockSearchFieldDelegate());
dpapad 2016/05/26 21:43:36 field.setDelegate(delegate);
tsergeant 2016/05/27 01:20:13 Done.
+ });
dpapad 2016/05/26 21:43:36 It is generally good practice to have tearDown und
tsergeant 2016/05/27 01:20:13 Done.
+
+ test('opens and closes correctly', function() {
+ return Promise.resolve().then(function() {
dpapad 2016/05/26 21:43:36 Why are you using a Promise here? This test does n
tsergeant 2016/05/27 01:20:13 CrSearchFieldBehavior.focus_() was previously asyn
+ assertFalse(field.showingSearch);
+ MockInteractions.tap(field);
+ assertTrue(field.showingSearch);
+ }).then(function() {
dpapad 2016/05/26 21:43:36 Same here (and below). Why is starting a new funct
tsergeant 2016/05/27 01:20:14 See above.
+ assertEquals(field.$.searchInput, field.root.activeElement);
+
+ MockInteractions.blur(field.$.searchInput);
+ assertFalse(field.showingSearch);
+
+ MockInteractions.tap(field);
+ }).then(function() {
+ assertEquals(field.$.searchInput, field.root.activeElement);
+ MockInteractions.pressAndReleaseKeyOn(
+ field.$.searchInput, 27, '', 'Escape');
+ assertFalse(field.showingSearch, 'Pressing escape closes field.');
+ }).then(function() {
+ assertNotEquals(field.$.searchInput, field.root.activeElement);
+ });
+ });
+
+ test('passes searches correctly', function() {
+ MockInteractions.tap(field);
+ mockSearch('test');
+ assertEquals('test', field.getValue());
+
+ MockInteractions.tap(field.$.clearSearch);
+ assertFalse(field.showingSearch);
+ assertEquals('', field.getValue());
+
+ assertEquals(2, searches.length);
+ assertEquals('test', searches[0]);
+ assertEquals('', searches[1]);
+ });
+
+ test('blur does not close field when a search is active', function() {
+ MockInteractions.tap(field);
+ mockSearch('test');
+ MockInteractions.blur(field.$.searchInput);
+
+ assertTrue(field.showingSearch);
+ });
+ });
+
+ mocha.run();
+});
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698