Commit 3c841711 authored by Masatoshi Kimura's avatar Masatoshi Kimura
Browse files

Bug 1745730 - Test to make sure that same page naviations do not create a...

Bug 1745730 - Test to make sure that same page naviations do not create a duplicate session history entry. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D134012
parent b11dca3e
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
<head>
<script>
let bc = new BroadcastChannel("test_same_url");
let listener = e => {
    switch (e.data) {
    case "linkClick":
        var link = document.getElementById("link1");
        link.click();
        break;
    case "closeWin":
        self.close();
        break;
    }
};
bc.addEventListener("message", listener);
</script>
</head>
<body onpageshow="bc.postMessage({bodyOnLoad: history.length})">
<a id="link1" href="file_same_url.html">Link 1</a>
<a name="1">link 1</a>
</body>
</html>
+3 −0
Original line number Diff line number Diff line
@@ -155,6 +155,9 @@ support-files = file_reload_nonbfcached_srcdoc.sjs
skip-if =
  (debug && e10s)  # bug 1263213
[test_performance_navigation.html]
[test_same_url.html]
fail-if = fission  # bug 1745730
support-files = file_same_url.html
[test_session_history_on_redirect.html]
[test_sessionhistory.html]
skip-if = verify && (os == 'mac') && debug # Hit MOZ_CRASH(Shutdown too long, probably frozen, causing a crash.) bug 1677545
+56 −0
Original line number Diff line number Diff line

<!DOCTYPE HTML>
<html>
<head>
    <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    <script type="application/javascript" src="/tests/SimpleTest/SpecialPowers.js"></script>
    <script type="application/javascript">
    // Since BFCache in parent requires no opener, use BroadcastChannel
    // to communicate with file_same_url.html.
    let bc = new BroadcastChannel("test_same_url");
    async function test() {
        var promise;
        let historyLength;

        promise = waitForLoad();
        window.open("file_same_url.html", "_blank", "noopener=yes");
        historyLength = await promise;
        is(historyLength, 1, "before same page navigation");

        promise = waitForLoad();
        bc.postMessage("linkClick");
        historyLength = await promise;
        is(historyLength, 1, "after same page navigation");
        bc.postMessage("closeWin");

        SimpleTest.finish();
    }

    async function waitForLoad() {
        return new Promise(resolve => {
            let listener = e => {
                if (e.data.bodyOnLoad) {
                    bc.removeEventListener("message", listener);
                    setTimeout(() => resolve(e.data.bodyOnLoad), 0);
                }
            };
            bc.addEventListener("message", listener);
        });
    }
    </script>
</head>

<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1745730">Bug 1745730</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<body onload="test()">
</body>
</html>