dom/imptests/editing/selecttest/test_selectAllChildren.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:de108c9e264c
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 InvalidNodeTypeError");
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 number of children");
44 if (originalRange) {
45 assert_not_equals(getSelection().getRangeAt(0), originalRange,
46 "selectAllChildren must replace any existing range, not mutate it");
47 }
48 }, "Range " + i + " " + testRanges[i] + ", node " + j + " " + testNodes[j]);
49 }
50 }
51
52 testDiv.style.display = "none";
53 </script>

mercurial