File: test_edit_contextmenu.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (103 lines) | stat: -rw-r--r-- 4,608 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1513343
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1513343</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
  <script type="application/javascript">
    SimpleTest.waitForExplicitFinish();

    async function runTest() {
      let win = window.browsingContext.topChromeWindow.open("file_edit_contextmenu.xhtml", "_blank", "chrome,width=600,height=600");
      await new Promise(r => win.addEventListener("load", r, { once: true }));
      await SimpleTest.promiseFocus(win);

      const elements = [
        win.document.querySelector("textarea"),
        win.document.querySelector("input"),
        win.document.querySelector("shadow-input").shadowRoot.querySelector("input"),
        // Intentionally twice to test revealing and un-revealing.
        win.document.querySelector("input[type=password]"),
        win.document.querySelector("input[type=password]"),
      ];
      for (const element of elements) {
        await testElement(element, win);
      }
      win.close();
      SimpleTest.finish();
    }

    async function testElement(element, win) {
      ok(element, "element exists");

      info("Synthesizing a key so 'Undo' will be enabled");
      element.focus();
      synthesizeKey("x", {}, win);
      is(element.value, "x", "initial value");

      element.select();
      synthesizeKey("c", { accelKey: true }, win); // copy to clipboard
      synthesizeKey("KEY_ArrowRight", {}, win); // drop selection to disable cut and copy context menu items

      win.document.addEventListener("contextmenu", (e) => {
        info("Calling prevent default on the first contextmenu event");
        e.preventDefault();
      }, { once: true });
      synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
      ok(!win.document.getElementById("textbox-contextmenu"), "contextmenu with preventDefault() doesn't run");

      let popupshown = new Promise(r => win.addEventListener("popupshown", r, { once: true }));
      synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
      let contextmenu = win.document.getElementById("textbox-contextmenu");
      ok(contextmenu, "context menu exists after right click");
      await popupshown;

      // Check that we only got the one context menu, and not two.
      let outerContextmenu = win.document.getElementById("outer-context-menu");
      ok(outerContextmenu.state == "closed", "the outer context menu state is is not closed, it's: " + outerContextmenu.state);

      ok(!contextmenu.querySelector("[command=cmd_undo]").hasAttribute("disabled"), "undo enabled");
      ok(contextmenu.querySelector("[command=cmd_cut]").hasAttribute("disabled"), "cut disabled");
      ok(contextmenu.querySelector("[command=cmd_copy]").hasAttribute("disabled"), "copy disabled");
      ok(!contextmenu.querySelector("[command=cmd_paste]").hasAttribute("disabled"), "paste enabled");
      ok(contextmenu.querySelector("[command=cmd_delete]").hasAttribute("disabled"), "delete disabled");
      ok(!contextmenu.querySelector("[command=cmd_selectAll]").hasAttribute("disabled"), "select all enabled");

      let revealPassword = contextmenu.querySelector("#textbox-contextmenu-reveal-password");
      let isPassword = element.type == "password";
      is(revealPassword.hidden, !isPassword, "reveal password");

      let popuphidden = new Promise(r => win.addEventListener("popuphidden", r, { once: true }));
      if (isPassword) {
        let isRevealed = element.revealPassword;
        is(revealPassword.getAttribute("checked"), isRevealed ? "true" : null, "reveal password checked");
        contextmenu.activateItem(revealPassword);
        await popuphidden;
        is(element.revealPassword, !isRevealed, "Password was revealed / unrevealed");
        element.value = "";
      } else {
        contextmenu.activateItem(contextmenu.querySelector("[command=cmd_undo]"));
        await popuphidden;
        is(element.value, "", "undo worked");
      }

      contextmenu.remove();
    }
  </script>
</head>
<body onload="runTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1513343">Mozilla Bug 1513343</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>