Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / select-out-of-editable.html
blobae42299e97c0f544a9e06109250028a5210a9ae7
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <p id="description">This test ensures that when editable text is selected by a drag that ends outside of the editable region, selection is extended to the either end of the text. See the <a href="https://bugs.webkit.org/show_bug.cgi?id=52986">bug 52986</a> for more details.</p>
5 <div id="test" contenteditable style="width: 200px; margin: 20px; border: solid 1px; font-size: x-large;">hello world</div>
6 <script>
8 function selectTextByDrag(div, endX, endY) {
9 window.getSelection().removeAllRanges();
11 eventSender.mouseMoveTo(div.offsetLeft + (div.offsetWidth / 2) , div.offsetTop + (div.offsetHeight / 2));
12 eventSender.mouseDown();
14 eventSender.leapForward(200);
16 // Without this, drag doesn't start selection.
17 eventSender.mouseMoveTo(div.offsetLeft + (div.offsetWidth / 3) , div.offsetTop + (div.offsetHeight / 3));
18 eventSender.mouseDown();
20 eventSender.leapForward(200);
22 eventSender.mouseMoveTo(endX, endY);
23 eventSender.mouseUp();
26 var log = '';
28 function assertEqual(actual, expected) {
29 if (actual == expected)
30 log += 'PASS';
31 else
32 log += 'FAIL - expected ' + expected + ' but got ' + actual;
33 log += '\n';
36 if (!window.testRunner || !window.eventSender)
37 document.writeln("This test requires eventSender since the bug does not reproduce reliably when tested manually.");
38 else {
39 testRunner.dumpAsText();
40 var description = document.getElementById('description');
41 description.style.display = 'none';
43 var div = document.getElementById('test');
45 log += 'Dragging to the left: ';
46 selectTextByDrag(div, div.offsetLeft - 10, div.offsetTop - 10);
47 assertEqual(window.getSelection().getRangeAt(0).startOffset, 0);
49 log += 'Dragging to the left: ';
50 selectTextByDrag(div, div.offsetLeft + 300, div.offsetTop + 100);
51 assertEqual(window.getSelection().getRangeAt(0).endOffset, div.innerText.length);
53 // Having the log in DOM will interfere with the test so append it at last.
54 var console = document.createElement('pre');
55 document.body.appendChild(console);
56 console.innerHTML = log;
59 </script>
60 </body>
61 </html>