| 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 | 7 * Extending TestBrowserProxy even though SearchManager is not a browser proxy |
| 8 * itself. Essentially TestBrowserProxy can act as a "proxy" for any external | 8 * itself. Essentially TestBrowserProxy can act as a "proxy" for any external |
| 9 * dependency, not just "browser proxies" (and maybe should be renamed to | 9 * dependency, not just "browser proxies" (and maybe should be renamed to |
| 10 * TestProxy). | 10 * TestProxy). |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 suite('MainPageTests', function() { | 59 suite('MainPageTests', function() { |
| 60 /** @type {?TestSearchManager} */ | 60 /** @type {?TestSearchManager} */ |
| 61 var searchManager = null; | 61 var searchManager = null; |
| 62 | 62 |
| 63 /** @type {?SettingsMainElement} */ | 63 /** @type {?SettingsMainElement} */ |
| 64 var settingsMain = null; | 64 var settingsMain = null; |
| 65 | 65 |
| 66 setup(function() { | 66 setup(function() { |
| 67 settings.navigateTo(settings.Route.BASIC); | 67 settings.navigateTo(settings.routes.BASIC); |
| 68 searchManager = new TestSearchManager(); | 68 searchManager = new TestSearchManager(); |
| 69 settings.setSearchManagerForTesting(searchManager); | 69 settings.setSearchManagerForTesting(searchManager); |
| 70 PolymerTest.clearBody(); | 70 PolymerTest.clearBody(); |
| 71 settingsMain = document.createElement('settings-main'); | 71 settingsMain = document.createElement('settings-main'); |
| 72 settingsMain.prefs = settingsPrefs.prefs; | 72 settingsMain.prefs = settingsPrefs.prefs; |
| 73 settingsMain.toolbarSpinnerActive = false; | 73 settingsMain.toolbarSpinnerActive = false; |
| 74 document.body.appendChild(settingsMain); | 74 document.body.appendChild(settingsMain); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 teardown(function() { settingsMain.remove(); }); | 77 teardown(function() { settingsMain.remove(); }); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 */ | 198 */ |
| 199 function assertAdvancedVisibilityAfterSearch(expectedAdvanced) { | 199 function assertAdvancedVisibilityAfterSearch(expectedAdvanced) { |
| 200 searchManager.setMatchesFound(true); | 200 searchManager.setMatchesFound(true); |
| 201 return settingsMain.searchContents('Query1') | 201 return settingsMain.searchContents('Query1') |
| 202 .then(function() { | 202 .then(function() { |
| 203 searchManager.setMatchesFound(false); | 203 searchManager.setMatchesFound(false); |
| 204 return settingsMain.searchContents(''); | 204 return settingsMain.searchContents(''); |
| 205 }) | 205 }) |
| 206 .then(function() { | 206 .then(function() { |
| 207 // Imitate behavior of clearing search. | 207 // Imitate behavior of clearing search. |
| 208 settings.navigateTo(settings.Route.BASIC); | 208 settings.navigateTo(settings.routes.BASIC); |
| 209 Polymer.dom.flush(); | 209 Polymer.dom.flush(); |
| 210 return assertPageVisibility('block', expectedAdvanced); | 210 return assertPageVisibility('block', expectedAdvanced); |
| 211 }); | 211 }); |
| 212 } | 212 } |
| 213 | 213 |
| 214 test('exiting search mode, advanced collapsed', function() { | 214 test('exiting search mode, advanced collapsed', function() { |
| 215 // Simulating searching while the advanced page is collapsed. | 215 // Simulating searching while the advanced page is collapsed. |
| 216 settingsMain.currentRouteChanged(settings.Route.BASIC); | 216 settingsMain.currentRouteChanged(settings.routes.BASIC); |
| 217 Polymer.dom.flush(); | 217 Polymer.dom.flush(); |
| 218 return assertAdvancedVisibilityAfterSearch('none'); | 218 return assertAdvancedVisibilityAfterSearch('none'); |
| 219 }); | 219 }); |
| 220 | 220 |
| 221 // Ensure that clearing the search results restores both "basic" and | 221 // Ensure that clearing the search results restores both "basic" and |
| 222 // "advanced" page, when the search has been initiated from a subpage | 222 // "advanced" page, when the search has been initiated from a subpage |
| 223 // whose parent is the "advanced" page. | 223 // whose parent is the "advanced" page. |
| 224 test('exiting search mode, advanced expanded', function() { | 224 test('exiting search mode, advanced expanded', function() { |
| 225 settings.navigateTo(settings.Route.SITE_SETTINGS); | 225 settings.navigateTo(settings.routes.SITE_SETTINGS); |
| 226 Polymer.dom.flush(); | 226 Polymer.dom.flush(); |
| 227 return assertAdvancedVisibilityAfterSearch('block'); | 227 return assertAdvancedVisibilityAfterSearch('block'); |
| 228 }); | 228 }); |
| 229 | 229 |
| 230 // Ensure that searching, then entering a subpage, then going back | 230 // Ensure that searching, then entering a subpage, then going back |
| 231 // lands the user in a page where both basic and advanced sections are | 231 // lands the user in a page where both basic and advanced sections are |
| 232 // visible, because the page is still in search mode. | 232 // visible, because the page is still in search mode. |
| 233 test('returning from subpage to search results', function() { | 233 test('returning from subpage to search results', function() { |
| 234 settings.navigateTo(settings.Route.BASIC); | 234 settings.navigateTo(settings.routes.BASIC); |
| 235 Polymer.dom.flush(); | 235 Polymer.dom.flush(); |
| 236 | 236 |
| 237 searchManager.setMatchesFound(true); | 237 searchManager.setMatchesFound(true); |
| 238 return settingsMain.searchContents('Query1').then(function() { | 238 return settingsMain.searchContents('Query1').then(function() { |
| 239 // Simulate navigating into a subpage. | 239 // Simulate navigating into a subpage. |
| 240 settings.navigateTo(settings.Route.SEARCH_ENGINES); | 240 settings.navigateTo(settings.routes.SEARCH_ENGINES); |
| 241 settingsMain.$$('settings-basic-page').fire('subpage-expand'); | 241 settingsMain.$$('settings-basic-page').fire('subpage-expand'); |
| 242 Polymer.dom.flush(); | 242 Polymer.dom.flush(); |
| 243 | 243 |
| 244 // Simulate clicking the left arrow to go back to the search results. | 244 // Simulate clicking the left arrow to go back to the search results. |
| 245 settings.navigateTo(settings.Route.BASIC); | 245 settings.navigateTo(settings.routes.BASIC); |
| 246 return assertPageVisibility('block', 'block'); | 246 return assertPageVisibility('block', 'block'); |
| 247 }); | 247 }); |
| 248 }); | 248 }); |
| 249 | 249 |
| 250 // TODO(michaelpg): Move these to a new test for settings-basic-page. | 250 // TODO(michaelpg): Move these to a new test for settings-basic-page. |
| 251 test('can collapse advanced on advanced section route', function() { | 251 test('can collapse advanced on advanced section route', function() { |
| 252 settings.navigateTo(settings.Route.PRIVACY); | 252 settings.navigateTo(settings.routes.PRIVACY); |
| 253 Polymer.dom.flush(); | 253 Polymer.dom.flush(); |
| 254 | 254 |
| 255 var basicPage = settingsMain.$$('settings-basic-page'); | 255 var basicPage = settingsMain.$$('settings-basic-page'); |
| 256 var advancedPage = null; | 256 var advancedPage = null; |
| 257 return basicPage.$$('#advancedPageTemplate').get().then( | 257 return basicPage.$$('#advancedPageTemplate').get().then( |
| 258 function(advanced) { | 258 function(advanced) { |
| 259 advancedPage = advanced; | 259 advancedPage = advanced; |
| 260 return assertPageVisibility('block', 'block'); | 260 return assertPageVisibility('block', 'block'); |
| 261 }).then(function() { | 261 }).then(function() { |
| 262 var whenHidden = test_util.whenAttributeIs( | 262 var whenHidden = test_util.whenAttributeIs( |
| 263 advancedPage, 'hidden', ''); | 263 advancedPage, 'hidden', ''); |
| 264 | 264 |
| 265 var advancedToggle = | 265 var advancedToggle = |
| 266 getToggleContainer().querySelector('#advancedToggle'); | 266 getToggleContainer().querySelector('#advancedToggle'); |
| 267 assertTrue(!!advancedToggle); | 267 assertTrue(!!advancedToggle); |
| 268 MockInteractions.tap(advancedToggle); | 268 MockInteractions.tap(advancedToggle); |
| 269 | 269 |
| 270 return whenHidden; | 270 return whenHidden; |
| 271 }).then(function() { | 271 }).then(function() { |
| 272 return assertPageVisibility('block', 'none'); | 272 return assertPageVisibility('block', 'none'); |
| 273 }); | 273 }); |
| 274 }); | 274 }); |
| 275 | 275 |
| 276 test('navigating to a basic page does not collapse advanced', function() { | 276 test('navigating to a basic page does not collapse advanced', function() { |
| 277 settings.navigateTo(settings.Route.PRIVACY); | 277 settings.navigateTo(settings.routes.PRIVACY); |
| 278 Polymer.dom.flush(); | 278 Polymer.dom.flush(); |
| 279 | 279 |
| 280 assertToggleContainerVisible(true); | 280 assertToggleContainerVisible(true); |
| 281 | 281 |
| 282 settings.navigateTo(settings.Route.PEOPLE); | 282 settings.navigateTo(settings.routes.PEOPLE); |
| 283 Polymer.dom.flush(); | 283 Polymer.dom.flush(); |
| 284 | 284 |
| 285 return assertPageVisibility('block', 'block'); | 285 return assertPageVisibility('block', 'block'); |
| 286 }); | 286 }); |
| 287 }); | 287 }); |
| 288 } | 288 } |
| 289 | 289 |
| 290 return { | 290 return { |
| 291 registerTests: registerTests, | 291 registerTests: registerTests, |
| 292 }; | 292 }; |
| 293 }); | 293 }); |
| OLD | NEW |