3 <div id=
"test"><span id=
"span1">foo
<span id=
"span2">bar
</span></span><span id=
"span3">baz
</span></div>
4 <div id=
"console"></div>
6 var s
= window
.getSelection();
7 var testDiv
= document
.getElementById("test");
8 var span1
= document
.getElementById("span1");
9 var span2
= document
.getElementById("span2");
10 var span3
= document
.getElementById("span3");
13 var li
= document
.createElement("li");
14 li
.appendChild(document
.createTextNode(str
));
15 document
.getElementById("console").appendChild(li
);
18 function shouldBe(expr
, expected
) {
19 var actual
= eval(expr
);
20 if (actual
!= expected
)
21 log("Failure: " + expr
+ " should be " + expected
+ ", was " + actual
+ ".");
23 log("Success: " + expr
+ " is " + expected
+ ".");
26 function shouldThrow(expr
) {
29 log("Failure: " + expr
+ " didn't raise an exception" + ".");
31 log("Success: " + expr
+ " raised " + ex
+ ".");
35 if (window
.testRunner
)
36 testRunner
.dumpAsText();
38 var r
= document
.createRange();
41 r
.setStart(span2
.firstChild
, 1);
42 r
.setEnd(span2
.firstChild
, 1);
45 s
.extend(span2
.firstChild
, 3);
46 shouldBe('window.getSelection()', 'ar');
48 shouldThrow('s.extend(span2.firstChild, 4)');
50 shouldThrow('s.extend(span2.firstChild, -1)');
52 s
.extend(span2
.firstChild
, 0);
53 shouldBe('window.getSelection()', 'b');
56 shouldBe('window.getSelection()', 'arbaz');
58 shouldThrow('s.extend()');
59 shouldThrow('s.extend(null, 0)');