Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / hit-test-anonymous.html
blob072a2a35340132b81d280b2009cfdfd71638a5b2
1 <head>
2 <style>
3 span:before {
4 content: "<before> ";
6 span:after {
7 content: " <after>";
9 </style>
10 <script>
11 function nodeAsString(node)
13 if (node && node.nodeType == Node.TEXT_NODE)
14 return "text in " + nodeAsString(node.parentNode);
15 if (node && node.nodeType == Node.ELEMENT_NODE) {
16 var id;
17 if (id = node.getAttribute("id"))
18 return id;
20 return node;
22 function selectionAsString()
24 return "(" + nodeAsString(getSelection().anchorNode)
25 + ", " + getSelection().anchorOffset
26 + "), (" + nodeAsString(getSelection().focusNode)
27 + ", " + getSelection().focusOffset + ")";
29 function checkSelection(step, expected)
31 if (selectionAsString() !== expected) {
32 document.getElementById("result").innerHTML = "FAIL: After step " + step + " selection was " + selectionAsString();
33 return true;
35 return false;
37 function runTest()
39 if (window.testRunner)
40 testRunner.dumpAsText();
42 var block = document.getElementById("block");
43 var x = block.offsetLeft + 5;
44 var y = block.offsetTop + 5;
46 if (window.eventSender) {
47 // Click in the anonymous content, check that cursor goes to
48 // the start of the span.
49 eventSender.mouseMoveTo(x, y);
50 eventSender.mouseDown();
51 eventSender.mouseUp();
54 if (checkSelection(1, "(text in span, 0), (text in span, 0)"))
55 return;
57 x = block.offsetLeft + 200;
59 if (window.eventSender) {
60 // Click in the regular text, make sure it goes into the span.
61 eventSender.mouseMoveTo(x, y);
62 eventSender.mouseDown();
63 eventSender.mouseUp();
66 if (checkSelection(2, "(text in span, 7), (text in span, 7)"))
67 return;
69 document.getElementById("result").innerHTML = "SUCCESS";
71 </script>
72 </head>
73 <body onload="runTest()">
74 <p>This tests clicking in anonymous content to see if a selection is successfully created.</p>
75 <p id="block" contentEditable style="border: 1px solid blue; font-size:30px"><span id="span">This is the selectable text.</span></div>
76 <p id="result">TEST DID NOT RUN</div>
77 </body>