OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>Range.intersectsNode() tests</title> |
| 3 <link rel="author" title="Aryeh Gregor" href=ayg@aryeh.name> |
| 4 <meta name=timeout content=long> |
| 5 <div id=log></div> |
| 6 <script src=../../../../resources/testharness.js></script> |
| 7 <script src=../../../../resources/testharnessreport.js></script> |
| 8 <script src=../common.js></script> |
| 9 <script> |
| 10 "use strict"; |
| 11 |
| 12 // Will be filled in on the first run for that range |
| 13 var testRangesCached = []; |
| 14 |
| 15 for (var i = 0; i < testNodes.length; i++) { |
| 16 var node = eval(testNodes[i]); |
| 17 |
| 18 for (var j = 0; j < testRanges.length; j++) { |
| 19 test(function() { |
| 20 if (testRangesCached[j] === undefined) { |
| 21 try { |
| 22 testRangesCached[j] = rangeFromEndpoints(eval(testRanges[i])); |
| 23 } catch(e) { |
| 24 testRangesCached[j] = null; |
| 25 } |
| 26 } |
| 27 assert_not_equals(testRangesCached[j], null, |
| 28 "Setting up the range failed"); |
| 29 |
| 30 var range = testRangesCached[j].cloneRange(); |
| 31 |
| 32 // "If node's root is different from the context object's root, |
| 33 // return false and terminate these steps." |
| 34 if (furthestAncestor(node) !== furthestAncestor(range.startContainer)) { |
| 35 assert_equals(range.intersectsNode(node), false, |
| 36 "Must return false if node and range have different roots"); |
| 37 return; |
| 38 } |
| 39 |
| 40 // "Let parent be node's parent." |
| 41 var parent_ = node.parentNode; |
| 42 |
| 43 // "If parent is null, return true and terminate these steps." |
| 44 if (!parent_) { |
| 45 assert_equals(range.intersectsNode(node), true, |
| 46 "Must return true if node's parent is null"); |
| 47 return; |
| 48 } |
| 49 |
| 50 // "Let offset be node's index." |
| 51 var offset = indexOf(node); |
| 52 |
| 53 // "If (parent, offset) is before end and (parent, offset + 1) is |
| 54 // after start, return true and terminate these steps." |
| 55 if (getPosition(parent_, offset, range.endContainer, range.endOffset) ===
"before" |
| 56 && getPosition(parent_, offset + 1, range.startContainer, range.startOffse
t) === "after") { |
| 57 assert_equals(range.intersectsNode(node), true, |
| 58 "Must return true if (parent, offset) is before range end and (parent,
offset + 1) is after range start"); |
| 59 return; |
| 60 } |
| 61 |
| 62 // "Return false." |
| 63 assert_equals(range.intersectsNode(node), false, |
| 64 "Must return false if (parent, offset) is not before range end or (paren
t, offset + 1) is not after range start"); |
| 65 }, "Node " + i + " " + testNodes[i] + ", range " + j + " " + testRanges[j]); |
| 66 } |
| 67 } |
| 68 |
| 69 testDiv.style.display = "none"; |
| 70 </script> |
OLD | NEW |