summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_tab_replace_while_loading.js
blob: e1b88334ffbc2250224c515cfda178579b821084 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* Test for bug 1578379. */

add_task(async function test_window_open_about_blank() {
  const URL =
    "http://mochi.test:8888/browser/docshell/test/browser/file_open_about_blank.html";
  let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
  let promiseTabOpened = BrowserTestUtils.waitForNewTab(
    gBrowser,
    "about:blank"
  );

  info("Opening about:blank using a click");
  await SpecialPowers.spawn(firstTab.linkedBrowser, [""], async function() {
    content.document.querySelector("#open").click();
  });

  info("Waiting for the second tab to be opened");
  let secondTab = await promiseTabOpened;

  info("Detaching tab");
  let windowOpenedPromise = BrowserTestUtils.waitForNewWindow();
  gBrowser.replaceTabWithWindow(secondTab);
  let win = await windowOpenedPromise;

  info("Asserting document is visible");
  let tab = win.gBrowser.selectedTab;
  await SpecialPowers.spawn(tab.linkedBrowser, [""], async function() {
    is(
      content.document.visibilityState,
      "visible",
      "Document should be visible"
    );
  });

  await BrowserTestUtils.closeWindow(win);
  await BrowserTestUtils.removeTab(firstTab);
});

add_task(async function test_detach_loading_page() {
  const URL =
    "http://mochi.test:8888/browser/docshell/test/browser/file_slow_load.sjs";
  // Open a dummy tab so that detaching the second tab works.
  let dummyTab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:blank"
  );
  let slowLoadingTab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    URL,
    /* waitForLoad = */ false
  );

  info("Wait for content document to be created");
  await BrowserTestUtils.waitForCondition(async function() {
    return SpecialPowers.spawn(
      slowLoadingTab.linkedBrowser,
      [URL],
      async function(url) {
        return content.document.documentURI == url;
      }
    );
  });

  info("Detaching tab");
  let windowOpenedPromise = BrowserTestUtils.waitForNewWindow();
  gBrowser.replaceTabWithWindow(slowLoadingTab);
  let win = await windowOpenedPromise;

  info("Asserting document is visible");
  let tab = win.gBrowser.selectedTab;
  await SpecialPowers.spawn(tab.linkedBrowser, [""], async function() {
    is(content.document.readyState, "loading");
    is(content.document.visibilityState, "visible");
  });

  await BrowserTestUtils.closeWindow(win);
  await BrowserTestUtils.removeTab(dummyTab);
});