OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>Selection.selectAllChildren tests</title> |
| 3 <div id=log></div> |
| 4 <script src=/resources/testharness.js></script> |
| 5 <script src=/resources/testharnessreport.js></script> |
| 6 <script src=common.js></script> |
| 7 <script> |
| 8 "use strict"; |
| 9 |
| 10 testRanges.unshift("[]"); |
| 11 |
| 12 for (var i = 0; i < testRanges.length; i++) { |
| 13 var endpoints = eval(testRanges[i]); |
| 14 |
| 15 for (var j = 0; j < testNodes.length; j++) { |
| 16 var node = eval(testNodes[j]); |
| 17 |
| 18 test(function() { |
| 19 setSelectionForwards(endpoints); |
| 20 var originalRange = getSelection().rangeCount |
| 21 ? getSelection().getRangeAt(0) |
| 22 : null; |
| 23 |
| 24 if (node.nodeType == Node.DOCUMENT_TYPE_NODE) { |
| 25 assert_throws("INVALID_NODE_TYPE_ERR", function() { |
| 26 selection.selectAllChildren(node); |
| 27 }, "selectAllChildren() on a DocumentType must throw InvalidNode
TypeError"); |
| 28 return; |
| 29 } |
| 30 |
| 31 selection.selectAllChildren(node); |
| 32 // This implicitly tests that the selection is forwards, by using |
| 33 // anchorOffset/focusOffset instead of getRangeAt. |
| 34 assert_equals(selection.rangeCount, 1, |
| 35 "After selectAllChildren, rangeCount must be 1"); |
| 36 assert_equals(selection.anchorNode, node, |
| 37 "After selectAllChildren, anchorNode must be the given node"); |
| 38 assert_equals(selection.anchorOffset, 0, |
| 39 "After selectAllChildren, anchorOffset must be 0"); |
| 40 assert_equals(selection.focusNode, node, |
| 41 "After selectAllChildren, focusNode must be the given node"); |
| 42 assert_equals(selection.focusOffset, node.childNodes.length, |
| 43 "After selectAllChildren, focusOffset must be the given node's n
umber of children"); |
| 44 if (originalRange) { |
| 45 assert_not_equals(getSelection().getRangeAt(0), originalRange, |
| 46 "selectAllChildren must replace any existing range, not muta
te it"); |
| 47 } |
| 48 }, "Range " + i + " " + testRanges[i] + ", node " + j + " " + testNodes[
j]); |
| 49 } |
| 50 } |
| 51 |
| 52 testDiv.style.display = "none"; |
| 53 </script> |
OLD | NEW |