Chromium Code Reviews| Index: chrome/test/data/webui/settings/settings_main_test.js |
| diff --git a/chrome/test/data/webui/settings/settings_main_test.js b/chrome/test/data/webui/settings/settings_main_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a1baef07e6ec043a496da5ae0646e29a8b6c196 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/settings/settings_main_test.js |
| @@ -0,0 +1,98 @@ |
| +// 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. |
| + |
| +cr.define('settings_main_page', function() { |
| + /** |
| + * @implements {SearchManager} |
| + */ |
| + var TestSearchManager = function() { |
| + /** @private {boolean} */ |
| + this.matchesFound_ = true; |
| + } |
| + |
| + TestSearchManager.prototype = { |
| + /** |
| + * @param {boolean} matchesFound |
| + */ |
| + setMatchesFound: function(matchesFound) { |
| + this.matchesFound_ = matchesFound; |
| + }, |
| + |
| + /** @override */ |
| + search: function(text, page) { |
| + var searchRequest = new settings.SearchRequest(text); |
| + searchRequest.finished = true; |
| + searchRequest.updateMatches(this.matchesFound_); |
| + searchRequest.resolver.resolve(searchRequest); |
| + return searchRequest.resolver.promise; |
| + }, |
| + }; |
| + |
| + function registerTests() { |
|
michaelpg
2016/07/30 05:38:44
nit: new tests shouldn't use the cr.define/registe
dpapad
2016/08/02 22:33:15
Unfortunately removing the registerTests() call, m
|
| + var settingsPrefs = null; |
| + |
| + suiteSetup(function() { |
| + settingsPrefs = document.createElement('settings-prefs'); |
| + }); |
| + |
| + suite('SearchTests', function() { |
| + /** @type {?TestSearchManager} */ |
| + var searchManager = null; |
| + |
| + /** @type {?SettingsMainElement} */ |
| + var page = null; |
|
michaelpg
2016/07/30 05:38:44
nit: page already has too many meaninsg
dpapad
2016/08/02 22:33:15
Done.
|
| + |
| + // TODO(tommycli): Remove once settings.navigateTo is no longer a stub. |
| + settings.navigateTo = function(route) { |
| + page.currentRoute = route; |
| + }; |
| + |
| + setup(function() { |
| + searchManager = new TestSearchManager(); |
| + settings.setSearchManagerForTesting(searchManager); |
| + PolymerTest.clearBody(); |
| + page = document.createElement('settings-main'); |
| + page.prefs = settingsPrefs.prefs; |
| + page.toolbarSpinnerActive = false; |
| + document.body.appendChild(page); |
| + }); |
| + |
| + teardown(function() { page.remove(); }); |
| + |
| + test('NoResultsPageShowsHides', function() { |
|
michaelpg
2016/07/30 05:38:44
nit... this is just a string, it doesn't have to b
dpapad
2016/08/02 22:33:15
Done.
|
| + var noSearchResults = page.$.noSearchResults; |
| + assertTrue(!!noSearchResults); |
| + assertTrue(noSearchResults.hidden); |
| + |
| + searchManager.setMatchesFound(false); |
| + return page.searchContents('foo').then(function() { |
| + assertFalse(noSearchResults.hidden); |
| + |
| + searchManager.setMatchesFound(true); |
| + return page.searchContents('foo'); |
| + }).then(function() { |
| + assertTrue(noSearchResults.hidden); |
| + }); |
| + }); |
| + |
| + // Ensure that when the user clears the search box, the "no results" page |
| + // is hidden. |
| + test('NoResultsPageHidesOnClear', function() { |
| + var noSearchResults = page.$.noSearchResults; |
| + assertTrue(!!noSearchResults); |
| + assertTrue(noSearchResults.hidden); |
| + searchManager.setMatchesFound(false); |
|
michaelpg
2016/07/30 05:38:44
assert first that noSearchResults is unhidden?
michaelpg
2016/08/02 20:45:20
ping, did you miss this file? this one is slightly
dpapad
2016/08/02 22:33:15
I don't fully understand your comment "to catch a
|
| + |
| + // Clearing the search box is effectively a search for the empty string. |
| + return page.searchContents('').then(function() { |
| + assertTrue(noSearchResults.hidden); |
| + }); |
| + }); |
| + }); |
| + } |
| + |
| + return { |
| + registerTests: registerTests, |
| + }; |
| +}); |