3 <title>Test for Range.comparePoint()
</title>
7 // comparePoint( refNode, offset ) - This method returns Ð1, 0 or 1 depending on
8 // if the point described by the refNode node and an offset within the node is
9 // before, same as, or after the range respectively.
11 var range
= document
.createRange();
13 // test 1 - point before range, different node
14 var expectedResult
= -1;
15 range
.selectNode(document
.getElementById("a2"));
16 var result
= range
.comparePoint(document
.getElementById("b1"), 1);
17 if (result
== expectedResult
)
18 document
.getElementById("test1").innerHTML
= "test 1 passed";
20 // test 2 - point before range, same node
21 range
.setStart(document
.getElementById("b2"), 1);
22 result
= range
.comparePoint(document
.getElementById("b2"), 0);
23 if (result
== expectedResult
)
24 document
.getElementById("test2").innerHTML
= "test 2 passed";
26 // test 3 - point on range start boundary
28 range
.selectNode(document
.getElementById("b2"));
29 result
= range
.comparePoint(document
.getElementById("b2"), 0);
30 if (result
== expectedResult
)
31 document
.getElementById("test3").innerHTML
= "test 3 passed";
33 // test 4 - point within range, same node
34 result
= range
.comparePoint(document
.getElementById("b2"), 1);
35 if (result
== expectedResult
)
36 document
.getElementById("test4").innerHTML
= "test 4 passed";
38 // test 5 - point within range, spans nodes
39 range
.setStart(document
.getElementById("b1"), 1);
40 range
.setEnd(document
.getElementById("c2"), 1);
41 result
= range
.comparePoint( document
.getElementById("c2"), 0);
42 if (result
== expectedResult
)
43 document
.getElementById("test5").innerHTML
= "test 5 passed";
45 // test 6 - point on range end boundary
46 result
= range
.comparePoint(document
.getElementById("c2"), 1);
47 if (result
== expectedResult
)
48 document
.getElementById("test6").innerHTML
= "test 6 passed";
50 // test 7 - point after range, same node
51 range
.setEnd(document
.getElementById("c2"), 0);
53 result
= range
.comparePoint(document
.getElementById("c2"), 1);
54 if (result
== expectedResult
)
55 document
.getElementById("test7").innerHTML
= "test 7 passed";
57 // test 8 - point after range, different node
59 result
= range
.comparePoint(document
.getElementById("a3"), 1);
60 if (result
== expectedResult
)
61 document
.getElementById("test8").innerHTML
= "test 8 passed";
63 // test 9 - detached range, attached node
65 var detachedRange
= document
.createRange();
66 detachedRange
.detach(); // no-op.
67 result
= detachedRange
.comparePoint(document
.getElementById("a1"), 0);
68 if (result
== expectedResult
)
69 document
.getElementById("test9").innerHTML
= "test 9 passed";
71 // test 10 - attached range, detached node
72 // firefox throws an exception
73 range
.selectNode(document
.getElementById("a1"));
74 var node
= document
.getElementById("b1");
75 node
.parentNode
.removeChild(node
);
77 range
.comparePoint(node
, 0);
79 document
.getElementById("test10").innerHTML
= "test 10 passed";
82 // test 11 - should throw TypeError when node is not an object
84 range
.comparePoint(null, 0);
86 if (e
.name
== 'TypeError')
87 document
.getElementById("test11").innerHTML
= "test 11 passed";
90 if (window
.testRunner
)
91 testRunner
.dumpAsText();
96 <body onload=
"test();">
98 <!-- visible area with test results -->
99 <div id=test1
><span style=
"color: red;">test
1 failed
</span></div><br>
100 <div id=test2
><span style=
"color: red;">test
2 failed
</span></div><br>
101 <div id=test3
><span style=
"color: red;">test
3 failed
</span></div><br>
102 <div id=test4
><span style=
"color: red;">test
4 failed
</span></div><br>
103 <div id=test5
><span style=
"color: red;">test
5 failed
</span></div><br>
104 <div id=test6
><span style=
"color: red;">test
6 failed
</span></div><br>
105 <div id=test7
><span style=
"color: red;">test
7 failed
</span></div><br>
106 <div id=test8
><span style=
"color: red;">test
8 failed
</span></div><br>
107 <div id=test9
><span style=
"color: red;">test
9 failed
</span></div><br>
108 <div id=test10
><span style=
"color: red;">test
10 failed
</span></div><br>
109 <div id=test11
><span style=
"color: red;">test
11 failed
</span></div><br>
111 <!-- hidden area to create the ranges being tested -->
112 <div style=
"visibility: hidden">
114 <div id=b1
>b1
</div> <div id=c1
>c1
</div>
118 <div id=b2
>b2
</div> <div id=c2
>c2
</div>
122 <div id=b3
>b3
</div> <div id=c3
>c3
</div>