summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/loader/document-with-fragment-url-3.html
blob: f3bc3424dcf47e3b822799032d4c075aeedd1f21 (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
<script>

if (!sessionStorage.in_document_with_fragment_url_3)
    sessionStorage.in_document_with_fragment_url_3 = true;
else
    delete sessionStorage.in_document_with_fragment_url_3;

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function documentURLHash()
{
    var index = document.URL.lastIndexOf("#");
    if (index == -1)
        return "";
    return document.URL.substring(index);
}

function hashChanged()
{
    alert("Hash changed to " + documentURLHash() + " which is interesting because we shouldn't get a hashchange event in this test.");
}

function loaded()
{
    if (sessionStorage.in_document_with_fragment_url_3) {
        alert("First load complete.  URL's current hash is " + documentURLHash());
        history.pushState(null, null, "#foo");
        alert("After pushState, the URL's current hash is " + documentURLHash());
        var rect = document.getElementById("clickanchor").getBoundingClientRect();
        eventSender.mouseMoveTo(rect.left + rect.width / 2, rect.top + rect.height / 2);
        eventSender.mouseDown();
        eventSender.mouseUp();
    } else {
        alert("Second load complete.  URL's current hash is " + documentURLHash());
        if (window.testRunner)
            testRunner.notifyDone();
    }
}

</script>
<body onhashchange="hashChanged();" onload="loaded();">
This page uses history.pushState() to add #foo to its URL.  Then click the second link, which has an empty href and should take you back to the original URL without the #foo.<br>
<a id="clickanchor" href="">Click here to return to the original page with the original url</a>
</body>