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