summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/contextMenu/browser_contextmenu_inspect.js
blob: 94241e9e1f70f9d19ba20bd442ba26a98c95c861 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Check that we show the inspect item(s) as appropriate.
 */
add_task(async function test_contextmenu_inspect() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["devtools.selfxss.count", 0],
      ["devtools.everOpened", false],
    ],
  });
  let contextMenu = document.getElementById("contentAreaContextMenu");
  await BrowserTestUtils.withNewTab("about:blank", async browser => {
    for (let [pref, value, expectation] of [
      ["devtools.selfxss.count", 10, true],
      ["devtools.selfxss.count", 0, false],
      ["devtools.everOpened", false, false],
      ["devtools.everOpened", true, true],
    ]) {
      await SpecialPowers.pushPrefEnv({
        set: [["devtools.selfxss.count", value]],
      });
      is(contextMenu.state, "closed", "checking if popup is closed");
      let promisePopupShown = BrowserTestUtils.waitForEvent(
        contextMenu,
        "popupshown"
      );
      let promisePopupHidden = BrowserTestUtils.waitForEvent(
        contextMenu,
        "popuphidden"
      );
      await BrowserTestUtils.synthesizeMouse(
        "body",
        2,
        2,
        { type: "contextmenu", button: 2 },
        browser
      );
      await promisePopupShown;
      let inspectItem = document.getElementById("context-inspect");
      ok(
        !inspectItem.hidden,
        `Inspect should be shown (pref ${pref} is ${value}).`
      );
      let inspectA11y = document.getElementById("context-inspect-a11y");
      is(
        inspectA11y.hidden,
        !expectation,
        `A11y should be ${
          expectation ? "visible" : "hidden"
        } (pref ${pref} is ${value}).`
      );
      contextMenu.hidePopup();
      await promisePopupHidden;
    }
  });
});