Bug 1462703 - Additional setElementCreationCallback tests in XUL document draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 23 May 2018 14:13:22 +0800
changeset 800173 b270d34d1765e553b327a74115fdca4f34695b08
parent 800172 0c6d2b62c0237bfeb5e9d98c73b97dd611ff29a8
push id111288
push usertimdream@gmail.com
push dateSat, 26 May 2018 01:57:00 +0000
bugs1462703, 1460815
milestone62.0a1
Bug 1462703 - Additional setElementCreationCallback tests in XUL document These tests ensures the feature interacts well with our setup in XUL. They work when bug 1460815 was implemented so they sits in its own changeset. MozReview-Commit-ID: Ia08tAewZyN
dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
--- a/dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
+++ b/dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
@@ -73,16 +73,21 @@
 
       connectedCallback() {
         this.textContent = "quuz";
       }
     }
     customElements.define("test-popup-extend",
       TestPopupExtendElement, { extends: "popup" });
 
+    class TestCustomElement3 extends XULElement { }
+
+    customElements.setElementCreationCallback(
+      "test-custom-element-3", () => customElements.define("test-custom-element-3", TestCustomElement3));
+
     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
     function basicCustomElementCreate() {
       let element = document.createElementNS(XUL_NS, "test-custom-element");
       document.querySelector("#content").appendChild(element);
       is(element.textContent, "foo", "Should have set the textContent");
       ok(element instanceof TestCustomElement, "Should be an instance of TestCustomElement");
 
@@ -307,23 +312,39 @@
         document.createElementNS(XUL_NS, "test-built-in-element-1")];
 
       for (let element of elements) {
         is(Object.getPrototypeOf(element), XULElement.prototype,
           `<${element.localName} is="${element.getAttribute("is")}" /> should not be a custom element.`);
       }
     }
 
+    function testSetElementCreationballbackInDocument() {
+      let element = document.getElementById("element8");
+      ok(element instanceof TestCustomElement3, "Should be an instance of TestCustomElement3");
+    }
+
     function setElementCreationCallbackCreate() {
       class TestCustomElement4 extends XULElement {}
       customElements.setElementCreationCallback(
         "test-custom-element-4", () => customElements.define("test-custom-element-4", TestCustomElement4));
 
       let element = document.createElementNS(XUL_NS, "test-custom-element-4");
       ok(element instanceof TestCustomElement4, "Should be an instance of TestCustomElement4");
+
+      class TestCustomElement5 extends XULElement {}
+      customElements.setElementCreationCallback(
+        "test-custom-element-5", () => {
+          ok(true, "test-custom-element-5 callback called");
+          customElements.define("test-custom-element-5", TestCustomElement5);
+        });
+
+      document.querySelector("#content").appendChild(parseXULToFragment(`<test-custom-element-5 />`));
+      let element1 = document.querySelector("#content").lastChild;
+      ok(element1 instanceof TestCustomElement5, "Should be an instance of TestCustomElement5");
     }
 
     function runTest() {
       basicCustomElementCreate();
       parserBasicElementUpgrade();
 
       tagNameWithoutDash();
       upgradeAfterDefine();
@@ -336,26 +357,28 @@
 
       upgradeAfterDefineBuiltIn();
 
       throwForInvalidBuiltInName();
       extendingWithoutDashCustomElement();
 
       nonCustomElementCreate();
 
+      testSetElementCreationballbackInDocument();
       setElementCreationCallbackCreate();
 
       SimpleTest.finish();
     }
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <p id="display"></p>
     <div id="content" style="display: none">
       <test-custom-element id="element4" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
       <testwithoutdash id="element5" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
       <axulelement id="element6" is="test-built-in-element" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
       <popup id="element7" is="test-popup-extend" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
+      <test-custom-element-3 id="element8" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"></test-custom-element-3>
     </div>
     <pre id="test"></pre>
   </body>
 </window>