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