From f1bc8a75a0fc09aa18681d00a8e7a9a96abc250d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 25 Feb 2021 00:07:08 +0000 Subject: [PATCH] Bug 1690607 [wpt PR 27461] - Portals: focus() inside portal should change active element, a=testonly Automatic update from web-platform-tests Portals: focus() inside portal should change active element Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: https://github.com/WICG/portals/issues/257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan Reviewed-by: Lucas Gadani Reviewed-by: Jeremy Roman Reviewed-by: Alex Moshchuk Reviewed-by: David Trainor Cr-Commit-Position: refs/heads/master{#853647} -- wpt-commits: a507854e826d126010758ba44847d1b67fb29c01 wpt-pr: 27461 UltraBlame original commit: 7e6160586f3c29315b5b2267b293ecbdfefd4324 --- .../tests/portals/portals-focus.sub.html | 440 ++++++++++++++++++ .../resources/focus-page-with-autofocus.html | 153 ++++++ .../resources/focus-page-with-button.html | 63 +++ .../focus-page-with-x-origin-iframe.sub.html | 23 +- 4 files changed, 676 insertions(+), 3 deletions(-) create mode 100644 testing/web-platform/tests/portals/resources/focus-page-with-autofocus.html diff --git a/testing/web-platform/tests/portals/portals-focus.sub.html b/testing/web-platform/tests/portals/portals-focus.sub.html index 7577b80b6d65d..25e5ba869c13f 100644 --- a/testing/web-platform/tests/portals/portals-focus.sub.html +++ b/testing/web-platform/tests/portals/portals-focus.sub.html @@ -296,6 +296,126 @@ promise_test ( async +( +) += +> +{ +let +portal += +await +createPortal +( +document +new +URL +( +" +resources +/ +focus +- +page +- +with +- +button +. +html +" +location +. +href +) +) +; +try +{ +let +activeElementUpdated += +new +Promise +( +r += +> +{ +portal +. +onmessage += +e += +> +r +( +e +. +data +. +activeElementUpdated +) +} +) +; +portal +. +postMessage +( +' +focus +- +update +- +active +- +element +' +) +; +assert_true +( +await +activeElementUpdated +) +; +} +finally +{ +document +. +body +. +removeChild +( +portal +) +; +} +} +" +test +that +activeElement +inside +a +portal +is +updated +after +focus +( +) +is +called +" +) +; +promise_test +( +async t = > @@ -427,6 +547,134 @@ promise_test ( async +( +) += +> +{ +let +portal += +await +createPortal +( +document +new +URL +( +" +resources +/ +focus +- +page +- +with +- +x +- +origin +- +iframe +. +sub +. +html +" +location +. +href +) +) +; +try +{ +portal +. +postMessage +( +" +focus +- +update +- +active +- +element +" +) +; +let +{ +activeElementUpdated +} += +await +new +Promise +( +r += +> +{ +portal +. +onmessage += +e += +> +r +( +e +. +data +) +; +} +) +; +assert_true +( +activeElementUpdated +) +; +} +finally +{ +document +. +body +. +removeChild +( +portal +) +; +} +} +" +test +that +a +portal +' +s +x +- +origin +subframe +becomes +active +element +on +focus +" +) +; +promise_test +( +async t = > @@ -844,6 +1092,198 @@ " ) ; +promise_test +( +async +( +) += +> +{ +let +win += +await +openBlankPortalHost +( +) +; +let +doc += +win +. +document +; +try +{ +let +portal += +await +createPortal +( +doc +new +URL +( +" +resources +/ +focus +- +page +- +with +- +autofocus +. +html +" +location +. +href +) +) +; +portal +. +postMessage +( +' +check +- +active +- +element +' +) +; +let +result += +await +new +Promise +( +r += +> +{ +portal +. +onmessage += +e += +> +r +( +e +. +data +) +; +} +) +; +assert_true +( +result +" +autofocused +element +is +active +element +" +) +; +await +portal +. +activate +( +) +; +win +. +portalHost +. +postMessage +( +' +check +- +active +- +element +' +) +; +result += +await +new +Promise +( +r += +> +{ +win +. +portalHost +. +onmessage += +e += +> +r +( +e +. +data +) +} +) +; +assert_true +( +result +" +autofocused +element +is +still +active +element +" +) +; +} +finally +{ +win +. +close +( +) +; +} +} +" +test +that +autofocus +inside +a +portal +works +" +) +; const TAB = diff --git a/testing/web-platform/tests/portals/resources/focus-page-with-autofocus.html b/testing/web-platform/tests/portals/resources/focus-page-with-autofocus.html new file mode 100644 index 0000000000000..f8f0e92fa7dab --- /dev/null +++ b/testing/web-platform/tests/portals/resources/focus-page-with-autofocus.html @@ -0,0 +1,153 @@ +< +! +DOCTYPE +html +> +< +body +> +< +button +id += +" +one +" +> +one +< +/ +button +> +< +button +id += +" +two +" +autofocus +> +two +< +/ +button +> +< +button +id += +" +three +" +> +three +< +/ +button +> +< +script +> +function +messageHandler +( +e +) +{ +if +( +e +. +data += += += +' +check +- +active +- +element +' +) +{ +let +autofocusedButton += +document +. +querySelector +( +' +# +two +' +) +; +e +. +source +. +postMessage +( +document +. +activeElement += += += +autofocusedButton +) +; +} +} +window +. +portalHost +. +onmessage += +messageHandler +; +window +. +onportalactivate += +e += +> +{ +let +portal += +e +. +adoptPredecessor +( +) +; +portal +. +onmessage += +messageHandler +; +document +. +body +. +appendChild +( +portal +) +; +} +< +/ +script +> +< +/ +body +> diff --git a/testing/web-platform/tests/portals/resources/focus-page-with-button.html b/testing/web-platform/tests/portals/resources/focus-page-with-button.html index 19c1f395e55d0..08a11021f5332 100644 --- a/testing/web-platform/tests/portals/resources/focus-page-with-button.html +++ b/testing/web-platform/tests/portals/resources/focus-page-with-button.html @@ -74,6 +74,69 @@ ) ; } +if +( +e +. +data += += +" +focus +- +update +- +active +- +element +" +) +{ +let +button += +document +. +querySelector +( +" +button +" +) +; +button +. +focus +( +) +; +e +. +source +. +postMessage +( +{ +activeElementUpdated +: +document +. +activeElement += += += +button +} +{ +targetOrigin +: +" +* +" +} +) +; +} } if ( diff --git a/testing/web-platform/tests/portals/resources/focus-page-with-x-origin-iframe.sub.html b/testing/web-platform/tests/portals/resources/focus-page-with-x-origin-iframe.sub.html index 4707376ca503f..2a18010cfde67 100644 --- a/testing/web-platform/tests/portals/resources/focus-page-with-x-origin-iframe.sub.html +++ b/testing/web-platform/tests/portals/resources/focus-page-with-x-origin-iframe.sub.html @@ -9,6 +9,7 @@ < script > +async function handleMessage ( @@ -25,6 +26,22 @@ " focus " +| +| +e +. +data += += +" +focus +- +update +- +active +- +element +" ) { let @@ -45,9 +62,9 @@ . postMessage ( -" -focus -" +e +. +data " * "