summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/referrer/browser_referrer_open_link_in_container_tab.js
blob: 3fe5df53c480d1384760406fb8a959c6f2f32b55 (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
// Tests referrer on context menu navigation - open link in new container tab.
// Selects "open link in new container tab" from the context menu.

function getReferrerTest(aTestNumber) {
  let testCase = _referrerTests[aTestNumber];
  if (testCase) {
    // We want all the referrer tests to fail!
    testCase.result = "";
  }

  return testCase;
}

function startNewTabTestCase(aTestNumber) {
  info(
    "browser_referrer_open_link_in_container_tab: " +
      getReferrerTestDescription(aTestNumber)
  );
  contextMenuOpened(gTestWindow, "testlink").then(function (aContextMenu) {
    someTabLoaded(gTestWindow).then(function (aNewTab) {
      gTestWindow.gBrowser.selectedTab = aNewTab;

      checkReferrerAndStartNextTest(
        aTestNumber,
        null,
        aNewTab,
        startNewTabTestCase
      );
    });

    let menu = gTestWindow.document.getElementById(
      "context-openlinkinusercontext-menu"
    );

    let menupopup = menu.menupopup;
    menu.addEventListener(
      "popupshown",
      function () {
        is(menupopup.nodeType, Node.ELEMENT_NODE, "We have a menupopup.");
        ok(menupopup.firstElementChild, "We have a first container entry.");

        let firstContext = menupopup.firstElementChild;
        is(
          firstContext.nodeType,
          Node.ELEMENT_NODE,
          "We have a first container entry."
        );
        ok(
          firstContext.hasAttribute("data-usercontextid"),
          "We have a usercontextid value."
        );

        aContextMenu.addEventListener(
          "popuphidden",
          function () {
            firstContext.doCommand();
          },
          { once: true }
        );

        aContextMenu.hidePopup();
      },
      { once: true }
    );

    menu.openMenu(true);
  });
}

function test() {
  waitForExplicitFinish();

  SpecialPowers.pushPrefEnv(
    { set: [["privacy.userContext.enabled", true]] },
    function () {
      requestLongerTimeout(10); // slowwww shutdown on e10s
      startReferrerTest(startNewTabTestCase);
    }
  );
}