| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 function testAddRange(exception, range, endpoints, qualifier, testName) { | 3 function testAddRange(exception, range, endpoints, qualifier, testName) { |
| 4 if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2])) { | 4 if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2])) { |
| 5 test(function() { | 5 testAddRangeDoesNothing(exception, range, endpoints, qualifier, testName
); |
| 6 assert_equals(exception, null, "Test setup must not throw exceptions
"); | |
| 7 | |
| 8 assertSelectionNoChange(function() { selection.addRange(range); }); | |
| 9 assert_equals(range.startContainer, endpoints[0], | |
| 10 "addRange() must not modify the startContainer of the Range it's
given"); | |
| 11 assert_equals(range.startOffset, endpoints[1], | |
| 12 "addRange() must not modify the startOffset of the Range it's gi
ven"); | |
| 13 assert_equals(range.endContainer, endpoints[2], | |
| 14 "addRange() must not modify the endContainer of the Range it's g
iven"); | |
| 15 assert_equals(range.endOffset, endpoints[3], | |
| 16 "addRange() must not modify the endOffset of the Range it's give
n"); | |
| 17 }, testName + ": " + qualifier + " addRange() must do nothing"); | |
| 18 return; | 6 return; |
| 19 } | 7 } |
| 20 | 8 |
| 21 test(function() { | 9 test(function() { |
| 22 assert_equals(exception, null, "Test setup must not throw exceptions"); | 10 assert_equals(exception, null, "Test setup must not throw exceptions"); |
| 23 | 11 |
| 24 selection.addRange(range); | 12 selection.addRange(range); |
| 25 | 13 |
| 26 assert_equals(range.startContainer, endpoints[0], | 14 assert_equals(range.startContainer, endpoints[0], |
| 27 "addRange() must not modify the startContainer of the Range it's giv
en"); | 15 "addRange() must not modify the startContainer of the Range it's giv
en"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, startContainer of the Selection's last Range must match the added Ra
nge"); | 108 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, startContainer of the Selection's last Range must match the added Ra
nge"); |
| 121 assert_equals(newRange.startOffset, range.startOffset, | 109 assert_equals(newRange.startOffset, range.startOffset, |
| 122 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, startOffset of the Selection's last Range must match the added Range
"); | 110 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, startOffset of the Selection's last Range must match the added Range
"); |
| 123 assert_equals(newRange.endContainer, range.endContainer, | 111 assert_equals(newRange.endContainer, range.endContainer, |
| 124 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, endContainer of the Selection's last Range must match the added Rang
e"); | 112 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, endContainer of the Selection's last Range must match the added Rang
e"); |
| 125 assert_equals(newRange.endOffset, range.endOffset, | 113 assert_equals(newRange.endOffset, range.endOffset, |
| 126 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, endOffset of the Selection's last Range must match the added Range")
; | 114 "After " + qualifier + " addRange(), after mutating the Selection's
last Range, endOffset of the Selection's last Range must match the added Range")
; |
| 127 }, testName + ": modifying the Selection's last Range must modify the " + qu
alifier + " added Range"); | 115 }, testName + ": modifying the Selection's last Range must modify the " + qu
alifier + " added Range"); |
| 128 } | 116 } |
| 129 | 117 |
| 118 function testAddRangeDoesNothing(exception, range, endpoints, qualifier, testNam
e) { |
| 119 test(function() { |
| 120 assert_equals(exception, null, "Test setup must not throw exceptions"); |
| 121 |
| 122 assertSelectionNoChange(function() { selection.addRange(range); }); |
| 123 assert_equals(range.startContainer, endpoints[0], |
| 124 "addRange() must not modify the startContainer of the Range it's giv
en"); |
| 125 assert_equals(range.startOffset, endpoints[1], |
| 126 "addRange() must not modify the startOffset of the Range it's given"
); |
| 127 assert_equals(range.endContainer, endpoints[2], |
| 128 "addRange() must not modify the endContainer of the Range it's given
"); |
| 129 assert_equals(range.endOffset, endpoints[3], |
| 130 "addRange() must not modify the endOffset of the Range it's given"); |
| 131 }, testName + ": " + qualifier + " addRange() must do nothing"); |
| 132 } |
| 133 |
| 130 // Do only n evals, not n^2 | 134 // Do only n evals, not n^2 |
| 131 var testRangesEvaled = testRanges.map(eval); | 135 var testRangesEvaled = testRanges.map(eval); |
| 132 | 136 |
| 133 // Run a subset of all of addRange tests. | 137 // Run a subset of all of addRange tests. |
| 134 // Huge number of tests in a single file causes problems. Each of | 138 // Huge number of tests in a single file causes problems. Each of |
| 135 // addRange-NN.html runs a part of them. | 139 // addRange-NN.html runs a part of them. |
| 136 // | 140 // |
| 137 // startIndex - Start index in testRanges array | 141 // startIndex - Start index in testRanges array |
| 138 // optionalEndIndex - End index in testRanges array + 1. If this argument is | 142 // optionalEndIndex - End index in testRanges array + 1. If this argument is |
| 139 // omitted, testRanges.length is applied. | 143 // omitted, testRanges.length is applied. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 191 } |
| 188 if (range2.endOffset !== endpoints2[3]) { | 192 if (range2.endOffset !== endpoints2[3]) { |
| 189 throw "Sanity check: the second Range we created must have t
he desired endOffset"; | 193 throw "Sanity check: the second Range we created must have t
he desired endOffset"; |
| 190 } | 194 } |
| 191 } catch (e) { | 195 } catch (e) { |
| 192 exception = e; | 196 exception = e; |
| 193 } | 197 } |
| 194 | 198 |
| 195 testAddRange(exception, range1, endpoints1, "first", testName); | 199 testAddRange(exception, range1, endpoints1, "first", testName); |
| 196 if (selection.rangeCount > 0) | 200 if (selection.rangeCount > 0) |
| 197 testAddRange(exception, range2, endpoints2, "second", testName); | 201 testAddRangeDoesNothing(exception, range2, endpoints2, "second",
testName); |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 } | 204 } |
| 201 | 205 |
| OLD | NEW |