summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_paste_as_quote_in_text_control.html
blob: 443ee00eaae09401695a2f11704d6a5095aef4b6 (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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing "paste" event dispatching for cmd_pasteQuote command</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  info("Waiting for initializing clipboard...");
  await SimpleTest.promiseClipboardChange(
    "plain text",
    () => SpecialPowers.clipboardCopyString("plain text")
  );

  for (let selector of ["input", "textarea"]) {
    const textControl = document.querySelector(selector);
    textControl.focus();
    textControl.addEventListener(
      "paste",
      event => event.preventDefault(),
      {once: true}
    );
    SpecialPowers.doCommand(window, "cmd_pasteQuote");
    is(
      textControl.value,
      "",
      `<${selector}> should not have pasted text because "paste" event should've been canceled`
    );
    SpecialPowers.doCommand(window, "cmd_pasteQuote");
    is(
      textControl.value.replace(/\n/g, ""),
      "> plain text",
      `<${selector}> should have pasted text with a ">"`
    );
  }

  SimpleTest.finish();
});
</script>
</head>
<body>
<input><textarea></textarea>
</body>
</html>