blob: 65a4ff3c6c58768b259bb637a52ef28c91c5c313 [file] [log] [blame]
Aryeh Gregor675dd402011-10-24 20:05:381<!doctype html>
2<title>Selection.selectAllChildren tests</title>
tkent0fd74da2017-02-14 10:00:143<meta name="timeout" content="long">
Aryeh Gregor675dd402011-10-24 20:05:384<div id=log></div>
Aryeh Gregor33fcf012015-08-09 12:21:105<script src=/resources/testharness.js></script>
6<script src=/resources/testharnessreport.js></script>
Aryeh Gregor675dd402011-10-24 20:05:387<script src=common.js></script>
8<script>
9"use strict";
10
Aryeh Gregor9ecb0222012-01-12 19:02:2611testRanges.unshift("[]");
Aryeh Gregor675dd402011-10-24 20:05:3812
Aryeh Gregor9ecb0222012-01-12 19:02:2613for (var i = 0; i < testRanges.length; i++) {
Aryeh Gregor01a11722015-08-09 13:04:2514 var endpoints = eval(testRanges[i]);
Aryeh Gregor675dd402011-10-24 20:05:3815
Aryeh Gregor01a11722015-08-09 13:04:2516 for (var j = 0; j < testNodes.length; j++) {
17 var node = eval(testNodes[j]);
Aryeh Gregor675dd402011-10-24 20:05:3818
Aryeh Gregor01a11722015-08-09 13:04:2519 test(function() {
20 setSelectionForwards(endpoints);
21 var originalRange = getSelection().rangeCount
22 ? getSelection().getRangeAt(0)
23 : null;
Aryeh Gregor675dd402011-10-24 20:05:3824
Aryeh Gregor01a11722015-08-09 13:04:2525 if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
26 assert_throws("INVALID_NODE_TYPE_ERR", function() {
27 selection.selectAllChildren(node);
28 }, "selectAllChildren() on a DocumentType must throw InvalidNodeTypeError");
29 return;
30 }
Aryeh Gregor9ecb0222012-01-12 19:02:2631
Aryeh Gregor01a11722015-08-09 13:04:2532 selection.selectAllChildren(node);
tkent0fd74da2017-02-14 10:00:1433 if (!document.contains(node)) {
34 if (originalRange) {
35 assert_equals(getSelection().getRangeAt(0), originalRange,
36 "selectAllChildren must do nothing");
37 } else {
38 assert_equals(getSelection().rangeCount, 0,
39 "selectAllChildren must do nothing");
40 }
41 return;
42 }
Aryeh Gregor01a11722015-08-09 13:04:2543 // This implicitly tests that the selection is forwards, by using
44 // anchorOffset/focusOffset instead of getRangeAt.
45 assert_equals(selection.rangeCount, 1,
46 "After selectAllChildren, rangeCount must be 1");
47 assert_equals(selection.anchorNode, node,
48 "After selectAllChildren, anchorNode must be the given node");
49 assert_equals(selection.anchorOffset, 0,
50 "After selectAllChildren, anchorOffset must be 0");
51 assert_equals(selection.focusNode, node,
52 "After selectAllChildren, focusNode must be the given node");
53 assert_equals(selection.focusOffset, node.childNodes.length,
54 "After selectAllChildren, focusOffset must be the given node's number of children");
55 if (originalRange) {
56 assert_not_equals(getSelection().getRangeAt(0), originalRange,
57 "selectAllChildren must replace any existing range, not mutate it");
58 }
59 }, "Range " + i + " " + testRanges[i] + ", node " + j + " " + testNodes[j]);
60 }
Aryeh Gregor675dd402011-10-24 20:05:3861}
62
63testDiv.style.display = "none";
64</script>