| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-main' displays the selected settings page. | 7 * 'settings-main' displays the selected settings page. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-main', | 10 is: 'settings-main', |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 /** | 169 /** |
| 170 * Navigates to the default search page (if necessary). | 170 * Navigates to the default search page (if necessary). |
| 171 * @private | 171 * @private |
| 172 */ | 172 */ |
| 173 ensureInDefaultSearchPage_: function() { | 173 ensureInDefaultSearchPage_: function() { |
| 174 settings.navigateTo(settings.Route.BASIC); | 174 settings.navigateTo(settings.Route.BASIC); |
| 175 }, | 175 }, |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @param {string} query | 178 * @param {string} query |
| 179 * @return {!Promise} A promise indicating that searching finished. |
| 179 */ | 180 */ |
| 180 searchContents: function(query) { | 181 searchContents: function(query) { |
| 181 this.ensureInDefaultSearchPage_(); | 182 this.ensureInDefaultSearchPage_(); |
| 182 this.toolbarSpinnerActive = true; | 183 this.toolbarSpinnerActive = true; |
| 183 | 184 |
| 184 // Trigger rendering of the basic and advanced pages and search once ready. | 185 // Trigger rendering of the basic and advanced pages and search once ready. |
| 185 this.showPages_ = {about: false, basic: true, advanced: true}; | 186 this.showPages_ = {about: false, basic: true, advanced: true}; |
| 186 | 187 |
| 187 setTimeout(function() { | 188 return new Promise(function(resolve, reject) { |
| 188 settings.getSearchManager().search( | 189 setTimeout(function() { |
| 189 query, assert(this.$$('settings-basic-page'))); | 190 var whenSearchDone = settings.getSearchManager().search( |
| 190 }.bind(this), 0); | 191 query, assert(this.$$('settings-basic-page'))); |
| 191 setTimeout(function() { | 192 assert( |
| 192 settings.getSearchManager().search( | 193 whenSearchDone === |
| 193 query, assert(this.$$('settings-advanced-page'))).then( | 194 settings.getSearchManager().search( |
| 194 function(request) { | 195 query, assert(this.$$('settings-advanced-page')))); |
| 195 if (!request.finished) { | |
| 196 // Nothing to do here. A previous search request was canceled | |
| 197 // because a new search request was issued before the first one | |
| 198 // completed. | |
| 199 return; | |
| 200 } | |
| 201 | 196 |
| 202 this.toolbarSpinnerActive = false; | 197 whenSearchDone.then(function(request) { |
| 203 this.showNoResultsFound_ = | 198 resolve(); |
| 204 !request.isSame('') && !request.didFindMatches(); | 199 if (!request.finished) { |
| 205 }.bind(this)); | 200 // Nothing to do here. A previous search request was canceled |
| 206 }.bind(this), 0); | 201 // because a new search request was issued before the first one |
| 202 // completed. |
| 203 return; |
| 204 } |
| 205 |
| 206 this.toolbarSpinnerActive = false; |
| 207 this.showNoResultsFound_ = |
| 208 !request.isSame('') && !request.didFindMatches(); |
| 209 }.bind(this)); |
| 210 }.bind(this), 0); |
| 211 }.bind(this)); |
| 207 }, | 212 }, |
| 208 | 213 |
| 209 /** | 214 /** |
| 210 * @param {(boolean|undefined)} visibility | 215 * @param {(boolean|undefined)} visibility |
| 211 * @return {boolean} True unless visibility is false. | 216 * @return {boolean} True unless visibility is false. |
| 212 * @private | 217 * @private |
| 213 */ | 218 */ |
| 214 showAdvancedSettings_: function(visibility) { | 219 showAdvancedSettings_: function(visibility) { |
| 215 return visibility !== false; | 220 return visibility !== false; |
| 216 }, | 221 }, |
| 217 }); | 222 }); |
| OLD | NEW |