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

Unified Diff: chrome/test/data/webui/settings/route_tests.js

Issue 2297663008: MD Settings: Prevent unexpected scrolling to section on popstates. (Closed)
Patch Set: add 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/settings/settings_page/main_page_behavior.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 ed9d7b5cb14612ae828cf9489a6be698712c4a38..302f2f57115288b60d16bbec06bbaa64eb0bd60e 100644
--- a/chrome/test/data/webui/settings/route_tests.js
+++ b/chrome/test/data/webui/settings/route_tests.js
@@ -3,6 +3,42 @@
// found in the LICENSE file.
suite('route', function() {
+ /**
+ * Returns a new promise that resolves after a window 'popstate' event.
+ * @return {!Promise}
+ */
+ function whenPopState(causeEvent) {
+ var promise = new Promise(function(resolve) {
+ window.addEventListener('popstate', function callback() {
+ window.removeEventListener('popstate', callback);
+ resolve();
+ });
+ });
+
+ causeEvent();
+ return promise;
+ }
+
+ /**
+ * Tests a specific navigation situation.
+ * @param {!settings.Route} previousRoute
+ * @param {!settings.Route} currentRoute
+ * @param {!settings.Route} expectedNavigatePreviousResult
+ * @return {!Promise}
+ */
+ function testNavigateBackUsesHistory(previousRoute, currentRoute,
+ expectedNavigatePreviousResult) {
+ settings.navigateTo(previousRoute);
+ settings.navigateTo(currentRoute);
+
+ return whenPopState(function() {
+ settings.navigateToPreviousRoute();
+ }).then(function() {
+ assertEquals(expectedNavigatePreviousResult,
+ settings.getCurrentRoute());
+ });
+ };
+
test('tree structure', function() {
// Set up root page routes.
var BASIC = new settings.Route('/');
@@ -55,38 +91,6 @@ suite('route', function() {
});
});
- /**
- * Tests a specific navigation situation.
- * @param {!settings.Route} previousRoute
- * @param {!settings.Route} currentRoute
- * @param {!settings.Route} expectedNavigatePreviousResult
- * @return {!Promise}
- */
- function testNavigateBackUsesHistory(previousRoute, currentRoute,
- expectedNavigatePreviousResult) {
- /**
- * Returns a new promise that resolves after a window 'popstate' event.
- * @return {!Promise}
- */
- function whenPopState() {
- return new Promise(function(resolve) {
- window.addEventListener('popstate', function callback() {
- window.removeEventListener('popstate', callback);
- resolve();
- });
- });
- }
-
- 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 testNavigateBackUsesHistory(
settings.Route.BASIC,
@@ -121,4 +125,22 @@ suite('route', function() {
settings.navigateToPreviousRoute();
assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
});
+
+ test('popstate flag works', function() {
+ settings.navigateTo(settings.Route.BASIC);
+ assertFalse(settings.lastRouteChangeWasPopstate());
+
+ settings.navigateTo(settings.Route.PEOPLE);
+ assertFalse(settings.lastRouteChangeWasPopstate());
+
+ return whenPopState(function() {
+ window.history.back();
+ }).then(function() {
+ assertEquals(settings.Route.BASIC, settings.getCurrentRoute());
+ assertTrue(settings.lastRouteChangeWasPopstate());
+
+ settings.navigateTo(settings.Route.ADVANCED);
+ assertFalse(settings.lastRouteChangeWasPopstate());
+ });
+ });
});
« no previous file with comments | « chrome/browser/resources/settings/settings_page/main_page_behavior.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698