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>
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();
28 function assertEqual(actual
, expected
) {
29 if (actual
== expected
)
32 log
+= 'FAIL - expected ' + expected
+ ' but got ' + actual
;
36 if (!window
.testRunner
|| !window
.eventSender
)
37 document
.writeln("This test requires eventSender since the bug does not reproduce reliably when tested manually.");
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
;