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 |
11 // optionalEndIndex - End index in testRanges array + 1. If this argument is | 11 // optionalEndIndex - End index in testRanges array + 1. If this argument is |
12 // omitted, testRanges.length is applied. | 12 // omitted, testRanges.length is applied. |
13 function testExtendSubSet(startIndex, optionalEndIndex) { | 13 function testExtendSubSet(startIndex, optionalEndIndex) { |
14 var endIndex = optionalEndIndex === undefined ? testRanges.length : optional
EndIndex; | 14 var endIndex = optionalEndIndex === undefined ? testRanges.length : optional
EndIndex; |
15 if (startIndex < 0 || startIndex >= testRanges.length) | 15 if (startIndex < 0 || startIndex >= testRanges.length) |
16 throw "Sanity check: Specified index is invalid."; | 16 throw "Sanity check: Specified index is invalid."; |
17 if (endIndex < 0 || endIndex > testRanges.length) | 17 if (endIndex < 0 || endIndex > testRanges.length) |
18 throw "Sanity check: Specified index is invalid."; | 18 throw "Sanity check: Specified index is invalid."; |
19 | 19 |
20 // We test Selections that go both forwards and backwards here. In the | 20 // We test Selections that go both forwards and backwards here. In the |
21 // latter case we need to use extend() to force it to go backwards, which is | 21 // latter case we need to use extend() to force it to go backwards, which is |
22 // fair enough, since that's what we're testing. We test collapsed | 22 // fair enough, since that's what we're testing. We test collapsed |
23 // selections only once. | 23 // selections only once. |
24 for (var i = startIndex; i < endIndex; i++) { | 24 for (var i = startIndex; i < endIndex; i++) { |
25 var endpoints = eval(testRanges[i]); | 25 var endpoints = eval(testRanges[i]); |
| 26 // We can't test extend() with unselectable endpoints. |
| 27 if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2])) |
| 28 continue; |
26 for (var j = 0; j < testPoints.length; j++) { | 29 for (var j = 0; j < testPoints.length; j++) { |
27 if (endpoints[0] == endpoints[2] | 30 if (endpoints[0] == endpoints[2] |
28 && endpoints[1] == endpoints[3]) { | 31 && endpoints[1] == endpoints[3]) { |
29 // Test collapsed selections only once | 32 // Test collapsed selections only once |
30 test(function() { | 33 test(function() { |
31 setSelectionForwards(endpoints); | 34 setSelectionForwards(endpoints); |
32 testExtend(endpoints, eval(testPoints[j])); | 35 testExtend(endpoints, eval(testPoints[j])); |
33 }, "extend() with range " + i + " " + testRanges[i] | 36 }, "extend() with range " + i + " " + testRanges[i] |
34 + " and point " + j + " " + testPoints[j]); | 37 + " and point " + j + " " + testPoints[j]); |
35 } else { | 38 } else { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 assert_equals(getSelection().anchorOffset, offset, | 152 assert_equals(getSelection().anchorOffset, offset, |
150 "anchorOffset must be the offset passed to extend() if the node has
a different root from the original range"); | 153 "anchorOffset must be the offset passed to extend() if the node has
a different root from the original range"); |
151 } | 154 } |
152 assert_equals(getSelection().focusNode, node, | 155 assert_equals(getSelection().focusNode, node, |
153 "focusNode must be the node passed to extend()"); | 156 "focusNode must be the node passed to extend()"); |
154 assert_equals(getSelection().focusOffset, offset, | 157 assert_equals(getSelection().focusOffset, offset, |
155 "focusOffset must be the offset passed to extend()"); | 158 "focusOffset must be the offset passed to extend()"); |
156 assert_not_equals(getSelection().getRangeAt(0), originalRange, | 159 assert_not_equals(getSelection().getRangeAt(0), originalRange, |
157 "extend() must replace any existing range with a new one, not mutate the
existing one"); | 160 "extend() must replace any existing range with a new one, not mutate the
existing one"); |
158 } | 161 } |
OLD | NEW |