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

Side by Side Diff: chrome/test/data/webui/settings/settings_main_test.js

Issue 2185493003: MD Settings: Adding some unit tests for <settings-main>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@search_no_results
Patch Set: Resolve conflicts with ToT. Created 4 years, 4 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
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cr.define('settings_main_page', function() {
6 /**
7 * @implements {SearchManager}
8 */
9 var TestSearchManager = function() {
10 /** @private {boolean} */
11 this.matchesFound_ = true;
12
13 /** @private {?settings.SearchRequest} */
14 this.searchRequest_ = null;
15 }
16
17 TestSearchManager.prototype = {
18 /**
19 * @param {boolean} matchesFound
20 */
21 setMatchesFound: function(matchesFound) {
22 this.matchesFound_ = matchesFound;
23 },
24
25 /** @override */
26 search: function(text, page) {
27 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) {
28 this.searchRequest_ = new settings.SearchRequest(text);
29 this.searchRequest_.finished = true;
30 this.searchRequest_.updateMatches(this.matchesFound_);
31 this.searchRequest_.resolver.resolve(this.searchRequest_);
32 }
33 return this.searchRequest_.resolver.promise;
34 },
35 };
36
37 function registerTests() {
38 var settingsPrefs = null;
39
40 suiteSetup(function() {
41 settingsPrefs = document.createElement('settings-prefs');
42 });
43
44 suite('SearchTests', function() {
45 /** @type {?TestSearchManager} */
46 var searchManager = null;
47
48 /** @type {?SettingsMainElement} */
49 var settingsMain = null;
50
51 // TODO(tommycli): Remove once settings.navigateTo is no longer a stub.
52 settings.navigateTo = function(route) {
53 settingsMain.currentRoute = route;
54 };
55
56 setup(function() {
57 searchManager = new TestSearchManager();
58 settings.setSearchManagerForTesting(searchManager);
59 PolymerTest.clearBody();
60 settingsMain = document.createElement('settings-main');
61 settingsMain.prefs = settingsPrefs.prefs;
62 settingsMain.toolbarSpinnerActive = false;
63 document.body.appendChild(settingsMain);
64 });
65
66 teardown(function() { settingsMain.remove(); });
67
68 test('no results page shows and hides', function() {
69 var noSearchResults = settingsMain.$.noSearchResults;
70 assertTrue(!!noSearchResults);
71 assertTrue(noSearchResults.hidden);
72
73 searchManager.setMatchesFound(false);
74 return settingsMain.searchContents('Query1').then(function() {
75 assertFalse(noSearchResults.hidden);
76
77 searchManager.setMatchesFound(true);
78 return settingsMain.searchContents('Query2');
79 }).then(function() {
80 assertTrue(noSearchResults.hidden);
81 });
82 });
83
84 // Ensure that when the user clears the search box, the "no results" page
85 // is hidden.
86 test('no results page hides on clear', function() {
87 var noSearchResults = settingsMain.$.noSearchResults;
88 assertTrue(!!noSearchResults);
89 assertTrue(noSearchResults.hidden);
90 searchManager.setMatchesFound(false);
91
92 // Clearing the search box is effectively a search for the empty string.
93 return settingsMain.searchContents('').then(function() {
94 assertTrue(noSearchResults.hidden);
95 });
96 });
97 });
98 }
99
100 return {
101 registerTests: registerTests,
102 };
103 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698