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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/ranges/Range-selectNode.html
diff --git a/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/ranges/Range-selectNode.html b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/ranges/Range-selectNode.html
new file mode 100644
index 0000000000000000000000000000000000000000..0fbb857df3488091b757e3e17dada501bb9dfaba
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/ranges/Range-selectNode.html
@@ -0,0 +1,99 @@
+<!doctype html>
+<title>Range.selectNode() and .selectNodeContents() tests</title>
+<link rel="author" title="Aryeh Gregor" href=ayg@aryeh.name>
+<meta name=timeout content=long>
+<div id=log></div>
+<script src=../../../../resources/testharness.js></script>
+<script src=../../../../resources/testharnessreport.js></script>
+<script src=../common.js></script>
+<script>
+"use strict";
+
+function testSelectNode(range, node) {
+ try {
+ range.collapsed;
+ } catch (e) {
+ // Range is detached
+ assert_throws("INVALID_STATE_ERR", function () {
+ range.selectNode(node);
+ }, "selectNode() on a detached node must throw INVALID_STATE_ERR");
+ assert_throws("INVALID_STATE_ERR", function () {
+ range.selectNodeContents(node);
+ }, "selectNodeContents() on a detached node must throw INVALID_STATE_ERR");
+ return;
+ }
+
+ if (!node.parentNode) {
+ assert_throws("INVALID_NODE_TYPE_ERR", function() {
+ range.selectNode(node);
+ }, "selectNode() on a node with no parent must throw INVALID_NODE_TYPE_ERR");
+ } else {
+ var index = 0;
+ while (node.parentNode.childNodes[index] != node) {
+ index++;
+ }
+
+ range.selectNode(node);
+ assert_equals(range.startContainer, node.parentNode,
+ "After selectNode(), startContainer must equal parent node");
+ assert_equals(range.endContainer, node.parentNode,
+ "After selectNode(), endContainer must equal parent node");
+ assert_equals(range.startOffset, index,
+ "After selectNode(), startOffset must be index of node in parent (" + index + ")");
+ assert_equals(range.endOffset, index + 1,
+ "After selectNode(), endOffset must be one plus index of node in parent (" + (index + 1) + ")");
+ }
+
+ if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
+ assert_throws("INVALID_NODE_TYPE_ERR", function () {
+ range.selectNodeContents(node);
+ }, "selectNodeContents() on a doctype must throw INVALID_NODE_TYPE_ERR");
+ } else {
+ range.selectNodeContents(node);
+ assert_equals(range.startContainer, node,
+ "After selectNodeContents(), startContainer must equal node");
+ assert_equals(range.endContainer, node,
+ "After selectNodeContents(), endContainer must equal node");
+ assert_equals(range.startOffset, 0,
+ "After selectNodeContents(), startOffset must equal 0");
+ var len = nodeLength(node);
+ assert_equals(range.endOffset, len,
+ "After selectNodeContents(), endOffset must equal node length (" + len + ")");
+ }
+}
+
+var range = document.createRange();
+var foreignRange = foreignDoc.createRange();
+var xmlRange = xmlDoc.createRange();
+var detachedRange = document.createRange();
+detachedRange.detach();
+var tests = [];
+function testTree(root, marker) {
+ if (root.nodeType == Node.ELEMENT_NODE && root.id == "log") {
+ // This is being modified during the tests, so let's not test it.
+ return;
+ }
+ tests.push([marker + root.nodeName.toLowerCase() + " node, current doc's range, type " + root.nodeType, range, root]);
+ tests.push([marker + root.nodeName.toLowerCase() + " node, foreign doc's range, type " + root.nodeType, foreignRange, root]);
+ tests.push([marker + root.nodeName.toLowerCase() + " node, XML doc's range, type " + root.nodeType, xmlRange, root]);
+ tests.push([marker + root.nodeName.toLowerCase() + " node, detached range, type " + root.nodeType, detachedRange, root]);
+ for (var i = 0; i < root.childNodes.length; i++) {
+ testTree(root.childNodes[i], "**" + marker);
+ }
+}
+testTree(document, " current doc: ");
+testTree(foreignDoc, " foreign doc: ");
+testTree(detachedDiv, " detached div in current doc: ");
+
+var otherTests = [xmlDoc, xmlElement, detachedTextNode, foreignTextNode,
+xmlTextNode, processingInstruction, comment, foreignComment, xmlComment,
+docfrag, foreignDocfrag, xmlDocfrag];
+
+for (var i = 0; i < otherTests.length; i++) {
+ testTree(otherTests[i], " ");
+}
+
+generate_tests(testSelectNode, tests);
+
+testDiv.style.display = "none";
+</script>

Powered by Google App Engine
This is Rietveld 408576698