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 (6663d3dc883b)

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
<!DOCTYPE>
<html>
<head>
<title>Test for bug1318312</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style type="text/css">
</style>
</head>
<body>
<div id="outerEditor" contenteditable><p>content of outer editor</p>
<div id="staticInEditor" contenteditable="false"><p>static content of outer editor</p>
<div id="innerEditor" contenteditable><p>content of inner editor</p></div></div></div>
<pre id="test">
<script class="testbody" type="text/javascript">

var outerEditor = document.getElementById("outerEditor");
var innerEditor = document.getElementById("innerEditor");

function runTests() {
  outerEditor.focus();
  is(document.activeElement, outerEditor,
     "outerEditor should have focus");

  // Move cursor into the innerEditor with ArrowDown key.  Then, focus shouldn't
  // be moved to innerEditor from outerEditor.
  // Note that Chrome moves focus in this case.  However, we should do that
  // at least for now because user can move focus with ArrowUp key even from
  // innerEditor to outerEditor but we don't allow such navigation.
  // FYI: Edge behaves same as us.
  synthesizeKey("KEY_ArrowDown");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by moving caret");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");
  is(document.getSelection().focusOffset, 0,
     "focus offset of selection should be 0");

  sendString("a");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by typing a character");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");
  is(document.getSelection().focusOffset, 1,
     "focus offset of selection should be 1");

  synthesizeKey("KEY_Enter");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by typing Enter");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").childNodes.item(1).firstChild,
     "focus node of selection should be the text node in the second paragraph in the innerEditor");
  is(document.getSelection().focusOffset, 0,
     "focus offset of selection should be 0");

  synthesizeKey("KEY_Backspace");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by typing Backspace (removing the line breaker)");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");
  is(document.getSelection().focusOffset, 1,
     "focus offset of selection should be 1");

  synthesizeKey("KEY_ArrowLeft", {shiftKey: true});
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by typing Shift+ArrowLeft (selecting 'a')");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");
  is(document.getSelection().focusOffset, 0,
     "focus offset of selection should be 0");
  is(document.getSelection().anchorNode, document.getElementById("innerEditor").firstChild.firstChild,
     "anchor node of selection should be the text node in the innerEditor");
  is(document.getSelection().anchorOffset, 1,
     "anchor offset of selection should be 1");

  synthesizeKey("KEY_Delete");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by typing Delete (removing the 'a')");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");
  is(document.getSelection().focusOffset, 0,
     "focus offset of selection should be 0");

  synthesizeKey("KEY_ArrowUp");
  is(document.activeElement, outerEditor,
     "outerEditor should still have focus because focus shouldn't be moved by moving caret from innerEditor to outerEditor");
  is(document.getSelection().focusNode, document.getElementById("outerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the outerEditor");
  is(document.getSelection().focusOffset, 0,
     "focus offset of selection should be 0");

  // However, clicking in innerEditor should move focus.
  synthesizeMouseAtCenter(innerEditor, {});
  is(document.activeElement, innerEditor,
     "innerEditor should get focus because focus should be moved to innerEditor even from outerEditor by click");
  is(document.getSelection().focusNode, document.getElementById("innerEditor").firstChild.firstChild,
     "focus node of selection should be the text node in the innerEditor");

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests);

</script>
</pre>
</body>
</html>