| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('settings_main_page', function() { | 5 cr.define('settings_main_page', function() { |
| 6 /** | 6 /** |
| 7 * Extending TestBrowserProxy even though SearchManager is not a browser proxy |
| 8 * itself. Essentially TestBrowserProxy can act as a "proxy" for any external |
| 9 * dependency, not just "browser proxies" (and maybe should be renamed to |
| 10 * TestProxy). |
| 11 * |
| 7 * @implements {SearchManager} | 12 * @implements {SearchManager} |
| 13 * @extends {settings.TestBrowserProxy} |
| 8 */ | 14 */ |
| 9 var TestSearchManager = function() { | 15 var TestSearchManager = function() { |
| 16 settings.TestBrowserProxy.call(this, [ |
| 17 'search', |
| 18 ]); |
| 19 |
| 10 /** @private {boolean} */ | 20 /** @private {boolean} */ |
| 11 this.matchesFound_ = true; | 21 this.matchesFound_ = true; |
| 12 | 22 |
| 13 /** @private {?settings.SearchRequest} */ | 23 /** @private {?settings.SearchRequest} */ |
| 14 this.searchRequest_ = null; | 24 this.searchRequest_ = null; |
| 15 } | 25 } |
| 16 | 26 |
| 17 TestSearchManager.prototype = { | 27 TestSearchManager.prototype = { |
| 28 __proto__: settings.TestBrowserProxy.prototype, |
| 29 |
| 18 /** | 30 /** |
| 19 * @param {boolean} matchesFound | 31 * @param {boolean} matchesFound |
| 20 */ | 32 */ |
| 21 setMatchesFound: function(matchesFound) { | 33 setMatchesFound: function(matchesFound) { |
| 22 this.matchesFound_ = matchesFound; | 34 this.matchesFound_ = matchesFound; |
| 23 }, | 35 }, |
| 24 | 36 |
| 25 /** @override */ | 37 /** @override */ |
| 26 search: function(text, page) { | 38 search: function(text, page) { |
| 39 this.methodCalled('search', text); |
| 40 |
| 27 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { | 41 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { |
| 28 this.searchRequest_ = new settings.SearchRequest(text); | 42 this.searchRequest_ = new settings.SearchRequest(text); |
| 29 this.searchRequest_.finished = true; | 43 this.searchRequest_.finished = true; |
| 30 this.searchRequest_.updateMatches(this.matchesFound_); | 44 this.searchRequest_.updateMatches(this.matchesFound_); |
| 31 this.searchRequest_.resolver.resolve(this.searchRequest_); | 45 this.searchRequest_.resolver.resolve(this.searchRequest_); |
| 32 } | 46 } |
| 33 return this.searchRequest_.resolver.promise; | 47 return this.searchRequest_.resolver.promise; |
| 34 }, | 48 }, |
| 35 }; | 49 }; |
| 36 | 50 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 settings.setSearchManagerForTesting(searchManager); | 69 settings.setSearchManagerForTesting(searchManager); |
| 56 PolymerTest.clearBody(); | 70 PolymerTest.clearBody(); |
| 57 settingsMain = document.createElement('settings-main'); | 71 settingsMain = document.createElement('settings-main'); |
| 58 settingsMain.prefs = settingsPrefs.prefs; | 72 settingsMain.prefs = settingsPrefs.prefs; |
| 59 settingsMain.toolbarSpinnerActive = false; | 73 settingsMain.toolbarSpinnerActive = false; |
| 60 document.body.appendChild(settingsMain); | 74 document.body.appendChild(settingsMain); |
| 61 }); | 75 }); |
| 62 | 76 |
| 63 teardown(function() { settingsMain.remove(); }); | 77 teardown(function() { settingsMain.remove(); }); |
| 64 | 78 |
| 79 test('searchContents() triggers SearchManager', function() { |
| 80 Polymer.dom.flush(); |
| 81 |
| 82 var expectedQuery1 = 'foo'; |
| 83 var expectedQuery2 = 'bar'; |
| 84 var expectedQuery3 = ''; |
| 85 |
| 86 return settingsMain.searchContents(expectedQuery1).then(function() { |
| 87 return searchManager.whenCalled('search'); |
| 88 }).then(function(query) { |
| 89 assertEquals(expectedQuery1, query); |
| 90 |
| 91 searchManager.resetResolver('search'); |
| 92 return settingsMain.searchContents(expectedQuery2); |
| 93 }).then(function() { |
| 94 return searchManager.whenCalled('search'); |
| 95 }).then(function(query) { |
| 96 assertEquals(expectedQuery2, query); |
| 97 |
| 98 searchManager.resetResolver('search'); |
| 99 return settingsMain.searchContents(expectedQuery3); |
| 100 }).then(function() { |
| 101 return searchManager.whenCalled('search'); |
| 102 }).then(function(query) { |
| 103 assertEquals(expectedQuery3, query); |
| 104 }); |
| 105 }); |
| 106 |
| 65 test('no results page shows and hides', function() { | 107 test('no results page shows and hides', function() { |
| 66 Polymer.dom.flush(); | 108 Polymer.dom.flush(); |
| 67 var noSearchResults = settingsMain.$.noSearchResults; | 109 var noSearchResults = settingsMain.$.noSearchResults; |
| 68 assertTrue(!!noSearchResults); | 110 assertTrue(!!noSearchResults); |
| 69 assertTrue(noSearchResults.hidden); | 111 assertTrue(noSearchResults.hidden); |
| 70 | 112 |
| 71 var toggleContainer = settingsMain.$$('#toggleContainer'); | 113 var toggleContainer = settingsMain.$$('#toggleContainer'); |
| 72 assertTrue(!!toggleContainer); | 114 assertTrue(!!toggleContainer); |
| 73 assertNotEquals('none', toggleContainer.style.display); | 115 assertNotEquals('none', toggleContainer.style.display); |
| 74 | 116 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 236 |
| 195 assertTrue(settingsMain.showPages_.advanced); | 237 assertTrue(settingsMain.showPages_.advanced); |
| 196 }); | 238 }); |
| 197 }); | 239 }); |
| 198 } | 240 } |
| 199 | 241 |
| 200 return { | 242 return { |
| 201 registerTests: registerTests, | 243 registerTests: registerTests, |
| 202 }; | 244 }; |
| 203 }); | 245 }); |
| OLD | NEW |