summaryrefslogtreecommitdiffstats
path: root/embedding/components/windowwatcher/test/browser_new_remote_window_flags.js
blob: e4f3d1ddf69e075cc027889a158314cc8b57deee (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
/**
 * Tests that when a remote browser opens a new window that the
 * newly opened window is also remote.
 */

const ANCHOR_PAGE = `data:text/html,<a href="about:blank" target="_blank">Click me!</a>`;
const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank");</script>`;

// This magic value of 2 means that by default, when content tries
// to open a new window, it'll actually open in a new window instead
// of a new tab.
add_task(function* setup() {
  yield SpecialPowers.pushPrefEnv({"set": [
    ["browser.link.open_newwindow", 2],
  ]});
});

function assertFlags(win) {
  let webNav = win.QueryInterface(Ci.nsIInterfaceRequestor)
                  .getInterface(Ci.nsIWebNavigation);
  let loadContext = webNav.QueryInterface(Ci.nsILoadContext);
  let chromeFlags = webNav.QueryInterface(Ci.nsIDocShellTreeItem)
                          .treeOwner
                          .QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIXULWindow)
                          .chromeFlags;
  Assert.ok(loadContext.useRemoteTabs,
            "Should be using remote tabs on the load context");
  Assert.ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_REMOTE_WINDOW,
            "Should have the remoteness chrome flag on the window");
}

/**
 * Content can open a window using a target="_blank" link
 */
add_task(function* test_new_remote_window_flags_target_blank() {
  yield BrowserTestUtils.withNewTab({
    gBrowser,
    url: ANCHOR_PAGE,
  }, function*(browser) {
    let newWinPromise = BrowserTestUtils.waitForNewWindow();
    yield BrowserTestUtils.synthesizeMouseAtCenter("a", {}, browser);
    let win = yield newWinPromise;
    assertFlags(win);
    yield BrowserTestUtils.closeWindow(win);
  });
});

/**
 * Content can open a window using window.open
 */
add_task(function* test_new_remote_window_flags_window_open() {
  let newWinPromise = BrowserTestUtils.waitForNewWindow();

  yield BrowserTestUtils.withNewTab({
    gBrowser,
    url: SCRIPT_PAGE,
  }, function*(browser) {
    let win = yield newWinPromise;
    assertFlags(win);
    yield BrowserTestUtils.closeWindow(win);
  });
});

/**
 * Privileged content scripts can also open new windows
 * using content.open.
 */
add_task(function* test_new_remote_window_flags_content_open() {
  let newWinPromise = BrowserTestUtils.waitForNewWindow();
  yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
    content.open("about:blank", "_blank");
  });

  let win = yield newWinPromise;
  assertFlags(win);
  yield BrowserTestUtils.closeWindow(win);
});