DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (4a45ed98fb43)

VCS Links

Line Code
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
<!doctype html>
<html>
<head>
  <title>Test for cut/copy in password field</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
  <input type="password">
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  let input = document.getElementsByTagName("input")[0];
  let editor = SpecialPowers.wrap(input).editor;
  const kMask = editor.passwordMask;
  async function copyToClipboard(aExpectedValue) {
    try {
      await SimpleTest.promiseClipboardChange(
          aExpectedValue, () => { SpecialPowers.doCommand(window, "cmd_copy"); },
          undefined, undefined, aExpectedValue === null);
    } catch (e) {
      console.error(e);
    }
  }
  async function cutToClipboard(aExpectedValue) {
    try {
      await SimpleTest.promiseClipboardChange(
          aExpectedValue, () => { SpecialPowers.doCommand(window, "cmd_cut"); },
          undefined, undefined, aExpectedValue === null);
    } catch (e) {
      console.error(e);
    }
  }
  input.value = "abcdef";
  input.focus();

  input.setSelectionRange(0, 6);
  ok(true, "Trying to copy masked password...");
  await copyToClipboard(null);
  isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
        "Copying masked password shouldn't copy raw value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
        "Copying masked password shouldn't copy masked value into the clipboard");
  ok(true, "Trying to cut masked password...");
  await cutToClipboard(null);
  isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
        "Cutting masked password shouldn't copy raw value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
        "Cutting masked password shouldn't copy masked value into the clipboard");
  is(input.value, "abcdef",
     "Cutting masked password shouldn't modify the value");

  editor.unmask(2, 4);
  input.setSelectionRange(0, 6);
  ok(true, "Trying to copy partially masked password...");
  await copyToClipboard(null);
  isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
        "Copying partially masked password shouldn't copy raw value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`,
        "Copying partially masked password shouldn't copy partially masked value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
        "Copying partially masked password shouldn't copy masked value into the clipboard");
  ok(true, "Trying to cut partially masked password...");
  await cutToClipboard(null);
  isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
        "Cutting partially masked password shouldn't copy raw value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`,
        "Cutting partially masked password shouldn't copy partially masked value into the clipboard");
  isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
        "Cutting partially masked password shouldn't copy masked value into the clipboard");
  is(input.value, "abcdef",
     "Cutting partially masked password shouldn't modify the value");

  input.setSelectionRange(2, 4);
  ok(true, "Trying to copy unmasked password...");
  await copyToClipboard("cd");
  is(input.value, "abcdef",
     "Copying unmasked password shouldn't modify the value");

  input.value = "012345";
  editor.unmask(2, 4);
  input.setSelectionRange(2, 4);
  ok(true, "Trying to cut unmasked password...");
  await cutToClipboard("23");
  is(input.value, "0145",
     "Cutting unmasked password should modify the value");

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