Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: chrome/test/data/webui/settings/route_tests.js

Issue 2271003003: Settings Router: Restrict navigateToPreviousRoute from going deeper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/route.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 testNavigateBackUsesHistory(previousRoute, currentRoute,
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 window.addEventListener('popstate', function callback() {
74 window.removeEventListener('popstate', callback);
75 resolve();
76 });
77 });
78 }
79
80 settings.navigateTo(previousRoute);
81 settings.navigateTo(currentRoute);
82 settings.navigateToPreviousRoute();
83
84 return whenPopState().then(function() {
85 assertEquals(expectedNavigatePreviousResult,
86 settings.getCurrentRoute());
87 });
88 };
89
90 test('navigate back to parent previous route', function() {
91 return testNavigateBackUsesHistory(
92 settings.Route.BASIC,
93 settings.Route.PEOPLE,
94 settings.Route.BASIC);
95 });
96
97 test('navigate back to non-ancestor shallower route', function() {
98 return testNavigateBackUsesHistory(
99 settings.Route.ADVANCED,
100 settings.Route.PEOPLE,
101 settings.Route.ADVANCED);
102 });
103
104 test('navigate back to sibling route', function() {
105 return testNavigateBackUsesHistory(
106 settings.Route.APPEARANCE,
107 settings.Route.PEOPLE,
108 settings.Route.APPEARANCE);
109 });
110
111 test('navigate back to parent when previous route is deeper', function() {
112 settings.navigateTo(settings.Route.SYNC);
113 settings.navigateTo(settings.Route.PEOPLE);
114 settings.navigateToPreviousRoute();
115 assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
116 });
117
118 test('navigate back to BASIC when going back from root pages', function() {
119 settings.navigateTo(settings.Route.PEOPLE);
120 settings.navigateTo(settings.Route.ADVANCED);
121 settings.navigateToPreviousRoute();
122 assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
123 });
57 }); 124 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/route.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698