Fix <label> clicks inside delegatesFocus ShadowRoots
This patch makes the delegatesFocus logic in MouseEventHandler also
account for <label>s, which fixes a bug where clicking on a <label>
inside a delegatesFocus ShadowRoot doesn't click on its target element.
Fixed: 329003651
Change-Id: I369be824f2e11dd2229f73b5f786a2fdaaff31ff
diff --git a/shadow-dom/focus/label-inside-delegatesfocus.html b/shadow-dom/focus/label-inside-delegatesfocus.html
new file mode 100644
index 0000000..6b1a862
--- /dev/null
+++ b/shadow-dom/focus/label-inside-delegatesfocus.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://issues.chromium.org/issues/329003651">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/resources/testdriver-actions.js"></script>
+
+<input value="hello world">
+<div id=host>
+ <template shadowrootmode=open shadowrootdelegatesfocus=true>
+ <label>
+ <p>click me</p>
+ <button>button</button>
+ </label>
+ </template>
+</div>
+
+<script>
+promise_test(async () => {
+ const p = host.shadowRoot.querySelector('p');
+ const button = host.shadowRoot.querySelector('button');
+ const input = document.querySelector('input');
+
+ let gotClick = false;
+ button.onclick = () => gotClick = true;
+
+ input.select();
+
+ // We can't use test_driver.click() here due to this issue:
+ // https://github.com/web-platform-tests/wpt/issues/41257
+ await new Promise(requestAnimationFrame);
+ const rect = p.getBoundingClientRect();
+ const actions = new test_driver.Actions();
+ await actions
+ .pointerMove(Math.round(rect.x + rect.width / 2), Math.round(rect.y + rect.height / 2), {})
+ .pointerDown({button: actions.ButtonType.LEFT})
+ .pointerUp({button: actions.ButtonType.LEFT})
+ .send();
+
+ assert_true(gotClick);
+}, 'Clicking a label should click its target like normal in a delegatesFocus shadowroot.');
+</script>