File: test_bug423523.html

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (101 lines) | stat: -rw-r--r-- 3,044 bytes parent folder | download | duplicates (4)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=423523
-->
<head>
  <title>Test for Bug 423523</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script src="/tests/SimpleTest/EventUtils.js"></script>
</head>
<body onload="setTimeout(runtests, 200)">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=423523">Mozilla Bug 423523</a>
<p id="display"></p>

  <table>
    <tbody><tr>
  <td class="tdABB" id="tdTo">
  <p id="par1">Some text...</p></td>
  <td>
  <div id="div1" style="border: 1px solid silver; width: 250px;" contenteditable="true" inputmode="none">This is some editable text.</div>
  </td></tr>
  </tbody></table>


<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 423523 **/
  SimpleTest.waitForExplicitFinish();
  SimpleTest.requestFlakyTimeout("untriaged");

 
  function divIsFocused() {
    // Check if div is directly focused.
    var divNode = document.getElementById("div1");
    if (window.getSelection().focusNode == divNode) {
      return true;
    }
    // Check if one of the div's children has focus.
    var node = window.getSelection().focusNode;
    var childNodes = divNode.childNodes;
    for (var i=0; i<childNodes.length; i++) {
      if (childNodes[i] == node) {
        return true;
      }
    }
    // Not focused (at least not the first gen kids, and
    // that's ok for this test).
    return false;
  }
  
  function selectionOffsetIs(expectedOffset) {
    return window.getSelection().focusOffset == expectedOffset;
  }

  function sendMouseClick() {
    synthesizeMouse(document.getElementById('div1'), 1, 1, {});
  }
 
  function runtests() {
    sendMouseClick();
    window.getSelection().collapse(document.getElementById("div1").firstChild, 0);
    ok(divIsFocused(), "Div should be focused [0].");

    ok(divIsFocused(), "Div should be focused [1].");
    ok(selectionOffsetIs(0), "Caret should be at offset 0");
    
    synthesizeKey("KEY_ArrowLeft");
    ok(divIsFocused(), "Div should be focused [2].");    
    ok(selectionOffsetIs(0), "Caret should be at offset 0");
    
    synthesizeKey("KEY_ArrowRight");
    ok(divIsFocused(), "Div should be focused [3].");
    ok(selectionOffsetIs(1), "Caret should be at offset 1");
    
    synthesizeKey("KEY_ArrowLeft");
    ok(divIsFocused(), "Div should be focused [4].");
    ok(selectionOffsetIs(0), "Caret should be at offset 0");

    ok(divIsFocused(), "Div should be focused [5].");    
    ok(selectionOffsetIs(0), "Caret should be at offset 0");
    sendMouseClick();

    ok(divIsFocused(), "Div should be focused [6].");    
    ok(selectionOffsetIs(0), "Caret should be at offset 0");    
    synthesizeKey("KEY_ArrowLeft");

    ok(divIsFocused(), "Div should be focused [7].");
    ok(selectionOffsetIs(0), "Caret should be at offset 0");
    SimpleTest.finish();
  }
  

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