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

Unified 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: add sundry tests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/settings/route.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/settings/route_tests.js
diff --git a/chrome/test/data/webui/settings/route_tests.js b/chrome/test/data/webui/settings/route_tests.js
index fd36bac1e821e26a0d6cfb9dd097f2006e5cf003..9d98b062309a3b295180e98d692a7ce683ddb49a 100644
--- a/chrome/test/data/webui/settings/route_tests.js
+++ b/chrome/test/data/webui/settings/route_tests.js
@@ -54,4 +54,66 @@ suite('route', function() {
paths.add(route.path);
});
});
+
+ /**
+ * Tests a specific navigation situation.
+ * @param {!settings.Route} previousRoute
+ * @param {!settings.Route} currentRoute
+ * @param {!settings.Route} expectedNavigatePreviousResult
+ * @return {!Promise}
+ */
+ function testNavigateBack(previousRoute, currentRoute,
michaelpg 2016/08/24 20:25:08 testNavigateBackUsesHistory
tommycli 2016/08/24 20:41:36 Done.
+ expectedNavigatePreviousResult) {
+ /**
+ * Returns a new promise that resolves after a window 'popstate' event.
+ * @return {!Promise}
+ */
+ function whenPopState() {
+ return new Promise(function(resolve) {
+ var callback = function() {
+ window.removeEventListener('popstate', callback);
+ resolve();
+ };
+ 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
+ });
+ }
+
+ settings.navigateTo(previousRoute);
+ settings.navigateTo(currentRoute);
+ settings.navigateToPreviousRoute();
+
+ return whenPopState().then(function() {
+ assertEquals(expectedNavigatePreviousResult,
+ settings.getCurrentRoute());
+ });
+ };
+
+ test('navigate back to parent previous route', function() {
+ return testNavigateBack(settings.Route.BASIC, settings.Route.PEOPLE,
+ settings.Route.BASIC);
+ });
+
+ test('navigate back to non-ancestor shallower route', function() {
+ return testNavigateBack(settings.Route.ADVANCED, settings.Route.PEOPLE,
+ settings.Route.ADVANCED);
+ });
+
+ test('navigate back to sibling route', function() {
+ return testNavigateBack(settings.Route.APPEARANCE, settings.Route.PEOPLE,
+ settings.Route.APPEARANCE);
+ });
+
+ test('navigate back to parent when previous route is deeper', function() {
+ settings.navigateTo(settings.Route.SYNC);
+ settings.navigateTo(settings.Route.PEOPLE);
+ settings.navigateToPreviousRoute();
+ assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
+ });
+
+ test('navigate back to BASIC when going back from root pages', function() {
+ settings.navigateTo(settings.Route.PEOPLE);
+ settings.navigateTo(settings.Route.ADVANCED);
+ settings.navigateToPreviousRoute();
+ assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
+ });
});
« 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