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_subpage', function() { | 5 cr.define('settings_subpage', function() { |
6 function registerTests() { | 6 function registerTests() { |
7 suite('SettingsSubpage', function() { | 7 suite('SettingsSubpage', function() { |
8 test('can navigate to parent', function() { | 8 test('navigates to parent when there is no history', function() { |
9 PolymerTest.clearBody(); | 9 PolymerTest.clearBody(); |
10 | 10 |
11 // Choose CERTIFICATES since it is not a descendant of BASIC. | 11 // Pretend that we initially started on the CERTIFICATES route. |
12 settings.navigateTo(settings.Route.CERTIFICATES); | 12 window.history.replaceState( |
| 13 undefined, '', settings.Route.CERTIFICATES.path); |
| 14 settings.initializeRouteFromUrl(); |
13 assertEquals(settings.Route.CERTIFICATES, settings.getCurrentRoute()); | 15 assertEquals(settings.Route.CERTIFICATES, settings.getCurrentRoute()); |
14 | 16 |
15 var subpage = document.createElement('settings-subpage'); | 17 var subpage = document.createElement('settings-subpage'); |
16 document.body.appendChild(subpage); | 18 document.body.appendChild(subpage); |
17 | 19 |
18 MockInteractions.tap(subpage.$$('paper-icon-button')); | 20 MockInteractions.tap(subpage.$$('paper-icon-button')); |
19 assertEquals(settings.Route.PRIVACY, settings.getCurrentRoute()); | 21 assertEquals(settings.Route.PRIVACY, settings.getCurrentRoute()); |
20 }); | 22 }); |
21 | 23 |
22 test('can navigate to grandparent using window.back()', function(done) { | 24 test('navigates to any route via window.back()', function(done) { |
23 PolymerTest.clearBody(); | 25 PolymerTest.clearBody(); |
24 | 26 |
25 settings.navigateTo(settings.Route.BASIC); | 27 settings.navigateTo(settings.Route.BASIC); |
26 settings.navigateTo(settings.Route.SYNC); | 28 settings.navigateTo(settings.Route.SYNC); |
27 assertEquals(settings.Route.SYNC, settings.getCurrentRoute()); | 29 assertEquals(settings.Route.SYNC, settings.getCurrentRoute()); |
28 | 30 |
29 var subpage = document.createElement('settings-subpage'); | 31 var subpage = document.createElement('settings-subpage'); |
30 document.body.appendChild(subpage); | 32 document.body.appendChild(subpage); |
31 | 33 |
32 MockInteractions.tap(subpage.$$('paper-icon-button')); | 34 MockInteractions.tap(subpage.$$('paper-icon-button')); |
33 | 35 |
34 // Since the previous history entry is an ancestor, we expect | |
35 // window.history.back() to be called and a popstate event to be fired. | |
36 window.addEventListener('popstate', function(event) { | 36 window.addEventListener('popstate', function(event) { |
37 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | 37 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); |
38 done(); | 38 done(); |
39 }); | 39 }); |
40 }); | 40 }); |
41 }); | 41 }); |
42 } | 42 } |
43 | 43 |
44 return { | 44 return { |
45 registerTests: registerTests, | 45 registerTests: registerTests, |
46 }; | 46 }; |
47 }); | 47 }); |
OLD | NEW |