| <html> |
| <head> |
| <title>Test for Range.isPointInRange()</title> |
| <script> |
| function test() |
| { |
| // isPointInRange( refNode, offset ) - This method returns Ð1, 0 or 1 depending on |
| // if the point described by the refNode node and an offset within the node is |
| // before, same as, or after the range respectively. |
| |
| var range = document.createRange(); |
| |
| // test 1 - point before range, different node |
| var expectedResult = false; |
| range.selectNode(document.getElementById("a2")); |
| var result = range.isPointInRange(document.getElementById("b1"), 1); |
| if (result == expectedResult) |
| document.getElementById("test1").innerHTML = "test 1 passed"; |
| |
| // test 2 - point before range, same node |
| range.setStart(document.getElementById("b2"), 1); |
| result = range.isPointInRange(document.getElementById("b2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test2").innerHTML = "test 2 passed"; |
| |
| // test 3 - point on range start boundary |
| expectedResult = true; |
| range.selectNode(document.getElementById("b2")); |
| result = range.isPointInRange(document.getElementById("b2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test3").innerHTML = "test 3 passed"; |
| |
| // test 4 - point within range, same node |
| result = range.isPointInRange(document.getElementById("b2"), 1); |
| if (result == expectedResult) |
| document.getElementById("test4").innerHTML = "test 4 passed"; |
| |
| // test 5 - point within range, spans nodes |
| range.setStart(document.getElementById("b1"), 1); |
| range.setEnd(document.getElementById("c2"), 1); |
| result = range.isPointInRange( document.getElementById("c2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test5").innerHTML = "test 5 passed"; |
| |
| // test 6 - point on range end boundary |
| result = range.isPointInRange(document.getElementById("c2"), 1); |
| if (result == expectedResult) |
| document.getElementById("test6").innerHTML = "test 6 passed"; |
| |
| // test 7 - point after range, same node |
| expectedResult = false; |
| range.setEnd(document.getElementById("c2"), 0); |
| result = range.isPointInRange(document.getElementById("c2"), 1); |
| if (result == expectedResult) |
| document.getElementById("test7").innerHTML = "test 7 passed"; |
| |
| // test 8 - point after range, different node |
| result = range.isPointInRange(document.getElementById("a3"), 1); |
| if (result == expectedResult) |
| document.getElementById("test8").innerHTML = "test 8 passed"; |
| |
| // test 9 - detached range, attached node |
| // detach() is a no-op. |
| expectedResult = false; |
| var detachedRange = document.createRange(); |
| detachedRange.detach(); |
| result = detachedRange.isPointInRange(document.getElementById("a1"), 0); |
| if (result == expectedResult) |
| document.getElementById("test9").innerHTML = "test 9 passed"; |
| |
| // test 10 - attached range, detached node |
| // firefox does not throw an exception and returns false for this test |
| range.selectNode(document.getElementById("a1")); |
| var node = document.getElementById("b1"); |
| node.parentNode.removeChild(node); |
| result = range.isPointInRange(node, 0); |
| if (result == expectedResult) |
| document.getElementById("test10").innerHTML = "test 10 passed"; |
| |
| if (window.testRunner) |
| testRunner.dumpAsText(); |
| } |
| |
| </script> |
| </head> |
| <body onload="test();"> |
| |
| <!-- visible area with test results --> |
| <div id=test1><span style="color: red;">test 1 failed</span></div><br> |
| <div id=test2><span style="color: red;">test 2 failed</span></div><br> |
| <div id=test3><span style="color: red;">test 3 failed</span></div><br> |
| <div id=test4><span style="color: red;">test 4 failed</span></div><br> |
| <div id=test5><span style="color: red;">test 5 failed</span></div><br> |
| <div id=test6><span style="color: red;">test 6 failed</span></div><br> |
| <div id=test7><span style="color: red;">test 7 failed</span></div><br> |
| <div id=test8><span style="color: red;">test 8 failed</span></div><br> |
| <div id=test9><span style="color: red;">test 9 failed</span></div><br> |
| <div id=test10><span style="color: red;">test 10 failed</span></div><br> |
| |
| <!-- hidden area to create the ranges being tested --> |
| <div style="visibility: hidden"> |
| <div id=a1>a1 |
| <div id=b1>b1</div> <div id=c1>c1</div> |
| </div> |
| |
| <div id=a2>a2 |
| <div id=b2>b2</div> <div id=c2>c2</div> |
| </div> |
| |
| <div id=a3>a3 |
| <div id=b3>b3</div> <div id=c3>c3</div> |
| </div> |
| </div> |
| |
| </body> |
| </html> |