|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=423523 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 423523</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
11 </head> |
|
12 <body onload="setTimeout(runtests, 200)"> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=423523">Mozilla Bug 423523</a> |
|
14 <p id="display"></p> |
|
15 |
|
16 <table> |
|
17 <tbody><tr> |
|
18 <td class="tdABB" id="tdTo"> |
|
19 <p id="par1">Some text...</p></td> |
|
20 <td> |
|
21 <div id="div1" style="border: 1px solid silver; width: 250px;" contenteditable="true">This is some editable text.</div> |
|
22 </td></tr> |
|
23 </tbody></table> |
|
24 |
|
25 |
|
26 <div id="content" style="display: none"> |
|
27 </div> |
|
28 <pre id="test"> |
|
29 <script class="testbody" type="text/javascript"> |
|
30 |
|
31 /** Test for Bug 423523 **/ |
|
32 SimpleTest.waitForExplicitFinish(); |
|
33 |
|
34 |
|
35 function divIsFocused() { |
|
36 // Check if div is directly focused. |
|
37 var divNode = document.getElementById("div1"); |
|
38 if (window.getSelection().focusNode == divNode) { |
|
39 return true; |
|
40 } |
|
41 // Check if one of the div's children has focus. |
|
42 var node = window.getSelection().focusNode; |
|
43 var childNodes = divNode.childNodes; |
|
44 for (var i=0; i<childNodes.length; i++) { |
|
45 if (childNodes[i] == node) { |
|
46 return true; |
|
47 } |
|
48 } |
|
49 // Not focused (at least not the first gen kids, and |
|
50 // that's ok for this test). |
|
51 return false; |
|
52 } |
|
53 |
|
54 function selectionOffsetIs(expectedOffset) { |
|
55 return window.getSelection().focusOffset == expectedOffset; |
|
56 } |
|
57 |
|
58 function sendMouseClick() { |
|
59 var rect=document.getElementById('div1').getBoundingClientRect(); |
|
60 var utils = SpecialPowers.getDOMWindowUtils(window); |
|
61 utils.sendMouseEvent('mousedown', rect.left+1, rect.top+1, 0, 1, 0); |
|
62 utils.sendMouseEvent('mouseup', rect.left+1, rect.top+1, 0, 1, 0); |
|
63 } |
|
64 |
|
65 function runtests() { |
|
66 sendMouseClick(); |
|
67 window.getSelection().collapse(document.getElementById("div1").firstChild, 0); |
|
68 ok(divIsFocused(), "Div should be focused [0]."); |
|
69 |
|
70 ok(divIsFocused(), "Div should be focused [1]."); |
|
71 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
72 |
|
73 synthesizeKey("VK_LEFT", { }); |
|
74 ok(divIsFocused(), "Div should be focused [2]."); |
|
75 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
76 |
|
77 synthesizeKey("VK_RIGHT", { }); |
|
78 ok(divIsFocused(), "Div should be focused [3]."); |
|
79 ok(selectionOffsetIs(1), "Caret should be at offset 1"); |
|
80 |
|
81 synthesizeKey("VK_LEFT", { }); |
|
82 ok(divIsFocused(), "Div should be focused [4]."); |
|
83 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
84 |
|
85 ok(divIsFocused(), "Div should be focused [5]."); |
|
86 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
87 sendMouseClick(); |
|
88 |
|
89 ok(divIsFocused(), "Div should be focused [6]."); |
|
90 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
91 synthesizeKey("VK_LEFT", { }); |
|
92 |
|
93 ok(divIsFocused(), "Div should be focused [7]."); |
|
94 ok(selectionOffsetIs(0), "Caret should be at offset 0"); |
|
95 SimpleTest.finish(); |
|
96 } |
|
97 |
|
98 |
|
99 </script> |
|
100 </pre> |
|
101 </body> |
|
102 </html> |
|
103 |