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
) {
17 if (id
= node
.getAttribute("id"))
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();
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)"))
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)"))
69 document
.getElementById("result").innerHTML
= "SUCCESS";
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>