summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_swapDocShells.js
blob: 047a36c510df305f0fb33563aed81228ea28d009 (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
"use strict";

add_task(async function () {
  let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(
    gBrowser,
    "about:mozilla"
  ));
  await promiseBrowserLoaded(gBrowser.selectedBrowser);

  let win = gBrowser.replaceTabWithWindow(tab);
  await promiseDelayedStartupFinished(win);
  await promiseBrowserHasURL(win.gBrowser.browsers[0], "about:mozilla");

  win.duplicateTabIn(win.gBrowser.selectedTab, "tab");
  await promiseTabRestored(win.gBrowser.tabs[1]);

  let browser = win.gBrowser.browsers[1];
  is(browser.currentURI.spec, "about:mozilla", "tab was duplicated");

  await BrowserTestUtils.closeWindow(win);
});

function promiseDelayedStartupFinished(win) {
  return new Promise(resolve => {
    whenDelayedStartupFinished(win, resolve);
  });
}

function promiseBrowserHasURL(browser, url) {
  let promise = Promise.resolve();

  if (
    browser.contentDocument.readyState === "complete" &&
    browser.currentURI.spec === url
  ) {
    return promise;
  }

  return promise.then(() => promiseBrowserHasURL(browser, url));
}