blob: 6ddccc66f225d4b6b2a1362e5e0c06a3ddf622d0 [file] [log] [blame]
tkent55c82392017-02-24 22:50:131<!DOCTYPE html>
2<title>Selection.removeRange tests</title>
3<body>
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
10testRanges.forEach(function(rangeData, index) {
11 var endpoints = eval(rangeData);
12 if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2]))
13 return;
14 test(function() {
15 var selection = getSelection();
16 selection.removeAllRanges();
17 var range = ownerDocument(endpoints[0]).createRange();
18 range.setStart(endpoints[0], endpoints[1]);
19 range.setEnd(endpoints[2], endpoints[3]);
20
21 selection.addRange(range);
22 assert_equals(selection.rangeCount, 1);
23 selection.removeRange(range);
24 assert_equals(selection.rangeCount, 0, 'Range should be correctly removed.');
25 assert_equals(selection.anchorNode, null);
26 assert_equals(selection.focusNode, null);
27
28 selection.addRange(range);
29 assert_equals(selection.rangeCount, 1);
30 var equivalentRange = ownerDocument(endpoints[0]).createRange();
31 equivalentRange.setStart(endpoints[0], endpoints[1]);
32 equivalentRange.setEnd(endpoints[2], endpoints[3]);
Aryeh Gregor1dcb7f12017-04-25 18:37:1933 assert_throws("NotFoundError",
34 function() { selection.removeRange(equivalentRange) },
35 "Removing a different range should throw");
tkent55c82392017-02-24 22:50:1336 assert_equals(selection.rangeCount, 1, 'Equivalent Range should not remove the registered Range.');
37
38 }, 'removeRange() with Range ' + index);
39});
40
41test(function() {
42 var selection = getSelection();
43 assert_throws(new TypeError(), function() { selection.removeRange(null); });
44 assert_throws(new TypeError(), function() { selection.removeRange(selection); });
45}, 'removeRange() argument is non-optional Range');
46</script>
47</body>