| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 // Also test a selection with no ranges | 3 // Also test a selection with no ranges |
| 4 testRanges.unshift("[]"); | 4 testRanges.unshift("[]"); |
| 5 | 5 |
| 6 // Run a subset of all of extend tests. | 6 // Run a subset of all of extend tests. |
| 7 // Huge number of tests in a single file causes problems. Each of | 7 // Huge number of tests in a single file causes problems. Each of |
| 8 // extend-NN.html runs a part of them. | 8 // extend-NN.html runs a part of them. |
| 9 // | 9 // |
| 10 // startIndex - Start index in testRanges array | 10 // startIndex - Start index in testRanges array |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 function testExtend(endpoints, target) { | 52 function testExtend(endpoints, target) { |
| 53 assert_equals(getSelection().rangeCount, endpoints.length/4, | 53 assert_equals(getSelection().rangeCount, endpoints.length/4, |
| 54 "Sanity check: rangeCount must be correct"); | 54 "Sanity check: rangeCount must be correct"); |
| 55 | 55 |
| 56 var node = target[0]; | 56 var node = target[0]; |
| 57 var offset = target[1]; | 57 var offset = target[1]; |
| 58 | 58 |
| 59 // "If node's root is not the document associated with the context object, |
| 60 // abort these steps." |
| 61 if (!document.contains(node)) { |
| 62 assertSelectionNoChange(function() { |
| 63 selection.extend(node, offset); |
| 64 }); |
| 65 return; |
| 66 } |
| 67 |
| 59 // "If the context object's range is null, throw an InvalidStateError | 68 // "If the context object's range is null, throw an InvalidStateError |
| 60 // exception and abort these steps." | 69 // exception and abort these steps." |
| 61 if (getSelection().rangeCount == 0) { | 70 if (getSelection().rangeCount == 0) { |
| 62 assert_throws("INVALID_STATE_ERR", function() { | 71 assert_throws("INVALID_STATE_ERR", function() { |
| 63 selection.extend(node, offset); | 72 selection.extend(node, offset); |
| 64 }, "extend() when rangeCount is 0 must throw InvalidStateError"); | 73 }, "extend() when rangeCount is 0 must throw InvalidStateError"); |
| 65 return; | 74 return; |
| 66 } | 75 } |
| 67 | 76 |
| 68 assert_equals(getSelection().getRangeAt(0).startContainer, endpoints[0], | 77 assert_equals(getSelection().getRangeAt(0).startContainer, endpoints[0], |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 assert_equals(getSelection().anchorOffset, offset, | 149 assert_equals(getSelection().anchorOffset, offset, |
| 141 "anchorOffset must be the offset passed to extend() if the node has
a different root from the original range"); | 150 "anchorOffset must be the offset passed to extend() if the node has
a different root from the original range"); |
| 142 } | 151 } |
| 143 assert_equals(getSelection().focusNode, node, | 152 assert_equals(getSelection().focusNode, node, |
| 144 "focusNode must be the node passed to extend()"); | 153 "focusNode must be the node passed to extend()"); |
| 145 assert_equals(getSelection().focusOffset, offset, | 154 assert_equals(getSelection().focusOffset, offset, |
| 146 "focusOffset must be the offset passed to extend()"); | 155 "focusOffset must be the offset passed to extend()"); |
| 147 assert_not_equals(getSelection().getRangeAt(0), originalRange, | 156 assert_not_equals(getSelection().getRangeAt(0), originalRange, |
| 148 "extend() must replace any existing range with a new one, not mutate the
existing one"); | 157 "extend() must replace any existing range with a new one, not mutate the
existing one"); |
| 149 } | 158 } |
| OLD | NEW |