Editing tests should use testRunner instead of layoutTestController
[WebKit-https.git] / LayoutTests / editing / selection / resources / select-out-of-floated-editable.js
1 function log(msg) {
2     document.getElementById('console').appendChild(document.createTextNode(msg + '\n'));
3 }
4
5 if (window.testRunner && window.eventSender) {
6     testRunner.dumpAsText();
7
8     var x = floatedEditable.offsetLeft + (floatedEditable.offsetWidth / 2);
9     var y = floatedEditable.offsetTop + (floatedEditable.offsetHeight / 2);
10     eventSender.mouseMoveTo(x, y);
11     eventSender.mouseDown();
12     x = floatedEditable.offsetLeft + floatedEditable.offsetWidth + 5;
13     eventSender.mouseMoveTo(x, y);
14     eventSender.leapForward(250);
15     eventSender.mouseUp();
16
17     checkSelection();
18 } else {
19     window.onmouseup = function() {
20         window.setTimeout(function() {
21             log('Input selection start: ' + getSelectionStart(floatedEditable) + ', end: ' +
22                 getSelectionEnd(floatedEditable));
23             checkSelection();
24         }, 0);  // Without a timeout the selection is inaccurately printed
25     }
26 }
27
28 function getSelectionStart(element) {
29     return element.isContentEditable ? window.getSelection().baseOffset : element.selectionStart;
30 }
31
32 function getSelectionEnd(element) {
33     return element.isContentEditable ? window.getSelection().extentOffset : element.selectionEnd;
34 }
35
36 function checkSelection() {
37     var inputText = floatedEditable.isContentEditable ? floatedEditable.textContent : floatedEditable.value;
38     var selectionStart = getSelectionStart(floatedEditable);
39     var selectionEnd = getSelectionEnd(floatedEditable);
40
41     var selectionStartsFromMiddle = selectionStart > 0 && selectionStart < inputText.length;
42     var selectionGoesToEnd = selectionEnd == inputText.length;
43     if (selectionStartsFromMiddle && selectionGoesToEnd)
44         result.innerHTML = '<span style="padding: 5px; background-color: green">SUCCESS</span>';
45     else
46         result.innerHTML = '<span style="padding: 5px; background-color: red">FAIL</span>';
47 }