summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/loader/stateobjects/document-destroyed-navigate-back-with-fragment-scroll.html
blob: 0a533a812417a7e0766ea5f2d5cb58b9c30d646d (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html>
<head>
<script>

if (window.testRunner) {
    if (!sessionStorage.stage)
        testRunner.clearBackForwardList();
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function lastPathComponent(url)
{
    return url.split('/').pop();
}

function hashOf(url)
{
    return url.substring(url.lastIndexOf('#'));
}

function runFirstStageOfTest()
{
    history.replaceState("FirstEntry", null, "#FirstEntry");
    history.pushState("SecondEntry", null, "#SecondEntry");
    history.back();
}

function runTest()
{
    alert("LOADED");
    if (!sessionStorage.stage)
        runFirstStageOfTest();
}

function continueTest(state)
{
    // FIXME: Once the popstate and hashchange events fire asynchronously, we
    // can eliminate this setTimeout hack.  The hashchange event currently runs
    // synchronously following the popstate event, but the calls to
    // replaceState cause the location to change immediately.  That confuses
    // our hashchange handler, which expects to see the "old" value of the
    // location.

    setTimeout(function() {
        if (state == "FirstEntry") {
            history.replaceState("FirstEntryWillLaterBeReactivated", null, "#FirstEntryWillLaterBeReactivated");
            history.forward();
        } else if (state == "SecondEntry") {
            history.replaceState("SecondEntryWillLaterBeReactivated", null, "#SecondEntryWillLaterBeReactivated");
            window.location = "resources/navigate-back.html";
        } else if (state == "SecondEntryWillLaterBeReactivated")
            history.back();
    }, 0);
}

window.onpopstate = function statePopped()
{
    var state = event.state;
    alert("State popped - " + state + " (type " + typeof state + ")");
    continueTest(state);
}

window.onpageshow = function pageShown()
{
    if (sessionStorage.stage == 2) {
        var state = history.state;
        alert("Page shown - " + state + " (type " + typeof state + ")");
        continueTest(state);
    }
}

window.onhashchange = function hashChanged(event)
{
   alert("hashChanged - Last path component of location is " + lastPathComponent(event.newURL));
   if (hashOf(event.newURL) == "#FirstEntryWillLaterBeReactivated") {
        alert("Test complete");
        sessionStorage.clear();
        if (window.testRunner)
            testRunner.notifyDone();
    }
}

</script>
<body onload="runTest();" onunload="/* disable page cache */">
<pre>
This test:
-Builds up a list of state object entries with fragment URLs.
-Navigates through them to verify that the popstate and hashchanged events are fired.
-Navigates away to a new document, with the old document being destroyed.
-Navigates back to the state object entries and verifies the pageshow or popstate events are fired on the new documents.
</pre>
</body>
</html>