dom/imptests/editing/selecttest/test_selectAllChildren.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/imptests/editing/selecttest/test_selectAllChildren.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +<!doctype html>
     1.5 +<title>Selection.selectAllChildren tests</title>
     1.6 +<div id=log></div>
     1.7 +<script src=/resources/testharness.js></script>
     1.8 +<script src=/resources/testharnessreport.js></script>
     1.9 +<script src=common.js></script>
    1.10 +<script>
    1.11 +"use strict";
    1.12 +
    1.13 +testRanges.unshift("[]");
    1.14 +
    1.15 +for (var i = 0; i < testRanges.length; i++) {
    1.16 +	var endpoints = eval(testRanges[i]);
    1.17 +
    1.18 +	for (var j = 0; j < testNodes.length; j++) {
    1.19 +		var node = eval(testNodes[j]);
    1.20 +
    1.21 +		test(function() {
    1.22 +			setSelectionForwards(endpoints);
    1.23 +			var originalRange = getSelection().rangeCount
    1.24 +				? getSelection().getRangeAt(0)
    1.25 +				: null;
    1.26 +
    1.27 +			if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
    1.28 +				assert_throws("INVALID_NODE_TYPE_ERR", function() {
    1.29 +					selection.selectAllChildren(node);
    1.30 +				}, "selectAllChildren() on a DocumentType must throw InvalidNodeTypeError");
    1.31 +				return;
    1.32 +			}
    1.33 +
    1.34 +			selection.selectAllChildren(node);
    1.35 +			// This implicitly tests that the selection is forwards, by using
    1.36 +			// anchorOffset/focusOffset instead of getRangeAt.
    1.37 +			assert_equals(selection.rangeCount, 1,
    1.38 +				"After selectAllChildren, rangeCount must be 1");
    1.39 +			assert_equals(selection.anchorNode, node,
    1.40 +				"After selectAllChildren, anchorNode must be the given node");
    1.41 +			assert_equals(selection.anchorOffset, 0,
    1.42 +				"After selectAllChildren, anchorOffset must be 0");
    1.43 +			assert_equals(selection.focusNode, node,
    1.44 +				"After selectAllChildren, focusNode must be the given node");
    1.45 +			assert_equals(selection.focusOffset, node.childNodes.length,
    1.46 +				"After selectAllChildren, focusOffset must be the given node's number of children");
    1.47 +			if (originalRange) {
    1.48 +				assert_not_equals(getSelection().getRangeAt(0), originalRange,
    1.49 +					"selectAllChildren must replace any existing range, not mutate it");
    1.50 +			}
    1.51 +		}, "Range " + i + " " + testRanges[i] + ", node " + j + " " + testNodes[j]);
    1.52 +	}
    1.53 +}
    1.54 +
    1.55 +testDiv.style.display = "none";
    1.56 +</script>

mercurial