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 (4f16fe418e32)

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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for operations in a password field</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<input type="password" value="abcdef ghijk" size="50">
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  await SpecialPowers.pushPrefEnv({
    set: [["layout.word_select.eat_space_to_next_word", false]],
  });
  // Double click on the anonymous text node
  let input = document.getElementsByTagName("input")[0];
  let editor = SpecialPowers.wrap(input).editor;
  let anonymousDiv = editor.rootElement;
  input.select();
  const kTextNodeRectInAnonymousDiv = {
     left: editor.selection.getRangeAt(0).getBoundingClientRect().left - anonymousDiv.getBoundingClientRect().left,
     top: editor.selection.getRangeAt(0).getBoundingClientRect().top - anonymousDiv.getBoundingClientRect().top,
     width: editor.selection.getRangeAt(0).getBoundingClientRect().width,
     height: editor.selection.getRangeAt(0).getBoundingClientRect().height,
  };
  kTextNodeRectInAnonymousDiv.right = kTextNodeRectInAnonymousDiv.left + kTextNodeRectInAnonymousDiv.width;
  kTextNodeRectInAnonymousDiv.bottom = kTextNodeRectInAnonymousDiv.top + kTextNodeRectInAnonymousDiv.height;
  input.setSelectionRange(0, 0);
  const kHalfHeightOfAnonymousDiv = anonymousDiv.getBoundingClientRect().height / 2;
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 5, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 5, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
  is(input.selectionStart, 0,
     "Double clicking on the anonymous text node in a password field should select all");
  is(input.selectionEnd, input.value.length,
     "Double clicking on the anonymous text node in a password field should select all");

  // Double click on the anonymous div element
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
  is(input.selectionStart, 0,
     "Double clicking on the anonymous div element in a password field should select all");
  is(input.selectionEnd, input.value.length,
     "Double clicking on the anonymous div element in a password field should select all");

  // Move caret per word
  let selectionController = editor.selectionController;
  input.focus();
  input.setSelectionRange(12, 12);
  selectionController.wordMove(false, false);
  is(input.selectionStart, 0,
     "Moving caret one word from the end should move caret to the start");
  input.setSelectionRange(0, 0);
  selectionController.wordMove(true, false);
  is(input.selectionStart, 12,
     "Moving caret one word from the start should move caret to the end");

  // Expand selection per word
  input.setSelectionRange(12, 12);
  selectionController.wordMove(false, true);
  is(input.selectionStart, 0,
     "Selecting one word from the end should move selection start to the start");
  input.setSelectionRange(0, 0);
  selectionController.wordMove(true, true);
  is(input.selectionEnd, 12,
     "Selecting one word from the start should move selection end to the end");

  // Delete one word
  input.setSelectionRange(12, 12);
  editor.deleteSelection(editor.ePreviousWord, editor.eStrip);
  is(input.value, "",
     "Deleting one word from the end should delete all characters");
  input.value = "abcdef ghijk";
  document.documentElement.scrollTop;  // Flush frames for setting the value.
  input.setSelectionRange(0, 0);
  editor.deleteSelection(editor.eNextWord, editor.eStrip);
  is(input.value, "",
     "Deleting one word from the start should delete all characters");
  input.value = "abcdef ghijk";
  document.documentElement.scrollTop;  // Flush frames for setting the value.

  // Test same things when the space is unmasked.

  // Double click on the anonymous text node
  editor.unmask(6, 7);
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.left + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
  is(input.selectionStart, 0,
     "Double clicking on the first word should select it");
  is(input.selectionEnd, 6,
     "Double clicking on the first word should select it");

  // Double click on the anonymous div element
  editor.unmask(6, 7);
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 1});
  synthesizeMouse(anonymousDiv, kTextNodeRectInAnonymousDiv.right + 3, kHalfHeightOfAnonymousDiv, {button: 0, clickCount: 2});
  is(input.selectionStart, 7,
     "Double clicking on the anonymous div element in a password field should select the last word");
  is(input.selectionEnd, input.value.length,
     "Double clicking on the anonymous div element in a password field should select the last word");

  // Move caret per word
  input.focus();
  input.setSelectionRange(12, 12);
  editor.unmask(6, 7);
  selectionController.wordMove(false, false);
  is(input.selectionStart, 6,
     "Moving caret one word from the end should move caret to end of the first word");
  input.setSelectionRange(0, 0);
  editor.unmask(6, 7);
  selectionController.wordMove(true, false);
  is(input.selectionStart, 7,
     "Moving caret one word from the start should move caret to start of the last word");

  // Expand selection per word
  input.setSelectionRange(12, 12);
  editor.unmask(6, 7);
  selectionController.wordMove(false, true);
  is(input.selectionStart, 6,
     "Selecting one word from the end should move selection start to end of the first word");
  input.setSelectionRange(0, 0);
  editor.unmask(6, 7);
  selectionController.wordMove(true, true);
  is(input.selectionEnd, 7,
     "Selecting one word from the start should move selection end to start of the last word");

  // Delete one word
  input.setSelectionRange(12, 12);
  editor.unmask(6, 7);
  editor.deleteSelection(editor.ePreviousWord, editor.eStrip);
  is(input.value, "abcdef",
     "Deleting one word from the end should delete the last word");
  input.value = "abcdef ghijk";
  document.documentElement.scrollTop;  // Flush frames for setting the value.
  input.setSelectionRange(0, 0);
  editor.unmask(6, 7);
  editor.deleteSelection(editor.eNextWord, editor.eStrip);
  is(input.value, "ghijk",
     "Deleting one word from the start should delete the first word");
  input.value = "abcdef ghijk";
  document.documentElement.scrollTop;  // Flush frames for setting the value.

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