Add a custom element test for synchronous element construction in HTML parser
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Mar 2016 22:37:57 +0000 (22:37 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Mar 2016 22:37:57 +0000 (22:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154932

Reviewed by Antti Koivisto.

Added a test.

* fast/custom-elements/parser/parser-constructs-custom-element-synchronously-expected.txt: Added.
* fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197466 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html [new file with mode: 0644]

index 4fd7593..759a4ca 100644 (file)
@@ -1,3 +1,15 @@
+2016-03-02  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add a custom element test for synchronous element construction in HTML parser
+        https://bugs.webkit.org/show_bug.cgi?id=154932
+
+        Reviewed by Antti Koivisto.
+
+        Added a test.
+
+        * fast/custom-elements/parser/parser-constructs-custom-element-synchronously-expected.txt: Added.
+        * fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html: Added.
+
 2016-03-02  Filip Pizlo  <fpizlo@apple.com>
 
         Add a benchmark for string transcoding.
diff --git a/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously-expected.txt b/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously-expected.txt
new file mode 100644 (file)
index 0000000..1a6d397
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS HTML parser must only append nodes that appear before a custom element before instantiating the custom element 
+
diff --git a/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html b/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html
new file mode 100644 (file)
index 0000000..814b19a
--- /dev/null
@@ -0,0 +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 construct a custom element synchronously">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<link rel='stylesheet' href='../../../resources/testharness.css'>
+</head>
+<body>
+<div id="log"></div>
+<script>
+
+var childElementCountInConstructor;
+var containerChildNodesInConstructor = [];
+var containerNextSilbingInConstructor;
+class MyCustomElement extends HTMLElement {
+    constructor() {
+        super();
+        var container = document.getElementById('custom-element-container');
+        for (var i = 0; i < container.childNodes.length; i++)
+            containerChildNodesInConstructor.push(container.childNodes[i]);
+        containerNextSilbingInConstructor = container.nextSibling;
+    }
+};
+document.defineCustomElement('my-custom-element', MyCustomElement);
+
+</script>
+<div id="custom-element-container">
+    <span id="custom-element-previous-element"></span>
+    <my-custom-element></my-custom-element>
+    <div id="custom-element-next-element"></div>
+</div>
+<script>
+
+test(function () {
+    var instance = document.querySelector('my-custom-element');
+
+    assert_equals(containerChildNodesInConstructor.length, 3);
+    assert_equals(containerChildNodesInConstructor[0], instance.parentNode.firstChild);
+    assert_equals(containerChildNodesInConstructor[1], document.getElementById('custom-element-previous-element'));
+    assert_equals(containerChildNodesInConstructor[2], instance.previousSibling);
+    assert_equals(containerNextSilbingInConstructor, null);
+
+}, 'HTML parser must only append nodes that appear before a custom element before instantiating the custom element');
+
+</script>
+</body>
+</html>