1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/test_bug423523.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=423523 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 423523</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.14 +</head> 1.15 +<body onload="setTimeout(runtests, 200)"> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=423523">Mozilla Bug 423523</a> 1.17 +<p id="display"></p> 1.18 + 1.19 + <table> 1.20 + <tbody><tr> 1.21 + <td class="tdABB" id="tdTo"> 1.22 + <p id="par1">Some text...</p></td> 1.23 + <td> 1.24 + <div id="div1" style="border: 1px solid silver; width: 250px;" contenteditable="true">This is some editable text.</div> 1.25 + </td></tr> 1.26 + </tbody></table> 1.27 + 1.28 + 1.29 +<div id="content" style="display: none"> 1.30 +</div> 1.31 +<pre id="test"> 1.32 +<script class="testbody" type="text/javascript"> 1.33 + 1.34 +/** Test for Bug 423523 **/ 1.35 + SimpleTest.waitForExplicitFinish(); 1.36 + 1.37 + 1.38 + function divIsFocused() { 1.39 + // Check if div is directly focused. 1.40 + var divNode = document.getElementById("div1"); 1.41 + if (window.getSelection().focusNode == divNode) { 1.42 + return true; 1.43 + } 1.44 + // Check if one of the div's children has focus. 1.45 + var node = window.getSelection().focusNode; 1.46 + var childNodes = divNode.childNodes; 1.47 + for (var i=0; i<childNodes.length; i++) { 1.48 + if (childNodes[i] == node) { 1.49 + return true; 1.50 + } 1.51 + } 1.52 + // Not focused (at least not the first gen kids, and 1.53 + // that's ok for this test). 1.54 + return false; 1.55 + } 1.56 + 1.57 + function selectionOffsetIs(expectedOffset) { 1.58 + return window.getSelection().focusOffset == expectedOffset; 1.59 + } 1.60 + 1.61 + function sendMouseClick() { 1.62 + var rect=document.getElementById('div1').getBoundingClientRect(); 1.63 + var utils = SpecialPowers.getDOMWindowUtils(window); 1.64 + utils.sendMouseEvent('mousedown', rect.left+1, rect.top+1, 0, 1, 0); 1.65 + utils.sendMouseEvent('mouseup', rect.left+1, rect.top+1, 0, 1, 0); 1.66 + } 1.67 + 1.68 + function runtests() { 1.69 + sendMouseClick(); 1.70 + window.getSelection().collapse(document.getElementById("div1").firstChild, 0); 1.71 + ok(divIsFocused(), "Div should be focused [0]."); 1.72 + 1.73 + ok(divIsFocused(), "Div should be focused [1]."); 1.74 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.75 + 1.76 + synthesizeKey("VK_LEFT", { }); 1.77 + ok(divIsFocused(), "Div should be focused [2]."); 1.78 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.79 + 1.80 + synthesizeKey("VK_RIGHT", { }); 1.81 + ok(divIsFocused(), "Div should be focused [3]."); 1.82 + ok(selectionOffsetIs(1), "Caret should be at offset 1"); 1.83 + 1.84 + synthesizeKey("VK_LEFT", { }); 1.85 + ok(divIsFocused(), "Div should be focused [4]."); 1.86 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.87 + 1.88 + ok(divIsFocused(), "Div should be focused [5]."); 1.89 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.90 + sendMouseClick(); 1.91 + 1.92 + ok(divIsFocused(), "Div should be focused [6]."); 1.93 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.94 + synthesizeKey("VK_LEFT", { }); 1.95 + 1.96 + ok(divIsFocused(), "Div should be focused [7]."); 1.97 + ok(selectionOffsetIs(0), "Caret should be at offset 0"); 1.98 + SimpleTest.finish(); 1.99 + } 1.100 + 1.101 + 1.102 +</script> 1.103 +</pre> 1.104 +</body> 1.105 +</html> 1.106 +