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 test('tree structure', function() { | 6 test('tree structure', function() { |
7 // Set up root page routes. | 7 // Set up root page routes. |
8 var BASIC = new settings.Route('/'); | 8 var BASIC = new settings.Route('/'); |
9 assertEquals(0, BASIC.depth); | 9 assertEquals(0, BASIC.depth); |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 assertEquals('', CLEAR_BROWSER_DATA.section); | 47 assertEquals('', CLEAR_BROWSER_DATA.section); |
48 }); | 48 }); |
49 | 49 |
50 test('no duplicate routes', function() { | 50 test('no duplicate routes', function() { |
51 var paths = new Set(); | 51 var paths = new Set(); |
52 Object.values(settings.Route).forEach(function(route) { | 52 Object.values(settings.Route).forEach(function(route) { |
53 assertFalse(paths.has(route.path), route.path); | 53 assertFalse(paths.has(route.path), route.path); |
54 paths.add(route.path); | 54 paths.add(route.path); |
55 }); | 55 }); |
56 }); | 56 }); |
57 | |
58 /** | |
59 * Tests a specific navigation situation. | |
60 * @param {!settings.Route} previousRoute | |
61 * @param {!settings.Route} currentRoute | |
62 * @param {!settings.Route} expectedNavigatePreviousResult | |
63 * @return {!Promise} | |
64 */ | |
65 function testNavigateBack(previousRoute, currentRoute, | |
michaelpg
2016/08/24 20:25:08
testNavigateBackUsesHistory
tommycli
2016/08/24 20:41:36
Done.
| |
66 expectedNavigatePreviousResult) { | |
67 /** | |
68 * Returns a new promise that resolves after a window 'popstate' event. | |
69 * @return {!Promise} | |
70 */ | |
71 function whenPopState() { | |
72 return new Promise(function(resolve) { | |
73 var callback = function() { | |
74 window.removeEventListener('popstate', callback); | |
75 resolve(); | |
76 }; | |
77 window.addEventListener('popstate', callback); | |
michaelpg
2016/08/24 20:25:08
opt nit: I prefer this pattern without a variable:
tommycli
2016/08/24 20:41:36
Done. Whoa... i didn't even know that was possible
| |
78 }); | |
79 } | |
80 | |
81 settings.navigateTo(previousRoute); | |
82 settings.navigateTo(currentRoute); | |
83 settings.navigateToPreviousRoute(); | |
84 | |
85 return whenPopState().then(function() { | |
86 assertEquals(expectedNavigatePreviousResult, | |
87 settings.getCurrentRoute()); | |
88 }); | |
89 }; | |
90 | |
91 test('navigate back to parent previous route', function() { | |
92 return testNavigateBack(settings.Route.BASIC, settings.Route.PEOPLE, | |
93 settings.Route.BASIC); | |
94 }); | |
95 | |
96 test('navigate back to non-ancestor shallower route', function() { | |
97 return testNavigateBack(settings.Route.ADVANCED, settings.Route.PEOPLE, | |
98 settings.Route.ADVANCED); | |
99 }); | |
100 | |
101 test('navigate back to sibling route', function() { | |
102 return testNavigateBack(settings.Route.APPEARANCE, settings.Route.PEOPLE, | |
103 settings.Route.APPEARANCE); | |
104 }); | |
105 | |
106 test('navigate back to parent when previous route is deeper', function() { | |
107 settings.navigateTo(settings.Route.SYNC); | |
108 settings.navigateTo(settings.Route.PEOPLE); | |
109 settings.navigateToPreviousRoute(); | |
110 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | |
111 }); | |
112 | |
113 test('navigate back to BASIC when going back from root pages', function() { | |
114 settings.navigateTo(settings.Route.PEOPLE); | |
115 settings.navigateTo(settings.Route.ADVANCED); | |
116 settings.navigateToPreviousRoute(); | |
117 assertEquals(settings.Route.BASIC, settings.getCurrentRoute()); | |
118 }); | |
57 }); | 119 }); |
OLD | NEW |