Files
tubestation/testing/web-platform/tests/screen-capture/delegate-request.https.sub.html
François Beaufort e5437a6e74 Bug 1816847 [wpt PR 38514] - Add experimental "display-capture" capability delegation, a=testonly
Automatic update from web-platform-tests
Add experimental "display-capture" capability delegation

This CL adds a new "display-capture" capability delegation so that
web developers can delegate a getUserMedia call from an iframe with user
activation to another frame.

Spec: https://github.com/WICG/capability-delegation/pull/32
Demo: https://display-capture-delegate.glitch.me/
I2S: https://groups.google.com/a/chromium.org/g/blink-dev/c/jag07miwY2g

Bug: 1412770
Change-Id: I89737d8a29a637d28b9b75b20ed84ff67f51bf8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4218507
Reviewed-by: Elad Alon <eladalon@chromium.org>
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Reviewed-by: Mustaq Ahmed <mustaq@chromium.org>
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1109509}

--

wpt-commits: f482c46636adda0bf1cd69656c4044af62ee7274
wpt-pr: 38514
2023-03-07 00:23:45 +00:00

81 lines
3.2 KiB
HTML

<!DOCTYPE html>
<title>Display-capture request delegation test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div>
Verifies that getDisplayMedia() calls from a cross-origin subframe without user activation
works if and only if the top frame has user activation and it delegates the capability to the
subframe.
</div>
<iframe allow="display-capture" width="300px" height="50px"
src="https://{{hosts[alt][www]}}:{{ports[https][0]}}/screen-capture/resources/delegate-request-subframe.sub.html">
</iframe>
<script>
// Returns a |Promise| that gets resolved with |event.data| when |window|
// receives from |source| a "message" event whose |event.data.type| matches the string
// |message_data_type|.
function getMessageData(message_data_type, source) {
return new Promise(resolve => {
function waitAndRemove(e) {
if (e.source != source || !e.data || e.data.type != message_data_type)
return;
window.removeEventListener("message", waitAndRemove);
resolve(e.data);
}
window.addEventListener("message", waitAndRemove);
});
}
promise_setup(async () => {
// Make sure the iframe has loaded.
await getMessageData("subframe-loaded", frames[0]);
});
const target_origin = "https://{{hosts[alt][www]}}:{{ports[https][0]}}";
const request = {"type": "make-display-capture-request"};
promise_test(async () => {
let result_promise = getMessageData("result", frames[0]);
frames[0].postMessage(request, {targetOrigin: target_origin});
let data = await result_promise;
assert_equals(data.result, "failure");
}, "Display-capture request from a subframe fails without delegation when the top frame has no user activation");
promise_test(async () => {
let result_promise = getMessageData("result", frames[0]);
await test_driver.bless();
frames[0].postMessage(request, {targetOrigin: target_origin});
let data = await result_promise;
assert_equals(data.result, "failure");
}, "Display-capture request from a subframe fails without delegation when the top frame has user activation");
promise_test(async () => {
{
let result_promise = getMessageData("result", frames[0]);
await test_driver.bless();
frames[0].postMessage(request, {targetOrigin: target_origin,
delegate: "display-capture"});
let data = await result_promise;
assert_equals(data.result, "success");
}
{
// Check display-capture request can be consumed only once.
let result_promise = getMessageData("result", frames[0]);
frames[0].postMessage(request, {targetOrigin: target_origin});
let data = await result_promise;
assert_equals(data.result, "failure");
}
}, "Display-capture request from a subframe succeeds with delegation when the top frame has user activation");
</script>