1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<!DOCTYPE html>
<meta name=timeout content=long>
<title>Correct behaviour of scroll restoration mode is cross origin history traversal</title>
<style>
iframe {
height: 300px;
width: 300px;
}
</style>
<body>
<iframe></iframe>
</body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
'use strict';
// The test does the following navigation steps for iframe
// 1. load blank1
// 2. load blank2
// 3. go back to blank1
async_test(function(t) {
var iframe = document.querySelector('iframe');
var baseURL = location.href.substring(0, location.href.lastIndexOf('/'));
var steps = [
function() {
iframe.src = 'resources/blank1.html';
},
function() {
assert_equals(iframe.contentWindow.location.href, baseURL + '/resources/blank1.html', 'should be on first blank page');
iframe.contentWindow.history.scrollRestoration = 'manual';
assert_equals(iframe.contentWindow.history.scrollRestoration, 'manual');
iframe.contentWindow.scrollTo(500, 500);
assert_equals(iframe.contentWindow.scrollX, 500, 'scripted scrolling should take effect');
assert_equals(iframe.contentWindow.scrollY, 500, 'scripted scrolling should take effect');
setTimeout(next, 0);
},
function() {
// navigate to new page
iframe.src = 'resources/blank2.html';
},
function() {
assert_equals(iframe.contentWindow.location.href, baseURL + '/resources/blank2.html', 'should be on second blank page');
assert_equals(iframe.contentWindow.history.scrollRestoration, 'auto', 'new page loads should set scrollRestoration to "auto"');
setTimeout(next, 0);
}, function() {
iframe.contentWindow.history.back();
}, function() {
// coming back scrollRestoration should be restored to 'manual' and respected
assert_equals(iframe.contentWindow.location.href, baseURL + '/resources/blank1.html', 'should be back on first blank page');
assert_equals(iframe.contentWindow.history.scrollRestoration, 'manual', 'navigating back should retain scrollRestoration value');
assert_equals(iframe.contentWindow.scrollX, 0, 'horizontal scroll offset should not be restored');
assert_equals(iframe.contentWindow.scrollY, 0, 'vertical scroll offset should not be restored');
t.done();
}
];
var stepCount = 0;
var next = t.step_func(function() {
steps[stepCount++]();
});
iframe.onload = next;
next();
}, 'Navigating to new page should reset to "auto" and navigating back should restore and respect scroll restoration mode');
</script>
|