Update web-platform-tests/shadow-dom
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 21:26:28 +0000 (21:26 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 21:26:28 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192137

Reviewed by Antti Koivisto.

Re-imported the shadow DOM tests from wpt.

* resources/import-expectations.json:
* web-platform-tests/shadow-dom/ShadowRoot-interface.html:
* web-platform-tests/shadow-dom/event-dispatch-order.tentative-expected.txt: Added.
* web-platform-tests/shadow-dom/event-dispatch-order.tentative.html: Added.
* web-platform-tests/shadow-dom/input-type-radio-expected.txt: Added.
* web-platform-tests/shadow-dom/input-type-radio.html: Added.
* web-platform-tests/shadow-dom/resources/shadow-dom.js:
(dispatchEventWithLog):
(assert_event_path_equals):
* web-platform-tests/shadow-dom/slots-outside-shadow-dom-expected.txt: Added.
* web-platform-tests/shadow-dom/slots-outside-shadow-dom.html: Added.
* web-platform-tests/shadow-dom/w3c-import.log:

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/resources/import-expectations.json
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/ShadowRoot-interface.html
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/resources/shadow-dom.js
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/w3c-import.log

index 3c739be..0b06b28 100644 (file)
@@ -1,3 +1,25 @@
+2018-11-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Update web-platform-tests/shadow-dom
+        https://bugs.webkit.org/show_bug.cgi?id=192137
+
+        Reviewed by Antti Koivisto.
+
+        Re-imported the shadow DOM tests from wpt.
+
+        * resources/import-expectations.json:
+        * web-platform-tests/shadow-dom/ShadowRoot-interface.html:
+        * web-platform-tests/shadow-dom/event-dispatch-order.tentative-expected.txt: Added.
+        * web-platform-tests/shadow-dom/event-dispatch-order.tentative.html: Added.
+        * web-platform-tests/shadow-dom/input-type-radio-expected.txt: Added.
+        * web-platform-tests/shadow-dom/input-type-radio.html: Added.
+        * web-platform-tests/shadow-dom/resources/shadow-dom.js:
+        (dispatchEventWithLog):
+        (assert_event_path_equals):
+        * web-platform-tests/shadow-dom/slots-outside-shadow-dom-expected.txt: Added.
+        * web-platform-tests/shadow-dom/slots-outside-shadow-dom.html: Added.
+        * web-platform-tests/shadow-dom/w3c-import.log:
+
 2018-11-29  Youenn Fablet  <youenn@apple.com>
 
         Updating a service worker during a navigation load sometimes makes the load fail
index 984d75c..1e8c8fc 100644 (file)
     "web-platform-tests/worklets": "skip", 
     "web-platform-tests/x-frame-options": "skip", 
     "web-platform-tests/xhr": "import"
-}
+}
\ No newline at end of file
index 6b49f93..bda361e 100644 (file)
@@ -94,8 +94,10 @@ function testStyleSheets(mode) {
         var host = document.createElement('div');
         var shadowRoot = host.attachShadow({'mode': mode});
 
-        assert_equals(shadowRoot.styleSheets.length, 0, 'shadowRoot.styleSheets must be empty when the shadow root does not contain any stylesheets');
         shadowRoot.innerHTML = '<span></span><style> a.rule {} </style><style> b.rule {} </style>';
+        assert_equals(shadowRoot.styleSheets.length, 0, 'shadowRoot.styleSheets must be empty when the shadow root is not connected');
+
+        document.body.appendChild(host);
         assert_equals(shadowRoot.styleSheets.length, 2, 'shadowRoot.styleSheets must contain two items when the shadow root has two style elements');
         var styles = shadowRoot.querySelectorAll('style');
         assert_equals(shadowRoot.styleSheets[0], styles[0].sheet, 'shadowRoot.styleSheets[0] must be the first style element in the shadow root');
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative-expected.txt
new file mode 100644 (file)
index 0000000..329341d
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Event dispatch order: capture listerns should be called in capturing phase at a shadow host 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative.html b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative.html
new file mode 100644 (file)
index 0000000..1e88740
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<title>Shadow DOM: event dispatch order for capture and non-capture listerns at a shadow host</title>
+<meta name="author" title="Hayato Ito" href="mailto:hayato@google.com">
+<link rel="help" href="https://github.com/whatwg/dom/issues/685">
+<link rel="help" href="https://github.com/whatwg/dom/pull/686">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/shadow-dom.js"></script>
+<div id=host>
+  <template id=shadowroot data-mode=open>
+    <div id=target></div>
+  </template>
+</div>
+<script>
+test(() => {
+  let nodes = createTestTree(host);
+  let log = dispatchEventWithLog(nodes, nodes.target,
+                                 new Event('my-event', { bubbles: true, composed: true }),
+                                 { capture: true });
+  let path = ['target', 'shadowroot', 'host'];
+  assert_event_path_equals(log,
+                           [['host', 'host', null, path, 'capture'],
+                            ['shadowroot', 'target', null, path, 'capture'],
+                            ['target', 'target', null, path, 'capture'],
+                            ['target', 'target', null, path, 'non-capture'],
+                            ['shadowroot', 'target', null, path, 'non-capture'],
+                            ['host', 'host', null, path, 'non-capture'],
+                           ]);
+}, 'Event dispatch order: capture listerns should be called in capturing phase at a shadow host');
+</script>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio-expected.txt
new file mode 100644 (file)
index 0000000..9c3c5bd
--- /dev/null
@@ -0,0 +1,4 @@
+
+FAIL input type=radio elements should form a group inside shadow DOM. assert_true: expected true got false
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio.html b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio.html
new file mode 100644 (file)
index 0000000..9c90fcf
--- /dev/null
@@ -0,0 +1,73 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<input type="radio" name="group" id="lightRadio1">
+<input type="radio" name="group" id="lightRadio2">
+<div id="host"></div>
+<script>
+
+test(() => {
+    var lightRadio1 = document.getElementById("lightRadio1");
+    var lightRadio2 = document.getElementById("lightRadio2");
+
+    var host = document.getElementById("host");
+    var sr = host.attachShadow({mode: "closed"});
+    var shadowRadio1 = document.createElement("input");
+    shadowRadio1.name = "group";
+    shadowRadio1.id = "shadowRadio1";
+    shadowRadio1.type = "radio";
+    sr.appendChild(shadowRadio1);
+    var shadowRadio2 = document.createElement("input");
+    shadowRadio2.name = "group";
+    shadowRadio2.id = "shadowRadio2";
+    shadowRadio2.type = "radio";
+    sr.appendChild(shadowRadio2);
+
+    assert_false(lightRadio1.checked);
+    assert_false(lightRadio2.checked);
+    assert_false(shadowRadio1.checked);
+    assert_false(shadowRadio2.checked);
+
+    lightRadio1.click();
+    assert_true(lightRadio1.checked);
+    assert_false(lightRadio2.checked);
+    assert_false(shadowRadio1.checked);
+    assert_false(shadowRadio2.checked);
+
+    lightRadio2.click();
+    assert_false(lightRadio1.checked);
+    assert_true(lightRadio2.checked);
+    assert_false(shadowRadio1.checked);
+    assert_false(shadowRadio2.checked);
+
+    shadowRadio1.click();
+    assert_false(lightRadio1.checked);
+    assert_true(lightRadio2.checked);
+    assert_true(shadowRadio1.checked);
+    assert_false(shadowRadio2.checked);
+
+    shadowRadio2.click();
+    assert_false(lightRadio1.checked);
+    assert_true(lightRadio2.checked);
+    assert_false(shadowRadio1.checked);
+    assert_true(shadowRadio2.checked);
+
+    // Ensure radio groups work even when modifying shadow DOM.
+    shadowRadio2.remove();
+    sr.appendChild(shadowRadio2);
+    shadowRadio2.click();
+    assert_false(lightRadio1.checked);
+    assert_true(lightRadio2.checked);
+    assert_false(shadowRadio1.checked);
+    assert_true(shadowRadio2.checked);
+
+    shadowRadio1.click();
+    assert_false(lightRadio1.checked);
+    assert_true(lightRadio2.checked);
+    assert_true(shadowRadio1.checked);
+    assert_false(shadowRadio2.checked);
+}, "input type=radio elements should form a group inside shadow DOM.");
+
+</script>
index 3e55684..192ad45 100644 (file)
@@ -53,7 +53,9 @@ function createTestTree(node) {
   return ids;
 }
 
-function dispatchEventWithLog(nodes, target, event) {
+// TODO: Refactor this so that only interested results are recorded.
+// Callers of this function would not be interested in every results.
+function dispatchEventWithLog(nodes, target, event, options) {
 
   function labelFor(e) {
     return e.id || e.tagName;
@@ -70,15 +72,40 @@ function dispatchEventWithLog(nodes, target, event) {
       if (!id)
         continue;
       attachedNodes.push(node);
-      node.addEventListener(event.type, (e) => {
+      if (options && options.capture) {
+        // Record [currentTarget, target, relatedTarget, composedPath(), 'capture' | 'non-capture']
+        // TODO: Support registering listeners in different orders.
+        // e.g. Register a non-capture listener at first, then register a capture listener.
+        node.addEventListener(event.type, (e) => {
+          log.push([id,
+                    labelFor(e.target),
+                    e.relatedTarget ? labelFor(e.relatedTarget) : null,
+                    e.composedPath().map((n) => {
+                      return labelFor(n);
+                    }),
+                    'capture']);
+        }, true);
+        node.addEventListener(event.type, (e) => {
+          log.push([id,
+                    labelFor(e.target),
+                    e.relatedTarget ? labelFor(e.relatedTarget) : null,
+                    e.composedPath().map((n) => {
+                      return labelFor(n);
+                    }),
+                    'non-capture']);
+        });
+      } else {
         // Record [currentTarget, target, relatedTarget, composedPath()]
-        log.push([id,
-                  labelFor(e.target),
-                  e.relatedTarget ? labelFor(e.relatedTarget) : null,
-                  e.composedPath().map((n) => {
-                    return labelFor(n);
-                  })]);
-      });
+        node.addEventListener(event.type, (e) => {
+          log.push([id,
+                    labelFor(e.target),
+                    e.relatedTarget ? labelFor(e.relatedTarget) : null,
+                    e.composedPath().map((n) => {
+                      return labelFor(n);
+                    })]
+                  );
+        });
+      }
     }
   }
   target.dispatchEvent(event);
@@ -122,9 +149,13 @@ function dispatchUAEventWithLog(nodes, target, eventType, callback) {
 function assert_event_path_equals(actual, expected) {
   assert_equals(actual.length, expected.length);
   for (let i = 0; i < actual.length; ++i) {
+    assert_equals(actual[i].length, expected[i].length);
     assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' should be same');
     assert_equals(actual[i][1], expected[i][1], 'target at ' + i + ' should be same');
     assert_equals(actual[i][2], expected[i][2], 'relatedTarget at ' + i + ' should be same');
     assert_array_equals(actual[i][3], expected[i][3], 'composedPath at ' + i + ' should be same');
+    if (actual[i][4]) {
+      assert_equals(actual[i][4], expected[i][4], 'listener type should be same at ' + i);
+    }
   }
 }
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom-expected.txt
new file mode 100644 (file)
index 0000000..1c52a7e
--- /dev/null
@@ -0,0 +1,4 @@
+foo
+
+FAIL Light DOM slot element should be in flattened assignedNodes assert_array_equals: property 0, expected Element node <slot>foo</slot> but got Text node "foo"
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom.html b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom.html
new file mode 100644 (file)
index 0000000..a6fa2b2
--- /dev/null
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id="host1"><slot>foo</slot></div>
+<script>
+
+test(() => {
+  var host1 = document.getElementById("host1");
+  var sr = host1.attachShadow({mode: "open"});
+  sr.innerHTML = "<slot></slot>";
+  assert_array_equals(sr.firstChild.assignedNodes({ flatten: true }), [host1.firstChild]);
+}, "Light DOM slot element should be in flattened assignedNodes");
+
+</script>
index 900feba..e83a8d3 100644 (file)
@@ -35,6 +35,7 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-composed-path-with-related-target.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-composed-path.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-composed.html
+/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-dispatch-order.tentative.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-inside-shadow-tree.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-inside-slotted-node.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/event-post-dispatch.html
@@ -43,6 +44,7 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/getElementById-dynamic-001.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/historical.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-element-list.html
+/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/input-type-radio.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/layout-slot-no-longer-assigned-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/layout-slot-no-longer-assigned.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/layout-slot-no-longer-fallback-expected.html
@@ -53,4 +55,5 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slotchange.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback-in-document.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-fallback.html
+/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots-outside-shadow-dom.html
 /LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slots.html