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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <style>
3 body {
4 height: 2000px;
5 width: 2000px;
6 }
7 </style>
8
9 <body></body>
10 <script src="../../../resources/testharness.js"></script>
11 <script src="../../../resources/testharnessreport.js"></script>
12 <script type="text/javascript">
13 'use strict';
14
15 async_test(function(t) {
16 history.scrollRestoration = 'auto';
17 window.scrollTo(0, 0);
18
19 // create history entries and then verify the impact of scrollRestoration
20 // when they are popped
21 var entries = {
22 /* TODO: spec does not defines behavior of 'auto' so we should not expect scroll position for these */
23 '#1': {type: 'push', expectedScroll: [50, 100], scrollRestoration: 'au to'},
24 '#2': {type: 'replace', expectedScroll: [100, 200], scrollRestoration: 'au to'},
25 /* Scroll position should not be restored for these. */
26 '#3': {type: 'push', expectedScroll: [555, 555], scrollRestoration: 'ma nual'},
27 '#4': {type: 'replace', expectedScroll: [555, 555], scrollRestoration: 'ma nual'}
28 };
29
30 // setup entries
31 for (var key in entries) {
32 var entry = entries[key],
33 beforeValue = history.scrollRestoration,
34 newValue = entry.scrollRestoration;
35
36 var args = [{key: key}, '', key];
37 if (entry.type == 'push') {
38 history.pushState.apply(history, args);
39 } else {
40 history.pushState(null, '', key);
41 history.replaceState.apply(history, args);
42 }
43 assert_equals(history.scrollRestoration, beforeValue, `${entry.type} retai n current history.scrollRestoration value`);
44 history.scrollRestoration = newValue;
45 assert_equals(history.scrollRestoration, newValue, `Setting scrollRestorat ion to ${newValue} does expected`);
46 window.scrollBy(50, 100);
47 }
48 assert_equals(history.length, 5, 'history entries match expectation');
49
50 // setup verification
51 window.addEventListener('hashchange', t.step_func(function() {
52 var key = location.hash,
53 entry = entries[key];
54
55 if (key === '') {
56 t.done();
57 return;
58 }
59 console.log(`verifying ${key}`);
60 assert_equals(history.state.key, key, `state should have key: ${key}`);
61 assert_equals(document.body.scrollLeft, entry.expectedScroll[0], `scrollLe ft is correct for ${key}`);
62 assert_equals(document.body.scrollTop, entry.expectedScroll[1], `scrollTop is correct ${key}`);
63
64 window.history.back();
65 }));
66
67 // Reset the scroll and kick off the verification
68 setTimeout(function() {
69 history.pushState(null, null, '#done');
70 window.scrollTo(555, 555);
71 window.history.back();
72 }, 0);
73
74 }, 'history.{push,replace}State retain and respect history.scrollRestoration') ;
75 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698