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

Unified 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, 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
Index: chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.js
diff --git a/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.js b/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.js
new file mode 100644
index 0000000000000000000000000000000000000000..8f5d3f0c4b06e74f42072b3b61b8d82e49dd9970
--- /dev/null
+++ b/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.js
@@ -0,0 +1,100 @@
+// 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-toolbar-search-field. */
+cr.define('cr_toolbar_search_field', function() {
+ function registerTests() {
+ suite('cr-toolbar-search-field', function() {
+ /** @type {?CrToolbarSearchFieldElement} */
+ var field;
+ /** @type {?MockSearchFieldDelegate} */
+ var delegate;
+
+ /** @param {string} term */
+ function simulateSearch(term) {
+ field.$.searchInput.bindValue = term;
+ field.onSearchTermSearch();
+ }
+
+ /**
+ * @constructor
+ * @implements {SearchFieldDelegate}
+ */
+ function MockSearchFieldDelegate() {
+ /** @type {!Array<string>} */
+ this.searches = [];
+ }
+
+ MockSearchFieldDelegate.prototype = {
+ /** @override */
+ onSearchTermSearch: function(term) {
+ this.searches.push(term);
+ }
+ };
+
+ suiteSetup(function() {
+ return PolymerTest.importHtml(
+ 'chrome://resources/cr_elements/cr_toolbar/' +
+ 'cr_toolbar_search_field.html');
+ });
+
+ setup(function() {
+ PolymerTest.clearBody();
+ // Constructing a new delegate resets the list of searches.
+ delegate = new MockSearchFieldDelegate();
+ field = document.createElement('cr-toolbar-search-field');
+ field.setDelegate(delegate);
+ document.body.appendChild(field);
+ });
+
+ teardown(function() {
+ field.remove();
+ field = null;
+ delegate = null;
+ });
+
+ test('opens and closes correctly', function() {
+ assertFalse(field.showingSearch);
+ MockInteractions.tap(field);
+ assertTrue(field.showingSearch);
+ assertEquals(field.$.searchInput, field.root.activeElement);
+
+ MockInteractions.blur(field.$.searchInput);
+ assertFalse(field.showingSearch);
+
+ MockInteractions.tap(field);
+ assertEquals(field.$.searchInput, field.root.activeElement);
+
+ MockInteractions.pressAndReleaseKeyOn(
+ field.$.searchInput, 27, '', 'Escape');
+ assertFalse(field.showingSearch, 'Pressing escape closes field.');
+ assertNotEquals(field.$.searchInput, field.root.activeElement);
+ });
+
+ test('passes searches correctly', function() {
+ MockInteractions.tap(field);
+ simulateSearch('test');
+ assertEquals('test', field.getValue());
+
+ MockInteractions.tap(field.$.clearSearch);
+ assertFalse(field.showingSearch);
+ assertEquals('', field.getValue());
+
+ assertEquals(['test', ''].join(), delegate.searches.join());
+ });
+
+ test('blur does not close field when a search is active', function() {
+ MockInteractions.tap(field);
+ simulateSearch('test');
+ MockInteractions.blur(field.$.searchInput);
+
+ assertTrue(field.showingSearch);
+ });
+ });
+ }
+
+ return {
+ registerTests: registerTests,
+ };
+});
« 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