summaryrefslogtreecommitdiffstats
path: root/browser/components/contextualidentity/test/browser/browser_middleClick.js
blob: 9b9fbcb737ca51ea152e8c52d3ce976c149cf974 (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
"use strict";

const BASE_ORIGIN = "http://example.com";
const URI =
  BASE_ORIGIN +
  "/browser/browser/components/contextualidentity/test/browser/empty_file.html";

add_task(async function () {
  info("Opening a new container tab...");

  let tab = BrowserTestUtils.addTab(gBrowser, URI, { userContextId: 1 });
  gBrowser.selectedTab = tab;

  let browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  info("Create a HTMLAnchorElement...");
  await SpecialPowers.spawn(browser, [URI], function (uri) {
    let anchor = content.document.createElement("a");
    anchor.setAttribute("id", "clickMe");
    anchor.setAttribute("href", uri);
    anchor.appendChild(content.document.createTextNode("click me!"));
    content.document.body.appendChild(anchor);
  });

  info("Synthesize a mouse click and wait for a new tab...");
  let newTab = await new Promise((resolve, reject) => {
    gBrowser.tabContainer.addEventListener(
      "TabOpen",
      function (openEvent) {
        resolve(openEvent.target);
      },
      { once: true }
    );

    BrowserTestUtils.synthesizeMouseAtCenter(
      "#clickMe",
      { button: 1 },
      browser
    );
  });

  is(newTab.getAttribute("usercontextid"), "1", "Correct UserContextId?");

  // newTab shouldn't be closed in the same event tick as TabOpen.
  await TestUtils.waitForTick();

  BrowserTestUtils.removeTab(tab);
  BrowserTestUtils.removeTab(newTab);
});