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

Unified Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/Node-compareDocumentPosition.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/nodes/Node-compareDocumentPosition.html
diff --git a/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/Node-compareDocumentPosition.html b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/Node-compareDocumentPosition.html
new file mode 100644
index 0000000000000000000000000000000000000000..7ac02c6f10072c4c7a8d407513a93d4673ee8b6a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/web-platform-tests/dom/nodes/Node-compareDocumentPosition.html
@@ -0,0 +1,87 @@
+<!doctype html>
+<title>Node.compareDocumentPosition() tests</title>
+<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
+<div id=log></div>
+<script src=../../../../resources/testharness.js></script>
+<script src=../../../../resources/testharnessreport.js></script>
+<script src=../common.js></script>
+<script>
+"use strict";
+
+testNodes.forEach(function(referenceName) {
+ var reference = eval(referenceName);
+ testNodes.forEach(function(otherName) {
+ var other = eval(otherName);
+ test(function() {
+ var result = reference.compareDocumentPosition(other);
+
+ // "If other and reference are the same object, return zero and
+ // terminate these steps."
+ if (other === reference) {
+ assert_equals(result, 0);
+ return;
+ }
+
+ // "If other and reference are not in the same tree, return the result of
+ // adding DOCUMENT_POSITION_DISCONNECTED,
+ // DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, and either
+ // DOCUMENT_POSITION_PRECEDING or DOCUMENT_POSITION_FOLLOWING, with the
+ // constraint that this is to be consistent, together and terminate these
+ // steps."
+ if (furthestAncestor(reference) !== furthestAncestor(other)) {
+ // TODO: Test that it's consistent.
+ assert_in_array(result, [Node.DOCUMENT_POSITION_DISCONNECTED +
+ Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
+ Node.DOCUMENT_POSITION_PRECEDING,
+ Node.DOCUMENT_POSITION_DISCONNECTED +
+ Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
+ Node.DOCUMENT_POSITION_FOLLOWING]);
+ return;
+ }
+
+ // "If other is an ancestor of reference, return the result of
+ // adding DOCUMENT_POSITION_CONTAINS to DOCUMENT_POSITION_PRECEDING
+ // and terminate these steps."
+ var ancestor = reference.parentNode;
+ while (ancestor && ancestor !== other) {
+ ancestor = ancestor.parentNode;
+ }
+ if (ancestor === other) {
+ assert_equals(result, Node.DOCUMENT_POSITION_CONTAINS +
+ Node.DOCUMENT_POSITION_PRECEDING);
+ return;
+ }
+
+ // "If other is a descendant of reference, return the result of adding
+ // DOCUMENT_POSITION_CONTAINED_BY to DOCUMENT_POSITION_FOLLOWING and
+ // terminate these steps."
+ ancestor = other.parentNode;
+ while (ancestor && ancestor !== reference) {
+ ancestor = ancestor.parentNode;
+ }
+ if (ancestor === reference) {
+ assert_equals(result, Node.DOCUMENT_POSITION_CONTAINED_BY +
+ Node.DOCUMENT_POSITION_FOLLOWING);
+ return;
+ }
+
+ // "If other is preceding reference return DOCUMENT_POSITION_PRECEDING
+ // and terminate these steps."
+ var prev = previousNode(reference);
+ while (prev && prev !== other) {
+ prev = previousNode(prev);
+ }
+ if (prev === other) {
+ assert_equals(result, Node.DOCUMENT_POSITION_PRECEDING);
+ return;
+ }
+
+ // "Return DOCUMENT_POSITION_FOLLOWING."
+ assert_equals(result, Node.DOCUMENT_POSITION_FOLLOWING);
+ }, referenceName + ".compareDocumentPosition(" + otherName + ")");
+ });
+});
+
+testDiv.parentNode.removeChild(testDiv);
+</script>
+<!-- vim: set expandtab tabstop=2 shiftwidth=2: -->

Powered by Google App Engine
This is Rietveld 408576698