Commit 2c546aa7 authored by Andreas Farre's avatar Andreas Farre
Browse files

Bug 1662410 - Part 3: Fix tests that use legacySHistory. r=peterv

parent d80d98ee
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -9,7 +9,28 @@ const gExpectedHistory = {
  entries: [],
};

function get_remote_history(browser) {
async function get_remote_history(browser) {
  if (SpecialPowers.getBoolPref("fission.sessionHistoryInParent")) {
    let sessionHistory = browser.browsingContext?.sessionHistory;
    if (!sessionHistory) {
      return null;
    }

    let result = {
      index: sessionHistory.index,
      entries: [],
    };

    for (let i = 0; i < sessionHistory.count; i++) {
      let entry = sessionHistory.getEntryAtIndex(i);
      result.entries.push({
        uri: entry.URI.spec,
        title: entry.title,
      });
    }
    return result;
  }

  return SpecialPowers.spawn(browser, [], () => {
    let webNav = content.docShell.QueryInterface(Ci.nsIWebNavigation);
    let sessionHistory = webNav.sessionHistory;
+34 −14
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ add_task(async function test() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: "http://example.com" },
    async function(browser) {
      if (!SpecialPowers.getBoolPref("fission.sessionHistoryInParent")) {
        await SpecialPowers.spawn(browser, [], async function() {
          let cw = content;
          let oldTitle = cw.document.title;
@@ -29,6 +30,25 @@ add_task(async function test() {
            "SHEntry title after pushstate."
          );
        });

        return;
      }

      let bc = browser.browsingContext;
      let oldTitle = browser.browsingContext.currentWindowGlobal.documentTitle;
      ok(oldTitle, "Content window should initially have a title.");
      SpecialPowers.spawn(browser, [], async function() {
        content.history.pushState("", "", "new_page");
      });

      let shistory = bc.sessionHistory;
      await SHListener.waitForHistory(shistory, SHListener.NewEntry);

      is(
        shistory.getEntryAtIndex(shistory.index).title,
        oldTitle,
        "SHEntry title after pushstate."
      );
    }
  );
});
+53 −0
Original line number Diff line number Diff line
@@ -198,3 +198,56 @@ function assertBackForwardState(canGoBack, canGoForward) {
    } disabled`
  );
}

class SHListener {
  static NewEntry = 0;
  static Reload = 1;
  static GotoIndex = 2;
  static Purge = 3;
  static ReplaceEntry = 4;
  static async waitForHistory(history, event) {
    return new Promise(resolve => {
      let listener = {
        OnHistoryNewEntry: () => {},
        OnHistoryReload: () => {
          return true;
        },
        OnHistoryGotoIndex: () => {},
        OnHistoryPurge: () => {},
        OnHistoryReplaceEntry: () => {},

        QueryInterface: ChromeUtils.generateQI([
          "nsISHistoryListener",
          "nsISupportsWeakReference",
        ]),
      };

      function finish() {
        history.removeSHistoryListener(listener);
        resolve();
      }
      switch (event) {
        case this.NewEntry:
          listener.OnHistoryNewEntry = finish;
          break;
        case this.Reload:
          listener.OnHistoryReload = () => {
            finish();
            return true;
          };
          break;
        case this.GotoIndex:
          listener.OnHistoryGotoIndex = finish;
          break;
        case this.Purge:
          listener.OnHistoryPurge = finish;
          break;
        case this.ReplaceEntry:
          listener.OnHistoryReplaceEntry = finish;
          break;
      }

      history.addSHistoryListener(listener);
    });
  }
}
+7 −2
Original line number Diff line number Diff line
@@ -35,8 +35,13 @@
      }

      // Work around bug 467960
      var history = gBrowser.webNavigation.sessionHistory;
      if (SpecialPowers.getBoolPref("fission.sessionHistoryInParent")) {
        let history = gBrowser.browsingContext.sessionHistory;
        history.purgeHistory(history.count);
      } else {
        let history = gBrowser.webNavigation.sessionHistory;
        history.legacySHistory.purgeHistory(history.count);
      }

      window.close();
      window.arguments[0].SimpleTest.finish();
+7 −2
Original line number Diff line number Diff line
@@ -37,8 +37,13 @@
    function finish() {
      gBrowser.removeEventListener("pageshow", eventListener, true);
      // Work around bug 467960
      if (SpecialPowers.getBoolPref("fission.sessionHistoryInParent")) {
        var history = gBrowser.browsingContext.sessionHistory;
        history.purgeHistory(history.count);
      } else {
        var history = gBrowser.webNavigation.sessionHistory;
        history.legacySHistory.purgeHistory(history.count);
      }

      window.close();
      window.arguments[0].SimpleTest.finish();
Loading