summaryrefslogtreecommitdiffstats
path: root/toolkit/components/printing/tests/browser_print_bcg_id_overflow.js
blob: 3053afe236f5fa7c204b9fc7fc2698259d9c93c7 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_PATH = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);

// The actual uri we open doesn't really matter.
const OPENED_URI = PrintHelper.defaultTestPageUrlHTTPS;

// Test for bug 1669554:
//
// This opens a rel=noopener window in a content process, which causes us to
// create a browsing context with an id that likely overflows an int32_t, which
// caused us to fail to parse the initialBrowsingContextGroupId attribute
// (causing us to potentially clone in the wrong process, etc).
const OPEN_NOOPENER_WINDOW = `
  <a rel="noopener" target="_blank" href="${OPENED_URI}">Open the window</a>
`;

add_task(async function test_bc_id_overflow() {
  is(document.querySelector(".printPreviewBrowser"), null);

  await BrowserTestUtils.withNewTab(
    `data:text/html,` + encodeURIComponent(OPEN_NOOPENER_WINDOW),
    async function (browser) {
      let tabOpenedPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        OPENED_URI,
        /* waitForLoad = */ true
      );
      await BrowserTestUtils.synthesizeMouse("a", 0, 0, {}, browser);
      let tab = await tabOpenedPromise;
      let helper = new PrintHelper(tab.linkedBrowser);
      await helper.startPrint();
      helper.assertDialogOpen();

      let previewBrowser = document.querySelector(".printPreviewBrowser");
      is(typeof previewBrowser.browsingContext.group.id, "number", "Sanity");
      is(
        previewBrowser.browsingContext.group.id,
        tab.linkedBrowser.browsingContext.group.id,
        "Group ids should match: " + tab.linkedBrowser.browsingContext.group.id
      );
      is(
        previewBrowser.browsingContext.group,
        tab.linkedBrowser.browsingContext.group,
        "Groups should match"
      );
      await helper.closeDialog();
      await BrowserTestUtils.removeTab(tab);
    }
  );
});