Index: LayoutTests/fast/loader/scroll-position-restoration-for-history-api.html |
diff --git a/LayoutTests/fast/loader/scroll-position-restoration-for-history-api.html b/LayoutTests/fast/loader/scroll-position-restoration-for-history-api.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85a58c5a0320722b9e3abbe6245217e40270fa8e |
--- /dev/null |
+++ b/LayoutTests/fast/loader/scroll-position-restoration-for-history-api.html |
@@ -0,0 +1,75 @@ |
+<!DOCTYPE html> |
+<style> |
+body { |
+ height: 2000px; |
+ width: 2000px; |
+} |
+</style> |
+ |
+<div id='console'></div> |
+<script src="../../resources/js-test.js"></script> |
+<script> |
+window.jsTestIsAsync = true; |
+description('This test verifies that navigating to entries created by ' + |
+ 'pushState or replaceState correctly restores scroll position ' + |
+ 'correctly and respects "willRestoreScroll" flag.'); |
+ |
+var tests = { |
+ '#1': {type: 'push', expectedScroll: [50, 100]}, |
+ '#2': {type: 'replace', expectedScroll: [100, 200]}, |
+ '#3': {type: 'push', expectedScroll: [150, 300], options: {willRestoreScroll: false}}, |
+ '#4': {type: 'replace', expectedScroll: [200, 400], options: {willRestoreScroll: false}}, |
+ /* Scroll position should not be restored for these two. */ |
+ '#5': {type: 'push', expectedScroll: [0, 0], options: {willRestoreScroll: true}}, |
+ '#6': {type: 'replace', expectedScroll: [0, 0], options: {willRestoreScroll: true}} |
+}; |
+ |
+// Navigation steps: |
+// 1. Create a history entry using pushState then scroll |
+// 2. Create a history entry and replace it then scroll |
+// 3-6. Repeat 1 & 2 with different option values |
+// 7. Navigate away and come back |
+// 8-13. Verify 6 to 1 and keep navigating back |
+function handleNavigation() { |
+ if (window.name !== 'verification phase') { |
+ for (var key in tests) { |
+ var test = tests[key]; |
+ var args = [{key: key}, '', key]; |
+ if ('options' in test) |
+ args.push(test.options); |
+ |
+ if (test.type == 'push') { |
+ history.pushState.apply(history, args); |
+ } else { |
+ history.pushState(null, '', key); |
+ history.replaceState.apply(history, args); |
+ } |
+ |
+ window.scrollBy(50, 100); |
+ } |
+ |
+ setTimeout(function() { |
+ window.name = 'verification phase'; |
+ window.location.href = 'resources/empty-document-goes-back.html'; |
+ }, 0); |
+ } else { |
+ var key = location.hash, |
+ test = tests[key]; |
+ |
+ debug('verifying ' + key); |
+ shouldBeEqualToString('history.state.key', '' + key); |
+ shouldBe('document.body.scrollLeft', test.expectedScroll[0].toString()); |
+ shouldBe('document.body.scrollTop', test.expectedScroll[1].toString()); |
+ |
+ if (key !== '#1') { |
+ window.history.back(); |
+ } else { |
+ window.name = ''; |
+ finishJSTest(); |
+ } |
+ } |
+} |
+ |
+window.addEventListener('pageshow', handleNavigation); |
+window.addEventListener('hashchange', handleNavigation); |
+</script> |