| <html> |
| <head> |
| <title>Test for Range.comparePoint()</title> |
| <script> |
| function test() |
| { |
| // comparePoint( 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 = -1; |
| range.selectNode(document.getElementById("a2")); |
| var result = range.comparePoint(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.comparePoint(document.getElementById("b2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test2").innerHTML = "test 2 passed"; |
| |
| // test 3 - point on range start boundary |
| expectedResult = 0; |
| range.selectNode(document.getElementById("b2")); |
| result = range.comparePoint(document.getElementById("b2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test3").innerHTML = "test 3 passed"; |
| |
| // test 4 - point within range, same node |
| result = range.comparePoint(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.comparePoint( document.getElementById("c2"), 0); |
| if (result == expectedResult) |
| document.getElementById("test5").innerHTML = "test 5 passed"; |
| |
| // test 6 - point on range end boundary |
| result = range.comparePoint(document.getElementById("c2"), 1); |
| if (result == expectedResult) |
| document.getElementById("test6").innerHTML = "test 6 passed"; |
| |
| // test 7 - point after range, same node |
| range.setEnd(document.getElementById("c2"), 0); |
| expectedResult = 1; |
| result = range.comparePoint(document.getElementById("c2"), 1); |
| if (result == expectedResult) |
| document.getElementById("test7").innerHTML = "test 7 passed"; |
| |
| // test 8 - point after range, different node |
| expectedResult = 1; |
| result = range.comparePoint(document.getElementById("a3"), 1); |
| if (result == expectedResult) |
| document.getElementById("test8").innerHTML = "test 8 passed"; |
| |
| // test 9 - detached range, attached node |
| // firefox throws an exception and does not return a value |
| var detachedRange = document.createRange(); |
| detachedRange.detach(); |
| try { |
| result = detachedRange.comparePoint(document.getElementById("a1"), 0); |
| } catch (e) { |
| document.getElementById("test9").innerHTML = "test 9 passed"; |
| } |
| |
| // test 10 - attached range, detached node |
| // firefox throws an exception |
| range.selectNode(document.getElementById("a1")); |
| var node = document.getElementById("b1"); |
| node.parentNode.removeChild(node); |
| try { |
| range.comparePoint(node, 0); |
| } catch (e) { |
| document.getElementById("test10").innerHTML = "test 10 passed"; |
| } |
| |
| if (window.layoutTestController) |
| layoutTestController.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> |