summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_bug1769189.js
blob: 823f76c67891d67a80673d737f1590cfe137668b (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_beforeUnload_and_replaceState() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: "data:text/html,<script>window.addEventListener('beforeunload', () => { window.history.replaceState(true, ''); });</script>",
    },
    async function (browser) {
      let initialState = await SpecialPowers.spawn(browser, [], () => {
        return content.history.state;
      });

      is(initialState, null, "history.state should be initially null.");

      let awaitPageShow = BrowserTestUtils.waitForContentEvent(
        browser,
        "pageshow"
      );
      BrowserCommands.reload();
      await awaitPageShow;

      let updatedState = await SpecialPowers.spawn(browser, [], () => {
        return content.history.state;
      });
      is(updatedState, true, "history.state should have been updated.");
    }
  );
});