Bug 1261002 - Part 2: Add a testcase for Node.isConnected. r=smaug
authorHoPang Hsu <hopang.hsu@gmail.com>
Fri, 20 May 2016 16:31:29 +0800
changeset 337907 1cc416ae06a0779e7f5069644e4d4c06a5cf0855
parent 337906 a5aea694837ade56d7686f74dbd0ad60b13b1cce
child 337908 8b76fb7a3e31a946f1de76d8e3aa9c222790600e
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1261002
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1261002 - Part 2: Add a testcase for Node.isConnected. r=smaug
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/dom/interfaces.html.ini
testing/web-platform/tests/dom/nodes/Node-isConnected.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -14707,16 +14707,20 @@
         "path": "dom/nodes/Node-isEqualNode.html",
         "url": "/dom/nodes/Node-isEqualNode.html"
       },
       {
         "path": "dom/nodes/Node-isSameNode.html",
         "url": "/dom/nodes/Node-isSameNode.html"
       },
       {
+        "path": "dom/nodes/Node-isConnected.html",
+        "url": "/dom/nodes/Node-isConnected.html"
+      },
+      {
         "path": "dom/nodes/Node-lookupNamespaceURI.html",
         "url": "/dom/nodes/Node-lookupNamespaceURI.html"
       },
       {
         "path": "dom/nodes/Node-lookupPrefix.xhtml",
         "url": "/dom/nodes/Node-lookupPrefix.xhtml"
       },
       {
--- a/testing/web-platform/meta/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/dom/interfaces.html.ini
@@ -104,31 +104,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "queryAll" with the proper type (36)]
     expected: FAIL
 
   [Document interface: calling queryAll(DOMString) on new Document() with too few arguments must throw TypeError]
     expected: FAIL
 
-  [Node interface: attribute isConnected]
-    expected: FAIL
-
-  [Node interface: new Document() must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
-  [Node interface: xmlDoc must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
-  [Node interface: document.doctype must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
-  [Node interface: document.createDocumentFragment() must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
   [ShadowRoot interface: attribute mode]
     expected: FAIL
 
   [Element interface: attribute slot]
     expected: FAIL
 
   [Element interface: operation attachShadow(ShadowRootInit)]
     expected: FAIL
@@ -143,29 +128,16 @@
     expected: FAIL
 
   [Element interface: calling attachShadow(ShadowRootInit) on element with too few arguments must throw TypeError]
     expected: FAIL
 
   [Element interface: element must inherit property "assignedSlot" with the proper type (48)]
     expected: FAIL
 
-  [Node interface: element must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
   [Attr interface: attribute nodeName]
     expected: FAIL
 
   [Text interface: attribute assignedSlot]
     expected: FAIL
 
   [Text interface: document.createTextNode("abc") must inherit property "assignedSlot" with the proper type (2)]
     expected: FAIL
-
-  [Node interface: document.createTextNode("abc") must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
-  [Node interface: xmlDoc.createProcessingInstruction("abc", "def") must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
-  [Node interface: document.createComment("abc") must inherit property "isConnected" with the proper type (15)]
-    expected: FAIL
-
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/nodes/Node-isConnected.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<head>
+<title>Node.prototype.isConnected</title>
+<link rel=help href="https://dom.spec.whatwg.org/#dom-node-isconnected">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+
+"use strict";
+
+test(function() {
+  var nodes = [document.createElement("div"),
+               document.createElement("div"),
+               document.createElement("div")];
+  checkNodes([], nodes);
+
+  // Append nodes[0].
+  document.body.appendChild(nodes[0]);
+  checkNodes([nodes[0]],
+             [nodes[1], nodes[2]]);
+
+  // Append nodes[1] and nodes[2] together.
+  nodes[1].appendChild(nodes[2]);
+  checkNodes([nodes[0]],
+             [nodes[1], nodes[2]]);
+
+  nodes[0].appendChild(nodes[1]);
+  checkNodes(nodes, []);
+
+  // Remove nodes[2].
+  nodes[2].remove();
+  checkNodes([nodes[0], nodes[1]],
+             [nodes[2]]);
+
+  // Remove nodes[0] and nodes[1] together.
+  nodes[0].remove();
+  checkNodes([], nodes);
+}, "Test with ordinary child nodes");
+
+test(function() {
+  var nodes = [document.createElement("iframe"),
+               document.createElement("iframe"),
+               document.createElement("iframe"),
+               document.createElement("iframe"),
+               document.createElement("div")];
+  var frames = [nodes[0],
+                nodes[1],
+                nodes[2],
+                nodes[3]];
+  checkNodes([], nodes);
+
+  // Since we cannot append anything to the contentWindow of an iframe before it
+  // is appended to the main DOM tree, we append the iframes one after another.
+  document.body.appendChild(nodes[0]);
+  checkNodes([nodes[0]],
+             [nodes[1], nodes[2], nodes[3], nodes[4]]);
+
+  frames[0].contentDocument.body.appendChild(nodes[1]);
+  checkNodes([nodes[0], nodes[1]],
+             [nodes[2], nodes[3], nodes[4]]);
+
+  frames[1].contentDocument.body.appendChild(nodes[2]);
+  checkNodes([nodes[0], nodes[1], nodes[2]],
+             [nodes[3], nodes[4]]);
+
+  frames[2].contentDocument.body.appendChild(nodes[3]);
+  checkNodes([nodes[0], nodes[1], nodes[2], nodes[3]],
+             [nodes[4]]);
+
+  frames[3].contentDocument.body.appendChild(nodes[4]);
+  checkNodes(nodes, []);
+
+  frames[3].remove();
+  // Since node[4] is still under the doument of frame[3], it's still connected.
+  checkNodes([nodes[0], nodes[1], nodes[2], nodes[4]],
+             [nodes[3]]);
+
+  frames[0].remove();
+  // Since node[1] and node[2] are still under the doument of frame[0], they are
+  // still connected.
+  checkNodes([nodes[1], nodes[2], nodes[4]],
+             [nodes[0], nodes[3]]);
+}, "Test with iframes");
+
+// This helper function is used to check whether nodes should be connected.
+function checkNodes(aConnectedNodes, aDisconnectedNodes) {
+  aConnectedNodes.forEach(node => assert_true(node.isConnected));
+  aDisconnectedNodes.forEach(node => assert_false(node.isConnected));
+}
+
+</script>
+</body>