Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/ranges/Range-selectNode.html

Issue 1529523002: Import dom/ from web-platform-tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak W3CImportExpectations Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <title>Range.selectNode() and .selectNodeContents() tests</title>
3 <link rel="author" title="Aryeh Gregor" href=ayg@aryeh.name>
4 <meta name=timeout content=long>
5 <div id=log></div>
6 <script src=../../../../resources/testharness.js></script>
7 <script src=../../../../resources/testharnessreport.js></script>
8 <script src=../common.js></script>
9 <script>
10 "use strict";
11
12 function testSelectNode(range, node) {
13 try {
14 range.collapsed;
15 } catch (e) {
16 // Range is detached
17 assert_throws("INVALID_STATE_ERR", function () {
18 range.selectNode(node);
19 }, "selectNode() on a detached node must throw INVALID_STATE_ERR");
20 assert_throws("INVALID_STATE_ERR", function () {
21 range.selectNodeContents(node);
22 }, "selectNodeContents() on a detached node must throw INVALID_STATE_ERR ");
23 return;
24 }
25
26 if (!node.parentNode) {
27 assert_throws("INVALID_NODE_TYPE_ERR", function() {
28 range.selectNode(node);
29 }, "selectNode() on a node with no parent must throw INVALID_NODE_TYPE_E RR");
30 } else {
31 var index = 0;
32 while (node.parentNode.childNodes[index] != node) {
33 index++;
34 }
35
36 range.selectNode(node);
37 assert_equals(range.startContainer, node.parentNode,
38 "After selectNode(), startContainer must equal parent node");
39 assert_equals(range.endContainer, node.parentNode,
40 "After selectNode(), endContainer must equal parent node");
41 assert_equals(range.startOffset, index,
42 "After selectNode(), startOffset must be index of node in parent (" + index + ")");
43 assert_equals(range.endOffset, index + 1,
44 "After selectNode(), endOffset must be one plus index of node in par ent (" + (index + 1) + ")");
45 }
46
47 if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
48 assert_throws("INVALID_NODE_TYPE_ERR", function () {
49 range.selectNodeContents(node);
50 }, "selectNodeContents() on a doctype must throw INVALID_NODE_TYPE_ERR") ;
51 } else {
52 range.selectNodeContents(node);
53 assert_equals(range.startContainer, node,
54 "After selectNodeContents(), startContainer must equal node");
55 assert_equals(range.endContainer, node,
56 "After selectNodeContents(), endContainer must equal node");
57 assert_equals(range.startOffset, 0,
58 "After selectNodeContents(), startOffset must equal 0");
59 var len = nodeLength(node);
60 assert_equals(range.endOffset, len,
61 "After selectNodeContents(), endOffset must equal node length (" + l en + ")");
62 }
63 }
64
65 var range = document.createRange();
66 var foreignRange = foreignDoc.createRange();
67 var xmlRange = xmlDoc.createRange();
68 var detachedRange = document.createRange();
69 detachedRange.detach();
70 var tests = [];
71 function testTree(root, marker) {
72 if (root.nodeType == Node.ELEMENT_NODE && root.id == "log") {
73 // This is being modified during the tests, so let's not test it.
74 return;
75 }
76 tests.push([marker + root.nodeName.toLowerCase() + " node, current doc's ran ge, type " + root.nodeType, range, root]);
77 tests.push([marker + root.nodeName.toLowerCase() + " node, foreign doc's ran ge, type " + root.nodeType, foreignRange, root]);
78 tests.push([marker + root.nodeName.toLowerCase() + " node, XML doc's range, type " + root.nodeType, xmlRange, root]);
79 tests.push([marker + root.nodeName.toLowerCase() + " node, detached range, t ype " + root.nodeType, detachedRange, root]);
80 for (var i = 0; i < root.childNodes.length; i++) {
81 testTree(root.childNodes[i], "**" + marker);
82 }
83 }
84 testTree(document, " current doc: ");
85 testTree(foreignDoc, " foreign doc: ");
86 testTree(detachedDiv, " detached div in current doc: ");
87
88 var otherTests = [xmlDoc, xmlElement, detachedTextNode, foreignTextNode,
89 xmlTextNode, processingInstruction, comment, foreignComment, xmlComment,
90 docfrag, foreignDocfrag, xmlDocfrag];
91
92 for (var i = 0; i < otherTests.length; i++) {
93 testTree(otherTests[i], " ");
94 }
95
96 generate_tests(testSelectNode, tests);
97
98 testDiv.style.display = "none";
99 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698