| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 function testCollapse(range, point) { | 3 function testCollapse(range, point) { |
| 4 selection.removeAllRanges(); | 4 selection.removeAllRanges(); |
| 5 var addedRange; | 5 var addedRange; |
| 6 if (range) { | 6 if (range) { |
| 7 addedRange = range.cloneRange(); | 7 addedRange = range.cloneRange(); |
| 8 selection.addRange(addedRange); | 8 selection.addRange(addedRange); |
| 9 } | 9 } |
| 10 | 10 |
| 11 if (point[0].nodeType == Node.DOCUMENT_TYPE_NODE) { | 11 if (point[0].nodeType == Node.DOCUMENT_TYPE_NODE) { |
| 12 assert_throws("INVALID_NODE_TYPE_ERR", function() { | 12 assert_throws("INVALID_NODE_TYPE_ERR", function() { |
| 13 selection.collapse(point[0], point[1]); | 13 selection.collapse(point[0], point[1]); |
| 14 }, "Must throw INVALID_NODE_TYPE_ERR when collapse()ing if the node is a
DocumentType"); | 14 }, "Must throw INVALID_NODE_TYPE_ERR when collapse()ing if the node is a
DocumentType"); |
| 15 return; | 15 return; |
| 16 } | 16 } |
| 17 | 17 |
| 18 if (point[1] < 0 || point[1] > getNodeLength(point[0])) { | 18 if (point[1] < 0 || point[1] > getNodeLength(point[0])) { |
| 19 assert_throws("INDEX_SIZE_ERR", function() { | 19 assert_throws("INDEX_SIZE_ERR", function() { |
| 20 selection.collapse(point[0], point[1]); | 20 selection.collapse(point[0], point[1]); |
| 21 }, "Must throw INDEX_SIZE_ERR when collapse()ing if the offset is negati
ve or greater than the node's length"); | 21 }, "Must throw INDEX_SIZE_ERR when collapse()ing if the offset is negati
ve or greater than the node's length"); |
| 22 return; | 22 return; |
| 23 } | 23 } |
| 24 | 24 |
| 25 if (!document.contains(point[0])) { |
| 26 assertSelectionNoChange(function() { |
| 27 selection.collapse(point[0], point[1]); |
| 28 }); |
| 29 return; |
| 30 } |
| 31 |
| 25 selection.collapse(point[0], point[1]); | 32 selection.collapse(point[0], point[1]); |
| 26 | 33 |
| 27 assert_equals(selection.rangeCount, 1, | 34 assert_equals(selection.rangeCount, 1, |
| 28 "selection.rangeCount must equal 1 after collapse()"); | 35 "selection.rangeCount must equal 1 after collapse()"); |
| 29 assert_equals(selection.focusNode, point[0], | 36 assert_equals(selection.focusNode, point[0], |
| 30 "focusNode must equal the node we collapse()d to"); | 37 "focusNode must equal the node we collapse()d to"); |
| 31 assert_equals(selection.focusOffset, point[1], | 38 assert_equals(selection.focusOffset, point[1], |
| 32 "focusOffset must equal the offset we collapse()d to"); | 39 "focusOffset must equal the offset we collapse()d to"); |
| 33 assert_equals(selection.focusNode, selection.anchorNode, | 40 assert_equals(selection.focusNode, selection.anchorNode, |
| 34 "focusNode and anchorNode must be equal after collapse()"); | 41 "focusNode and anchorNode must be equal after collapse()"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 91 } |
| 85 }, "Set up range " + i + " " + testRanges[i]); | 92 }, "Set up range " + i + " " + testRanges[i]); |
| 86 for (var j = 0; j < testPoints.length; j++) { | 93 for (var j = 0; j < testPoints.length; j++) { |
| 87 tests.push(["Range " + i + " " + testRanges[i] + ", point " + j + "
" + testPoints[j], range, testPointsCached[j]]); | 94 tests.push(["Range " + i + " " + testRanges[i] + ", point " + j + "
" + testPoints[j], range, testPointsCached[j]]); |
| 88 } | 95 } |
| 89 } | 96 } |
| 90 | 97 |
| 91 generate_tests(testCollapse, tests); | 98 generate_tests(testCollapse, tests); |
| 92 } | 99 } |
| 93 | 100 |
| OLD | NEW |