| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <title>Selection.collapseTo(Start|End)() tests</title> | 2 <title>Selection.collapseTo(Start|End)() tests</title> |
| 3 <div id=log></div> | 3 <div id=log></div> |
| 4 <script src=/resources/testharness.js></script> | 4 <script src=/resources/testharness.js></script> |
| 5 <script src=/resources/testharnessreport.js></script> | 5 <script src=/resources/testharnessreport.js></script> |
| 6 <script src=common.js></script> | 6 <script src=common.js></script> |
| 7 <script> | 7 <script> |
| 8 "use strict"; | 8 "use strict"; |
| 9 | 9 |
| 10 // Also test a selection with no ranges | 10 test(function() { |
| 11 testRanges.unshift("[]"); | 11 selection.removeAllRanges(); |
| 12 assert_throws("INVALID_STATE_ERR", function() { |
| 13 selection.collapseToStart(); |
| 14 }); |
| 15 }, "Must throw InvalidStateErr if the selection's range is null"); |
| 12 | 16 |
| 13 for (var i = 0; i < testRanges.length; i++) { | 17 for (var i = 0; i < testRanges.length; i++) { |
| 18 var endpoints = eval(testRanges[i]); |
| 19 if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2])) |
| 20 continue; |
| 14 test(function() { | 21 test(function() { |
| 15 selection.removeAllRanges(); | 22 selection.removeAllRanges(); |
| 16 var endpoints = eval(testRanges[i]); | |
| 17 if (!endpoints.length) { | |
| 18 assert_throws("INVALID_STATE_ERR", function() { | |
| 19 selection.collapseToStart(); | |
| 20 }, "Must throw InvalidStateErr if the selection's range is null"); | |
| 21 return; | |
| 22 } | |
| 23 | 23 |
| 24 var addedRange = ownerDocument(endpoints[0]).createRange(); | 24 var addedRange = ownerDocument(endpoints[0]).createRange(); |
| 25 addedRange.setStart(endpoints[0], endpoints[1]); | 25 addedRange.setStart(endpoints[0], endpoints[1]); |
| 26 addedRange.setEnd(endpoints[2], endpoints[3]); | 26 addedRange.setEnd(endpoints[2], endpoints[3]); |
| 27 selection.addRange(addedRange); | 27 selection.addRange(addedRange); |
| 28 | 28 |
| 29 // We don't penalize browsers here for mishandling addRange() and | 29 // We don't penalize browsers here for mishandling addRange() and |
| 30 // adding a different range than we specified. They fail addRange() | 30 // adding a different range than we specified. They fail addRange() |
| 31 // tests for that, and don't have to fail collapseToStart/End() tests | 31 // tests for that, and don't have to fail collapseToStart/End() tests |
| 32 // too. They do fail if they throw unexpectedly, though. I also fail | 32 // too. They do fail if they throw unexpectedly, though. I also fail |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 "collapseToStart() must not change the startOffset of the selection'
s original range"); | 59 "collapseToStart() must not change the startOffset of the selection'
s original range"); |
| 60 assert_equals(addedRange.endContainer, endpoints[2], | 60 assert_equals(addedRange.endContainer, endpoints[2], |
| 61 "collapseToStart() must not change the endContainer of the selection
's original range"); | 61 "collapseToStart() must not change the endContainer of the selection
's original range"); |
| 62 assert_equals(addedRange.endOffset, endpoints[3], | 62 assert_equals(addedRange.endOffset, endpoints[3], |
| 63 "collapseToStart() must not change the endOffset of the selection's
original range"); | 63 "collapseToStart() must not change the endOffset of the selection's
original range"); |
| 64 }, "Range " + i + " " + testRanges[i] + " collapseToStart()"); | 64 }, "Range " + i + " " + testRanges[i] + " collapseToStart()"); |
| 65 | 65 |
| 66 // Copy-paste of above | 66 // Copy-paste of above |
| 67 test(function() { | 67 test(function() { |
| 68 selection.removeAllRanges(); | 68 selection.removeAllRanges(); |
| 69 var endpoints = eval(testRanges[i]); | |
| 70 if (!endpoints.length) { | |
| 71 assert_throws("INVALID_STATE_ERR", function() { | |
| 72 selection.collapseToEnd(); | |
| 73 }, "Must throw InvalidStateErr if the selection's range is null"); | |
| 74 return; | |
| 75 } | |
| 76 | 69 |
| 77 var addedRange = ownerDocument(endpoints[0]).createRange(); | 70 var addedRange = ownerDocument(endpoints[0]).createRange(); |
| 78 addedRange.setStart(endpoints[0], endpoints[1]); | 71 addedRange.setStart(endpoints[0], endpoints[1]); |
| 79 addedRange.setEnd(endpoints[2], endpoints[3]); | 72 addedRange.setEnd(endpoints[2], endpoints[3]); |
| 80 selection.addRange(addedRange); | 73 selection.addRange(addedRange); |
| 81 | 74 |
| 82 // We don't penalize browsers here for mishandling addRange() and | 75 // We don't penalize browsers here for mishandling addRange() and |
| 83 // adding a different range than we specified. They fail addRange() | 76 // adding a different range than we specified. They fail addRange() |
| 84 // tests for that, and don't have to fail collapseToStart/End() tests | 77 // tests for that, and don't have to fail collapseToStart/End() tests |
| 85 // too. They do fail if they throw unexpectedly, though. I also fail | 78 // too. They do fail if they throw unexpectedly, though. I also fail |
| (...skipping 26 matching lines...) Expand all Loading... |
| 112 "collapseToEnd() must not change the startOffset of the selection's
original range"); | 105 "collapseToEnd() must not change the startOffset of the selection's
original range"); |
| 113 assert_equals(addedRange.endContainer, endpoints[2], | 106 assert_equals(addedRange.endContainer, endpoints[2], |
| 114 "collapseToEnd() must not change the endContainer of the selection's
original range"); | 107 "collapseToEnd() must not change the endContainer of the selection's
original range"); |
| 115 assert_equals(addedRange.endOffset, endpoints[3], | 108 assert_equals(addedRange.endOffset, endpoints[3], |
| 116 "collapseToEnd() must not change the endOffset of the selection's or
iginal range"); | 109 "collapseToEnd() must not change the endOffset of the selection's or
iginal range"); |
| 117 }, "Range " + i + " " + testRanges[i] + " collapseToEnd()"); | 110 }, "Range " + i + " " + testRanges[i] + " collapseToEnd()"); |
| 118 } | 111 } |
| 119 | 112 |
| 120 testDiv.style.display = "none"; | 113 testDiv.style.display = "none"; |
| 121 </script> | 114 </script> |
| OLD | NEW |