| 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 suite('route', function() { | 5 suite('route', function() { |
| 6 /** | 6 /** |
| 7 * Returns a new promise that resolves after a window 'popstate' event. | 7 * Returns a new promise that resolves after a window 'popstate' event. |
| 8 * @return {!Promise} | 8 * @return {!Promise} |
| 9 */ | 9 */ |
| 10 function whenPopState(causeEvent) { | 10 function whenPopState(causeEvent) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | 119 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); |
| 120 }); | 120 }); |
| 121 | 121 |
| 122 test('navigate back to BASIC when going back from root pages', function() { | 122 test('navigate back to BASIC when going back from root pages', function() { |
| 123 settings.navigateTo(settings.Route.PEOPLE); | 123 settings.navigateTo(settings.Route.PEOPLE); |
| 124 settings.navigateTo(settings.Route.ADVANCED); | 124 settings.navigateTo(settings.Route.ADVANCED); |
| 125 settings.navigateToPreviousRoute(); | 125 settings.navigateToPreviousRoute(); |
| 126 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | 126 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); |
| 127 }); | 127 }); |
| 128 | 128 |
| 129 test('navigateTo respects removeSearch optional parameter', function() { |
| 130 var params = new URLSearchParams('search=foo'); |
| 131 settings.navigateTo(settings.Route.BASIC, params); |
| 132 assertEquals(params.toString(), settings.getQueryParameters().toString()); |
| 133 |
| 134 settings.navigateTo( |
| 135 settings.Route.SITE_SETTINGS, null, /* removeSearch */ false); |
| 136 assertEquals(params.toString(), settings.getQueryParameters().toString()); |
| 137 |
| 138 settings.navigateTo( |
| 139 settings.Route.SEARCH_ENGINES, null, /* removeSearch */ true); |
| 140 assertEquals('', settings.getQueryParameters().toString()); |
| 141 }); |
| 142 |
| 129 test('popstate flag works', function() { | 143 test('popstate flag works', function() { |
| 130 settings.navigateTo(settings.Route.BASIC); | 144 settings.navigateTo(settings.Route.BASIC); |
| 131 assertFalse(settings.lastRouteChangeWasPopstate()); | 145 assertFalse(settings.lastRouteChangeWasPopstate()); |
| 132 | 146 |
| 133 settings.navigateTo(settings.Route.PEOPLE); | 147 settings.navigateTo(settings.Route.PEOPLE); |
| 134 assertFalse(settings.lastRouteChangeWasPopstate()); | 148 assertFalse(settings.lastRouteChangeWasPopstate()); |
| 135 | 149 |
| 136 return whenPopState(function() { | 150 return whenPopState(function() { |
| 137 window.history.back(); | 151 window.history.back(); |
| 138 }).then(function() { | 152 }).then(function() { |
| 139 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | 153 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); |
| 140 assertTrue(settings.lastRouteChangeWasPopstate()); | 154 assertTrue(settings.lastRouteChangeWasPopstate()); |
| 141 | 155 |
| 142 settings.navigateTo(settings.Route.ADVANCED); | 156 settings.navigateTo(settings.Route.ADVANCED); |
| 143 assertFalse(settings.lastRouteChangeWasPopstate()); | 157 assertFalse(settings.lastRouteChangeWasPopstate()); |
| 144 }); | 158 }); |
| 145 }); | 159 }); |
| 146 }); | 160 }); |
| OLD | NEW |