Missing cursor/caret showing in search field on google.com
[WebKit-https.git] / LayoutTests / editing / selection / context-menu-text-selection-lookup.html
1 <body onload="load()">
2 <p>This test checks that triggering the context menu selects/doesn't select using surround text as context (as platform-appropriate).</p>
3 <div id="text">New York</div>
4 <div id="resultmac">RUNNING</div>
5 <div id="resultwin">RUNNING</div>
6 <div id="resultunix">RUNNING</div>
7 </body>
8 <script>
9 function test(platform, selectionExpected, expectedText, result)
10 {
11     // clear selection
12     window.getSelection().removeAllRanges();
13
14     internals.settings.setEditingBehavior(platform);
15
16     var text = document.getElementById("text");
17
18     var x = text.offsetParent.offsetLeft + text.offsetLeft + 4;
19     var y = text.offsetParent.offsetTop + text.offsetTop + text.offsetHeight / 2;
20
21     eventSender.mouseMoveTo(x, y);
22     eventSender.contextClick();
23     // esc key to kill the context menu
24     eventSender.keyDown(String.fromCharCode(0x001B), null);
25
26     var resultElement = document.getElementById(result);
27     var selectionType = window.getSelection().type;
28     if (selectionExpected) {
29         if (selectionType == "Range") {
30             var selectionText = window.getSelection().toString();
31             if (selectionText == expectedText)
32                 resultElement.innerHTML = "SUCCESS";
33             else
34                 resultElement.innerHTML = "FAILURE: We expected " + expectedText + ", but we got " + selectionText + ".";
35         } else
36             resultElement.innerHTML = "FAILURE: There should be a selection.";
37     } else {
38         if (selectionType == "Range")
39             resultElement.innerHTML = "FAILURE: There shouldn't be a selection.";
40         else
41             resultElement.innerHTML = "SUCCESS";
42     }
43 }
44
45 function load()
46 {
47     if (!window.eventSender || !window.testRunner || !window.internals)
48         return;
49
50     testRunner.dumpAsText();
51
52     test('mac', true, 'New York', 'resultmac');
53     test('win', false, '', 'resultwin');
54     test('unix', false, '', 'resultunix');
55 }
56 </script>