Bug 1425079 - Add WPT test for the attributeChangedCallback which is triggered from parser; draft
authorEdgar Chen <echen@mozilla.com>
Mon, 15 Jan 2018 17:23:27 +0800
changeset 720343 96143bb4f12ef12b5774bde539dae5b175a79ab8
parent 720329 0294f39851acc561288eb9022d269567631a3e4b
child 746037 92298fa0c70ad33bdb94137fd11bcdf2ab1e5a1c
push id95514
push userechen@mozilla.com
push dateMon, 15 Jan 2018 09:32:34 +0000
bugs1425079
milestone59.0a1
Bug 1425079 - Add WPT test for the attributeChangedCallback which is triggered from parser; MozReview-Commit-ID: G0Cnxmv3sP8
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/custom-elements/parser/parser-sets-attributes-and-children.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -529267,17 +529267,17 @@
    "228d4a90d57dc942692becc6f126ec9130b3a4e0",
    "testharness"
   ],
   "custom-elements/parser/parser-fallsback-to-unknown-element.html": [
    "2fbbd742bfdc3ab63c5d5f01160830451fe620d2",
    "testharness"
   ],
   "custom-elements/parser/parser-sets-attributes-and-children.html": [
-   "422bd43f10b48f0450b20fd4b0de046d465bec38",
+   "9157427f1c1e3d30d8a470ce7bd756dbf3a0cdfe",
    "testharness"
   ],
   "custom-elements/parser/parser-uses-constructed-element.html": [
    "ed5476ab5b9a8d23ab7d84665c5d3224bb53dd18",
    "testharness"
   ],
   "custom-elements/parser/parser-uses-registry-of-owner-document.html": [
    "a62669ffcc75d54df38b65e33463566238c8644c",
--- a/testing/web-platform/tests/custom-elements/parser/parser-sets-attributes-and-children.html
+++ b/testing/web-platform/tests/custom-elements/parser/parser-sets-attributes-and-children.html
@@ -3,30 +3,40 @@
 <head>
 <title>Custom Elements: Changes to the HTML parser</title>
 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
 <meta name="assert" content="HTML parser must set the attributes and append the children on a custom element">
 <link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-token">
 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
 </head>
 <body>
 <div id="log"></div>
 <script>
 
 var numberOfAttributesInConstructor;
 var numberOfChildNodesInConstructor;
+var attributesChangedCalls = [];
 
 class MyCustomElement extends HTMLElement {
     constructor(...args) {
         super(...args);
         numberOfAttributesInConstructor = this.attributes.length;
         numberOfChildNodesInConstructor = this.childNodes.length;
     }
+
+    attributeChangedCallback(...args) {
+        attributesChangedCalls.push(create_attribute_changed_callback_log(this, ...args));
+    }
+
+    static get observedAttributes() {
+        return ['id', 'class'];
+    }
 };
 customElements.define('my-custom-element', MyCustomElement);
 
 </script>
 <my-custom-element id="custom-element-id" class="class1 class2">hello <b>world</b></my-custom-element>
 <script>
 
 var customElement = document.querySelector('my-custom-element');
@@ -49,11 +59,17 @@ test(function () {
     assert_equals(customElement.lastChild.firstChild.data, 'world', 'HTML parser must preserve grandchild nodes of a custom element');
 }, 'HTML parser must append child nodes');
 
 test(function () {
     assert_equals(numberOfAttributesInConstructor, 0, 'HTML parser must not set attributes on a custom element before invoking the constructor');
     assert_equals(numberOfChildNodesInConstructor, 0, 'HTML parser must not append child nodes to a custom element before invoking the constructor');
 }, 'HTML parser must set the attributes or append children before calling constructor');
 
+test(function () {
+    assert_equals(attributesChangedCalls.length, 2);
+    assert_attribute_log_entry(attributesChangedCalls[0], {name: 'id', oldValue: null, newValue: 'custom-element-id', namespace: null});
+    assert_attribute_log_entry(attributesChangedCalls[1], {name: 'class', oldValue: null, newValue: 'class1 class2', namespace: null});
+}, 'HTML parser must enqueue attributeChanged reactions');
+
 </script>
 </body>
 </html>