4 function nodeAsString(node
)
6 if (node
&& node
.nodeType
== Node
.TEXT_NODE
)
7 return "text in " + nodeAsString(node
.parentNode
);
8 if (node
&& node
.nodeType
== Node
.ELEMENT_NODE
) {
10 if (id
= node
.getAttribute("id"))
15 function selectionAsString()
17 return "(" + nodeAsString(getSelection().anchorNode
)
18 + ", " + getSelection().anchorOffset
19 + "), (" + nodeAsString(getSelection().focusNode
)
20 + ", " + getSelection().focusOffset
+ ")";
22 function checkSelection(step
, expected
)
24 if (selectionAsString() !== expected
) {
25 document
.getElementById("result").innerHTML
= "FAIL: After step " + step
+ " selection was " + selectionAsString();
32 if (window
.testRunner
)
33 testRunner
.dumpAsText();
34 getSelection().collapse(document
.getElementById("first").firstChild
, 4);
35 if (checkSelection(1, "(text in first, 4), (text in first, 4)"))
37 getSelection().modify("extend", "backward", "line");
38 if (checkSelection(2, "(text in first, 4), (text in first, 0)"))
40 getSelection().collapse(document
.getElementById("last").firstChild
, 4);
41 if (checkSelection(3, "(text in last, 4), (text in last, 4)"))
43 getSelection().modify("extend", "forward", "line");
44 if (checkSelection(4, "(text in last, 4), (text in last, 61)"))
46 getSelection().collapse(document
.getElementById("first").firstChild
, 4);
47 if (checkSelection(5, "(text in first, 4), (text in first, 4)"))
49 getSelection().modify("extend", "backward", "paragraph");
50 if (checkSelection(6, "(text in first, 4), (text in first, 0)"))
52 getSelection().collapse(document
.getElementById("last").firstChild
, 4);
53 if (checkSelection(7, "(text in last, 4), (text in last, 4)"))
55 getSelection().modify("extend", "forward", "paragraph");
56 if (checkSelection(8, "(text in last, 4), (text in last, 61)"))
58 document
.getElementById("result").innerHTML
= "SUCCESS";
62 <body onload=
"runTest()"><p id=
"first">This is the first paragraph, used for the moving-backward test.
</p>
63 <p>This tests for a problem with selections at document edges.
</p>
64 <p id=
"result">TEST HAS NOT YET RUN.
</p>
65 <p id=
"last">This is the last paragraph, used for the moving-forward test.
</p>