test_bug423523.html (3043B)
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 src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 <script 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" inputmode="none">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 SimpleTest.requestFlakyTimeout("untriaged"); 34 35 36 function divIsFocused() { 37 // Check if div is directly focused. 38 var divNode = document.getElementById("div1"); 39 if (window.getSelection().focusNode == divNode) { 40 return true; 41 } 42 // Check if one of the div's children has focus. 43 var node = window.getSelection().focusNode; 44 var childNodes = divNode.childNodes; 45 for (var i=0; i<childNodes.length; i++) { 46 if (childNodes[i] == node) { 47 return true; 48 } 49 } 50 // Not focused (at least not the first gen kids, and 51 // that's ok for this test). 52 return false; 53 } 54 55 function selectionOffsetIs(expectedOffset) { 56 return window.getSelection().focusOffset == expectedOffset; 57 } 58 59 function sendMouseClick() { 60 synthesizeMouse(document.getElementById('div1'), 1, 1, {}); 61 } 62 63 function runtests() { 64 sendMouseClick(); 65 window.getSelection().collapse(document.getElementById("div1").firstChild, 0); 66 ok(divIsFocused(), "Div should be focused [0]."); 67 68 ok(divIsFocused(), "Div should be focused [1]."); 69 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 70 71 synthesizeKey("KEY_ArrowLeft"); 72 ok(divIsFocused(), "Div should be focused [2]."); 73 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 74 75 synthesizeKey("KEY_ArrowRight"); 76 ok(divIsFocused(), "Div should be focused [3]."); 77 ok(selectionOffsetIs(1), "Caret should be at offset 1"); 78 79 synthesizeKey("KEY_ArrowLeft"); 80 ok(divIsFocused(), "Div should be focused [4]."); 81 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 82 83 ok(divIsFocused(), "Div should be focused [5]."); 84 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 85 sendMouseClick(); 86 87 ok(divIsFocused(), "Div should be focused [6]."); 88 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 89 synthesizeKey("KEY_ArrowLeft"); 90 91 ok(divIsFocused(), "Div should be focused [7]."); 92 ok(selectionOffsetIs(0), "Caret should be at offset 0"); 93 SimpleTest.finish(); 94 } 95 96 97 </script> 98 </pre> 99 </body> 100 </html>