Skip to content

Commit

Permalink
[Partitioned Popins] Implement popinContextType() JS API
Browse files Browse the repository at this point in the history
This CL implements `window.popinContextType()` that tells whether a page
is inside of a Partitioned Popin.

Explainer: https://explainers-by-googlers.github.io/partitioned-popins/
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/ApU_zUmpQ2g/

Low-Coverage-Reason: COVERAGE_UNDERREPORTED Tested through WPTs.

Bug: 340606651
Bug: b/362973178
Change-Id: I053512217160d4875e7558be35eda3a3bbace833
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5826165
Reviewed-by: Ari Chivukula <[email protected]>
Reviewed-by: Robert Kaplow <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Sandor «Alex» Major <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1350877}
  • Loading branch information
sandormajor authored and chromium-wpt-export-bot committed Sep 4, 2024
1 parent ab72b1d commit a154121
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

'use strict';

// Spec: https://explainers-by-googlers.github.io/partitioned-popins/
// Step 1 (window) Set up listener to resolve messages as they come in.
// Step 2 (window) Open popin.
// Step 3 (popin) Call `window.popinContextType()` and send result to opener.
// Step 4 (main-window) Assert and cleanup.

async_test(t => {
// Step 1
window.addEventListener("message", t.step_func(e => {
switch (e.data.type) {
case 'popin':
// Step 4
assert_equals(e.data.message, "partitioned");
t.done();
break;
}
}));

// Step 2
window.open("/partitioned-popins/resources/popinContextType.html", '_blank', 'popin');
}, "Verify PopinContextType is 'partitioned' in a Partitioned Popin");
12 changes: 12 additions & 0 deletions partitioned-popins/popinContextType.tentative.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

'use strict';

// Spec: https://explainers-by-googlers.github.io/partitioned-popins/
// Step 1 - Call `window.popinContextType()` and receive null.

async_test(t => {
assert_equals(window.popinContextType(), null);
t.done();
}, "Verify PopinContextType is null on top-level page");
17 changes: 17 additions & 0 deletions partitioned-popins/resources/popinContextType.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<meta charset="utf-8">
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
(async function () {
test_driver.set_test_context(window.opener);

// Step 3 (partitioned-popins/popinContextType.in-popin.tentative.sub.https.window.js)
let message = "popinContextType is not supported";
try {
message = window.popinContextType();
} catch (_) { }
window.opener.postMessage({ type: "popin", message: message }, "*");
window.close();
})();
</script>

0 comments on commit a154121

Please sign in to comment.