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

Unified Diff: LayoutTests/fast/history/scroll-restoration/scroll-restoration-push-replace.html

Issue 1239463005: Replace history.options with history.scrollRestoration attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move setScrollRestorationType to History Created 5 years, 5 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
Index: LayoutTests/fast/history/scroll-restoration/scroll-restoration-push-replace.html
diff --git a/LayoutTests/fast/history/scroll-restoration/scroll-restoration-push-replace.html b/LayoutTests/fast/history/scroll-restoration/scroll-restoration-push-replace.html
new file mode 100644
index 0000000000000000000000000000000000000000..3db338f7ca74140e3e322af9c91f3ad537f367cf
--- /dev/null
+++ b/LayoutTests/fast/history/scroll-restoration/scroll-restoration-push-replace.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<style>
+ body {
+ height: 2000px;
+ width: 2000px;
+ }
+</style>
+
+<body></body>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script type="text/javascript">
+ 'use strict';
+
+ async_test(function(t) {
+ history.scrollRestoration = 'auto';
+ window.scrollTo(0, 0);
+
+ // create history entries and then verify the impact of scrollRestoration
+ // when they are popped
+ var entries = {
+ /* TODO: spec does not defines behavior of 'auto' so we should not expect scroll position for these */
+ '#1': {type: 'push', expectedScroll: [50, 100], scrollRestoration: 'auto'},
+ '#2': {type: 'replace', expectedScroll: [100, 200], scrollRestoration: 'auto'},
+ /* Scroll position should not be restored for these. */
+ '#3': {type: 'push', expectedScroll: [555, 555], scrollRestoration: 'manual'},
+ '#4': {type: 'replace', expectedScroll: [555, 555], scrollRestoration: 'manual'}
+ };
+
+ // setup entries
+ for (var key in entries) {
+ var entry = entries[key],
+ beforeValue = history.scrollRestoration,
+ newValue = entry.scrollRestoration;
+
+ var args = [{key: key}, '', key];
+ if (entry.type == 'push') {
+ history.pushState.apply(history, args);
+ } else {
+ history.pushState(null, '', key);
+ history.replaceState.apply(history, args);
+ }
+ assert_equals(history.scrollRestoration, beforeValue, `${entry.type} retain current history.scrollRestoration value`);
+ history.scrollRestoration = newValue;
+ assert_equals(history.scrollRestoration, newValue, `Setting scrollRestoration to ${newValue} does expected`);
+ window.scrollBy(50, 100);
+ }
+ assert_equals(history.length, 5, 'history entries match expectation');
+
+ // setup verification
+ window.addEventListener('hashchange', t.step_func(function() {
+ var key = location.hash,
+ entry = entries[key];
+
+ if (key === '') {
+ t.done();
+ return;
+ }
+ console.log(`verifying ${key}`);
+ assert_equals(history.state.key, key, `state should have key: ${key}`);
+ assert_equals(document.body.scrollLeft, entry.expectedScroll[0], `scrollLeft is correct for ${key}`);
+ assert_equals(document.body.scrollTop, entry.expectedScroll[1], `scrollTop is correct ${key}`);
+
+ window.history.back();
+ }));
+
+ // Reset the scroll and kick off the verification
+ setTimeout(function() {
+ history.pushState(null, null, '#done');
+ window.scrollTo(555, 555);
+ window.history.back();
+ }, 0);
+
+ }, 'history.{push,replace}State retain and respect history.scrollRestoration');
+</script>

Powered by Google App Engine
This is Rietveld 408576698