Bug 1450230 [wpt PR 10251] - custom-elements: Add tests for callback timing with HTML parser., a=testonly
authorKent Tamura <tkent@chromium.org>
Mon, 09 Apr 2018 21:28:49 +0000
changeset 413709 e117fa7c449c13971a2eca201b848620e1704cda
parent 413708 563e2bd2cf265bd19c07cdc0e72c07e39fe90748
child 413710 c1715027770e6a4a487ba2ad522b91a6a51691ac
push id33850
push userapavel@mozilla.com
push dateMon, 16 Apr 2018 09:53:48 +0000
treeherdermozilla-central@6276ec7ebbf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1450230, 10251, 821831, 987972, 547424
milestone61.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 1450230 [wpt PR 10251] - custom-elements: Add tests for callback timing with HTML parser., a=testonly Automatic update from web-platform-testscustom-elements: Add tests for callback timing with HTML parser. Bug: 821831 Change-Id: I5b3e1978e37ce34e6fb885ca1077ea90ab2f494c Reviewed-on: https://chromium-review.googlesource.com/987972 Reviewed-by: Takayoshi Kochi <kochi@chromium.org> Commit-Queue: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/master@{#547424} wpt-commits: bc209c37228e5071e3fc8d3bcbc78c7b09db57a8 wpt-pr: 10251 wpt-commits: bc209c37228e5071e3fc8d3bcbc78c7b09db57a8 wpt-pr: 10251
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
@@ -546517,17 +546517,17 @@
    "228d4a90d57dc942692becc6f126ec9130b3a4e0",
    "testharness"
   ],
   "custom-elements/parser/parser-fallsback-to-unknown-element.html": [
    "2fbbd742bfdc3ab63c5d5f01160830451fe620d2",
    "testharness"
   ],
   "custom-elements/parser/parser-sets-attributes-and-children.html": [
-   "8049449173e4082b2f4ccadfe552abadadc0834a",
+   "89d8b4861a76f744687479f26086d9de4f72aac3",
    "testharness"
   ],
   "custom-elements/parser/parser-uses-constructed-element.html": [
    "ed5476ab5b9a8d23ab7d84665c5d3224bb53dd18",
    "testharness"
   ],
   "custom-elements/parser/parser-uses-create-an-element-for-a-token-svg.svg": [
    "51ecc75f42124e8071a767ef908ecc915cbf0fc1",
--- 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
@@ -1,42 +1,50 @@
 <!DOCTYPE html>
 <html>
 <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://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element">
 <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 numberOfAttributesInConstructor = 0;
+var numberOfChildNodesInConstructor = 0;
+var numberOfChildNodesInAttributeChangedCallback = 0;
+var numberOfChildNodesInConnectedCallback = 0;
 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));
+        numberOfChildNodesInAttributeChangedCallback = this.childNodes.length;
     }
 
     static get observedAttributes() {
         return ['id', 'class'];
     }
+
+    connectedCallback() {
+        numberOfChildNodesInConnectedCallback = this.childNodes.length;
+    }
 };
 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');
@@ -60,16 +68,28 @@ test(function () {
 }, '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 () {
+    // https://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element
+    // 3.3. Pop the element queue from the custom element reactions
+    // stack, and invoke custom element reactions in that queue.
+    assert_equals(numberOfChildNodesInConnectedCallback, 0);
+}, 'HTML parser should call connectedCallback before appending child nodes.');
+
+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});
+    // https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token
+    // 9.2. Invoke custom element reactions in queue.
+    assert_equals(numberOfChildNodesInAttributeChangedCallback, 0,
+                  'attributeChangedCallback should be called ' +
+                      'before appending a child');
 }, 'HTML parser must enqueue attributeChanged reactions');
 
 </script>
 </body>
 </html>