summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_bug623893.js
blob: 27751e74ad804475ef06ada0e087451a3a2f05dd (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 test() {
  await BrowserTestUtils.withNewTab(
    "data:text/plain;charset=utf-8,1",
    async function (browser) {
      BrowserTestUtils.loadURIString(
        browser,
        "data:text/plain;charset=utf-8,2"
      );
      await BrowserTestUtils.browserLoaded(browser);

      BrowserTestUtils.loadURIString(
        browser,
        "data:text/plain;charset=utf-8,3"
      );
      await BrowserTestUtils.browserLoaded(browser);

      await duplicate(0, "maintained the original index");
      BrowserTestUtils.removeTab(gBrowser.selectedTab);

      await duplicate(-1, "went back");
      await duplicate(1, "went forward");
      BrowserTestUtils.removeTab(gBrowser.selectedTab);
      BrowserTestUtils.removeTab(gBrowser.selectedTab);
    }
  );
});

async function promiseGetIndex(browser) {
  if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
    return SpecialPowers.spawn(browser, [], function () {
      let shistory =
        docShell.browsingContext.childSessionHistory.legacySHistory;
      return shistory.index;
    });
  }

  let shistory = browser.browsingContext.sessionHistory;
  return shistory.index;
}

let duplicate = async function (delta, msg, cb) {
  var startIndex = await promiseGetIndex(gBrowser.selectedBrowser);

  duplicateTabIn(gBrowser.selectedTab, "tab", delta);

  await BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored");

  let endIndex = await promiseGetIndex(gBrowser.selectedBrowser);
  is(endIndex, startIndex + delta, msg);
};