summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_bug1206879.js
blob: 114a3c448b7c37b11d3dfb7a35fe0a63d728f467 (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
add_task(async function () {
  let url =
    getRootDirectory(gTestPath).replace(
      "chrome://mochitests/content/",
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      "http://example.com/"
    ) + "file_bug1206879.html";
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url, true);

  let numLocationChanges = await SpecialPowers.spawn(
    tab.linkedBrowser,
    [],
    async function () {
      let webprogress = content.docShell.QueryInterface(Ci.nsIWebProgress);
      let locationChangeCount = 0;
      let listener = {
        onLocationChange(aWebProgress, aRequest, aLocation) {
          info("onLocationChange: " + aLocation.spec);
          locationChangeCount++;
          this.resolve();
        },
        QueryInterface: ChromeUtils.generateQI([
          "nsIWebProgressListener",
          "nsISupportsWeakReference",
        ]),
      };
      let locationPromise = new Promise(resolve => {
        listener.resolve = resolve;
      });
      webprogress.addProgressListener(
        listener,
        Ci.nsIWebProgress.NOTIFY_LOCATION
      );

      content.frames[0].history.pushState(null, null, "foo");

      await locationPromise;
      webprogress.removeProgressListener(listener);

      return locationChangeCount;
    }
  );

  gBrowser.removeTab(tab);
  is(
    numLocationChanges,
    1,
    "pushState with a different URI should cause a LocationChange event."
  );
});