Bug 811259 - Patch2: Add web-platform tests for insertAdjacentText and insertAdjacentElement. r=smaug
authorJocelyn Liu <joliu@mozilla.com>
Mon, 28 Mar 2016 18:17:36 +0800
changeset 292286 3d44a2dab529
parent 292285 85d6982a515a
child 292287 cd16e4847afb
push id30154
push usercbook@mozilla.com
push date2016-04-08 10:00 +0000
treeherdermozilla-central@d9b1a9829c8e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs811259
milestone48.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 811259 - Patch2: Add web-platform tests for insertAdjacentText and insertAdjacentElement. r=smaug MozReview-Commit-ID: edMCmc8FrE
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/dom/interfaces.html.ini
testing/web-platform/tests/dom/interfaces.html
testing/web-platform/tests/dom/nodes/Element-insertAdjacentElement.html
testing/web-platform/tests/dom/nodes/Element-insertAdjacentText.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -34906,16 +34906,28 @@
       },
       "testharness": {
         "dom/collections/HTMLCollection-as-proto-length-get-throws.html": [
           {
             "path": "dom/collections/HTMLCollection-as-proto-length-get-throws.html",
             "url": "/dom/collections/HTMLCollection-as-proto-length-get-throws.html"
           }
         ],
+        "dom/nodes/Element-insertAdjacentElement.html": [
+          {
+            "path": "dom/nodes/Element-insertAdjacentElement.html",
+            "url": "/dom/nodes/Element-insertAdjacentElement.html"
+          }
+        ],
+        "dom/nodes/Element-insertAdjacentText.html": [
+          {
+            "path": "dom/nodes/Element-insertAdjacentText.html",
+            "url": "/dom/nodes/Element-insertAdjacentText.html"
+          }
+        ],
         "dom/nodes/remove-unscopable.html": [
           {
             "path": "dom/nodes/remove-unscopable.html",
             "url": "/dom/nodes/remove-unscopable.html"
           }
         ],
         "js/builtins/Promise-incumbent-global.sub.html": [
           {
--- a/testing/web-platform/meta/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/dom/interfaces.html.ini
@@ -286,35 +286,35 @@
     expected: FAIL
 
   [DOMTokenList interface: document.body.classList must inherit property "supports" with the proper type (7)]
     expected: FAIL
 
   [DOMTokenList interface: calling supports(DOMString) on document.body.classList with too few arguments must throw TypeError]
     expected: FAIL
 
-  [Element interface: element must inherit property "prepend" with the proper type (32)]
+  [Element interface: element must inherit property "prepend" with the proper type (34)]
     expected: FAIL
 
-  [Element interface: element must inherit property "append" with the proper type (33)]
+  [Element interface: element must inherit property "append" with the proper type (35)]
     expected: FAIL
 
-  [Element interface: element must inherit property "query" with the proper type (34)]
+  [Element interface: element must inherit property "query" with the proper type (36)]
     expected: FAIL
 
-  [Element interface: element must inherit property "queryAll" with the proper type (35)]
+  [Element interface: element must inherit property "queryAll" with the proper type (37)]
     expected: FAIL
 
-  [Element interface: element must inherit property "before" with the proper type (40)]
+  [Element interface: element must inherit property "before" with the proper type (42)]
     expected: FAIL
 
-  [Element interface: element must inherit property "after" with the proper type (41)]
+  [Element interface: element must inherit property "after" with the proper type (43)]
     expected: FAIL
 
-  [Element interface: element must inherit property "replaceWith" with the proper type (42)]
+  [Element interface: element must inherit property "replaceWith" with the proper type (44)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "origin" with the proper type (3)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "prepend" with the proper type (33)]
     expected: FAIL
 
--- a/testing/web-platform/tests/dom/interfaces.html
+++ b/testing/web-platform/tests/dom/interfaces.html
@@ -305,16 +305,19 @@ interface Element : Node {
   Attr removeAttributeNode(Attr attr);
 
   Element? closest(DOMString selectors);
   boolean matches(DOMString selectors);
 
   HTMLCollection getElementsByTagName(DOMString localName);
   HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
   HTMLCollection getElementsByClassName(DOMString classNames);
+
+  Element? insertAdjacentElement(DOMString where, Element element); // historical
+  void insertAdjacentText(DOMString where, DOMString data); // historical
 };
 
 interface NamedNodeMap {
   readonly attribute unsigned long length;
   getter Attr? item(unsigned long index);
   getter Attr? getNamedItem(DOMString name);
   Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
   Attr? setNamedItem(Attr attr);
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/nodes/Element-insertAdjacentElement.html
@@ -0,0 +1,91 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+
+<div id="target"></div>
+<div id="parent"><span id=target2></span></div>
+<div id="log" style="visibility:visible"></div>
+<span id="test1"></span>
+<span id="test2"></span>
+<span id="test3"></span>
+<span id="test4"></span>
+<script>
+var target = document.getElementById("target");
+var target2 = document.getElementById("target2");
+
+test(function() {
+  assert_throws("SyntaxError", function() {
+    target.insertAdjacentElement("test", document.getElementById("test1"))
+  });
+
+  assert_throws("SyntaxError", function() {
+    target2.insertAdjacentElement("test", document.getElementById("test1"))
+  });
+}, "Inserting to an invalid location should cause a Syntax Error exception")
+
+test(function() {
+  var el = target.insertAdjacentElement("beforebegin", document.getElementById("test1"));
+  assert_equals(target.previousSibling.id, "test1");
+  assert_equals(el.id, "test1");
+
+  el = target2.insertAdjacentElement("beforebegin", document.getElementById("test1"));
+  assert_equals(target2.previousSibling.id, "test1");
+  assert_equals(el.id, "test1");
+}, "Inserted element should be target element's previous sibling for 'beforebegin' case")
+
+test(function() {
+  var el = target.insertAdjacentElement("afterbegin", document.getElementById("test2"));
+  assert_equals(target.firstChild.id, "test2");
+  assert_equals(el.id, "test2");
+
+  el = target2.insertAdjacentElement("afterbegin", document.getElementById("test2"));
+  assert_equals(target2.firstChild.id, "test2");
+  assert_equals(el.id, "test2");
+}, "Inserted element should be target element's first child for 'afterbegin' case")
+
+test(function() {
+  var el = target.insertAdjacentElement("beforeend", document.getElementById("test3"));
+  assert_equals(target.lastChild.id, "test3");
+  assert_equals(el.id, "test3");
+
+  el = target2.insertAdjacentElement("beforeend", document.getElementById("test3"));
+  assert_equals(target2.lastChild.id, "test3");
+  assert_equals(el.id, "test3");
+}, "Inserted element should be target element's last child for 'beforeend' case")
+
+test(function() {
+  var el = target.insertAdjacentElement("afterend", document.getElementById("test4"));
+  assert_equals(target.nextSibling.id, "test4");
+  assert_equals(el.id, "test4");
+
+  el = target2.insertAdjacentElement("afterend", document.getElementById("test4"));
+  assert_equals(target2.nextSibling.id, "test4");
+  assert_equals(el.id, "test4");
+}, "Inserted element should be target element's next sibling for 'afterend' case")
+
+test(function() {
+  var docElement = document.documentElement;
+  docElement.style.visibility="hidden";
+
+  assert_throws("HierarchyRequestError", function() {
+    var el = docElement.insertAdjacentElement("beforebegin", document.getElementById("test1"));
+    assert_equals(el, null);
+  });
+
+  var el = docElement.insertAdjacentElement("afterbegin", document.getElementById("test2"));
+  assert_equals(docElement.firstChild.id, "test2");
+  assert_equals(el.id, "test2");
+
+  el = docElement.insertAdjacentElement("beforeend", document.getElementById("test3"));
+  assert_equals(docElement.lastChild.id, "test3");
+  assert_equals(el.id, "test3");
+
+  assert_throws("HierarchyRequestError", function() {
+    var el = docElement.insertAdjacentElement("afterend", document.getElementById("test4"));
+    assert_equals(el, null);
+  });
+}, "Adding more than one child to document should cause a HierarchyRequestError exception")
+
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/dom/nodes/Element-insertAdjacentText.html
@@ -0,0 +1,76 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<body style="visibility:hidden">
+<div id="target"></div>
+<div id="parent"><span id=target2></span></div>
+<div id="log" style="visibility:visible"></div>
+</body>
+<script>
+var target = document.getElementById("target");
+var target2 = document.getElementById("target2");
+
+test(function() {
+  assert_throws("SyntaxError", function() {
+    target.insertAdjacentText("test", "text")
+  });
+
+  assert_throws("SyntaxError", function() {
+    target2.insertAdjacentText("test", "test")
+  });
+}, "Inserting to an invalid location should cause a Syntax Error exception")
+
+test(function() {
+  target.insertAdjacentText("beforebegin", "test1");
+  assert_equals(target.previousSibling.nodeValue, "test1");
+
+  target2.insertAdjacentText("beforebegin", "test1");
+  assert_equals(target2.previousSibling.nodeValue, "test1");
+}, "Inserted text node should be target element's previous sibling for 'beforebegin' case")
+
+test(function() {
+  target.insertAdjacentText("afterbegin", "test2");
+  assert_equals(target.firstChild.nodeValue, "test2");
+
+  target2.insertAdjacentText("afterbegin", "test2");
+  assert_equals(target2.firstChild.nodeValue, "test2");
+}, "Inserted text node should be target element's first child for 'afterbegin' case")
+
+test(function() {
+  target.insertAdjacentText("beforeend", "test3");
+  assert_equals(target.lastChild.nodeValue, "test3");
+
+  target2.insertAdjacentText("beforeend", "test3");
+  assert_equals(target2.lastChild.nodeValue, "test3");
+}, "Inserted text node should be target element's last child for 'beforeend' case")
+
+test(function() {
+  target.insertAdjacentText("afterend", "test4");
+  assert_equals(target.nextSibling.nodeValue, "test4");
+
+  target2.insertAdjacentText("afterend", "test4");
+  assert_equals(target.nextSibling.nodeValue, "test4");
+}, "Inserted text node should be target element's next sibling for 'afterend' case")
+
+test(function() {
+  var docElement = document.documentElement;
+  docElement.style.visibility="hidden";
+
+  assert_throws("HierarchyRequestError", function() {
+    docElement.insertAdjacentText("beforebegin", "text1")
+  });
+
+  docElement.insertAdjacentText("afterbegin", "test2");
+  assert_equals(docElement.firstChild.nodeValue, "test2");
+
+  docElement.insertAdjacentText("beforeend", "test3");
+  assert_equals(docElement.lastChild.nodeValue, "test3");
+
+  assert_throws("HierarchyRequestError", function() {
+    docElement.insertAdjacentText("afterend", "test4")
+  });
+}, "Adding more than one child to document should cause a HierarchyRequestError exception")
+
+</script>