diff options
Diffstat (limited to 'testing/web-platform/tests/html/capability-delegation')
8 files changed, 392 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-cross-origin.https.sub.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-cross-origin.https.sub.tentative.html new file mode 100644 index 0000000000..837fa438a3 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-cross-origin.https.sub.tentative.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/WICG/capability-delegation/issues/10 +--> +<title>Capability Delegation of Fullscreen Requests: Popup Cross-Origin</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> +<script src="resources/utils.js"></script> + +<div> + Verifies that element.requestFullscreen() calls from a cross-origin popup without user activation + work if and only if the opener has user activation and it delegates the capability. + + https://wicg.github.io/capability-delegation/spec.html +</div> + +<script> + let popup = null; + + function testCrossOriginPopupFullscreenDelegation(capability, activate, expectation) { + const message = {"type": "make-fullscreen-request"}; + const origin = "https://{{hosts[alt][www]}}:{{ports[https][0]}}"; + const expectationType = expectation ? "succeeds" : "fails"; + const delegationType = capability ? "with delegation" : "without delegation"; + const activationType = activate ? "with user activation" : "with no user activation"; + + promise_test(async () => { + const data = await postCapabilityDelegationMessage(popup, message, origin, capability, activate); + assert_equals(data.result, expectation ? "success" : "failure"); + }, `Fullscreen requests from a cross-origin popup ${expectationType} ${delegationType} from an opener ${activationType}`); + } + + promise_setup(async () => { + // Make sure the recipient popup has loaded. + popup = window.open("https://{{hosts[alt][www]}}:{{ports[https][0]}}/html/capability-delegation/resources/delegate-fullscreen-request-recipient.html", + "", "width=300,height=200"); + return getMessageData("recipient-loaded", popup); + }); + + testCrossOriginPopupFullscreenDelegation(/*capability=*/"", /*activate=*/false, /*expectation=*/false); + testCrossOriginPopupFullscreenDelegation(/*capability=*/"", /*activate=*/true, /*expectation=*/false); + testCrossOriginPopupFullscreenDelegation(/*capability=*/"fullscreen", /*activate=*/true, /*expectation=*/true); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-same-origin.https.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-same-origin.https.tentative.html new file mode 100644 index 0000000000..42bb8703d8 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-popup-same-origin.https.tentative.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/WICG/capability-delegation/issues/10 +--> +<title>Capability Delegation of Fullscreen Requests: Popup Same-Origin</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> +<script src="resources/utils.js"></script> + +<div> + Verifies that element.requestFullscreen() calls from a same-origin popup without user activation + work if and only if the opener has user activation and it delegates the capability. + + https://wicg.github.io/capability-delegation/spec.html +</div> + +<script> + let popup = null; + + function testSameOriginPopupFullscreenDelegation(capability, activate, expectation) { + const message = {"type": "make-fullscreen-request"}; + const expectationType = expectation ? "succeeds" : "fails"; + const delegationType = capability ? "with delegation" : "without delegation"; + const activationType = activate ? "with user activation" : "with no user activation"; + + promise_test(async () => { + const data = await postCapabilityDelegationMessage(popup, message, location.origin, capability, activate); + assert_equals(data.result, expectation ? "success" : "failure"); + }, `Fullscreen requests from a same-origin popup ${expectationType} ${delegationType} from an opener ${activationType}`); + } + + promise_setup(async () => { + // Make sure the recipient popup has loaded. + popup = window.open("./resources/delegate-fullscreen-request-recipient.html", + "", "width=300,height=200"); + return getMessageData("recipient-loaded", popup); + }); + + testSameOriginPopupFullscreenDelegation(/*capability=*/"", /*activate=*/false, /*expectation=*/false); + testSameOriginPopupFullscreenDelegation(/*capability=*/"", /*activate=*/true, /*expectation=*/false); + testSameOriginPopupFullscreenDelegation(/*capability=*/"fullscreen", /*activate=*/true, /*expectation=*/true); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-cross-origin.https.sub.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-cross-origin.https.sub.tentative.html new file mode 100644 index 0000000000..517860c896 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-cross-origin.https.sub.tentative.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/WICG/capability-delegation/issues/10 +--> +<title>Capability Delegation of Fullscreen Requests: Subframe Cross-Origin</title> +<script src="/common/get-host-info.sub.js"></script> +<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> +<script src="resources/utils.js"></script> + +<div> + Verifies that element.requestFullscreen() calls from a cross-origin subframe without user + activation work if and only if the top frame has user activation and it delegates the capability. + + https://wicg.github.io/capability-delegation/spec.html + + See wpt/html/user-activation/propagation*.html for frame tree user activation visibility tests. +</div> + +<iframe allow="fullscreen" width="300px" height="50px"> +</iframe> + +<script> + const origin = get_host_info().HTTPS_REMOTE_ORIGIN; + document.querySelector("iframe").src = origin + "/html/capability-delegation/resources/delegate-fullscreen-request-recipient.html"; + + function testCrossOriginSubframeFullscreenDelegation(capability, activate, expectation) { + const message = {"type": "make-fullscreen-request"}; + const expectationType = expectation ? "succeeds" : "fails"; + const delegationType = capability ? "with delegation" : "without delegation"; + const activationType = activate ? "with user activation" : "with no user activation"; + + promise_test(async () => { + const data = await postCapabilityDelegationMessage(frames[0], message, origin, capability, activate); + assert_equals(data.result, expectation ? "success" : "failure"); + }, `Fullscreen requests from a cross-origin subframe ${expectationType} ${delegationType} from an opener ${activationType}`); + } + + promise_setup(async () => { + // Make sure the recipient iframe has loaded. + return getMessageData("recipient-loaded", frames[0]); + }); + + testCrossOriginSubframeFullscreenDelegation(/*capability=*/"", /*activate=*/false, /*expectation=*/false); + testCrossOriginSubframeFullscreenDelegation(/*capability=*/"", /*activate=*/true, /*expectation=*/false); + testCrossOriginSubframeFullscreenDelegation(/*capability=*/"fullscreen", /*activate=*/true, /*expectation=*/true); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-same-origin.https.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-same-origin.https.tentative.html new file mode 100644 index 0000000000..16cbbfd3e9 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegate-fullscreen-request-subframe-same-origin.https.tentative.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/WICG/capability-delegation/issues/10 +--> +<title>Capability Delegation of Fullscreen Requests: Subframe Same-Origin</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> +<script src="resources/utils.js"></script> + +<div> + Verifies that element.requestFullscreen() calls from a same-origin subframe without user + activation work if and only if the top frame has user activation, regardless of whether it + delegates the capability or not. + + https://wicg.github.io/capability-delegation/spec.html + + See wpt/html/user-activation/propagation*.html for frame tree user activation visibility tests. +</div> + +<iframe allow="fullscreen" width="300px" height="50px" + src="./resources/delegate-fullscreen-request-recipient.html"> +</iframe> + +<script> + function testSameOriginSubframeFullscreenDelegation(capability, activate, expectation) { + const message = {"type": "make-fullscreen-request"}; + const expectationType = expectation ? "succeeds" : "fails"; + const delegationType = capability ? "with delegation" : "without delegation"; + const activationType = activate ? "with user activation" : "with no user activation"; + + promise_test(async () => { + const data = await postCapabilityDelegationMessage(frames[0], message, window.location, capability, activate); + assert_equals(data.result, expectation ? "success" : "failure"); + }, `Fullscreen requests from a same-origin subframe ${expectationType} ${delegationType} from an opener ${activationType}`); + } + + promise_setup(async () => { + // Make sure the recipient iframe has loaded. + return getMessageData("recipient-loaded", frames[0]); + }); + + testSameOriginSubframeFullscreenDelegation(/*capability=*/"", /*activate=*/false, /*expectation=*/false); + testSameOriginSubframeFullscreenDelegation(/*capability=*/"", /*activate=*/true, /*expectation=*/true); + testSameOriginSubframeFullscreenDelegation(/*capability=*/"fullscreen", /*activate=*/true, /*expectation=*/true); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/delegation-consumes-activation.https.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegation-consumes-activation.https.tentative.html new file mode 100644 index 0000000000..a538f29493 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegation-consumes-activation.https.tentative.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/whatwg/html/issues/4008 +--> +<title>Capability Delegation: Consumes User Activation</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> +<script src="resources/utils.js"></script> + +<div> + Test that capability delegation consumes transient user activation. + + https://wicg.github.io/capability-delegation/spec.html +</div> + +<iframe width="300px" height="50px"></iframe> + +<script> + function sendCapabilityDelegationMessageIgnoringException(origin, capability) { + try { + frames[0].postMessage("any_message", {targetOrigin: origin, delegate: capability}); + } catch (e) {} + } + + let capability_to_delegate; + + promise_setup(async () => { + capability_to_delegate = await findOneCapabilitySupportingDelegation(); + assert_true(!!capability_to_delegate, "The user agent supports delegating at least one capability"); + }); + + promise_test(async () => { + assert_false(navigator.userActivation.isActive); + + await test_driver.bless(); + assert_true(navigator.userActivation.isActive, "User activation is available initially"); + + sendCapabilityDelegationMessageIgnoringException("/", "blah"); + assert_true(navigator.userActivation.isActive, + "User activation is not consumed by delegation of an unknown delegation"); + + sendCapabilityDelegationMessageIgnoringException("*", capability_to_delegate); + assert_true(navigator.userActivation.isActive, + "User activation is not consumed by known delegation to disallowed targetOrigin"); + + sendCapabilityDelegationMessageIgnoringException("/", capability_to_delegate); + assert_false(navigator.userActivation.isActive, + "User activation is consumed by supported delegation"); + + }, "Capability delegation consumes transient user activation"); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/delegation-sender-checks.tentative.html b/testing/web-platform/tests/html/capability-delegation/delegation-sender-checks.tentative.html new file mode 100644 index 0000000000..4fa8a2d433 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/delegation-sender-checks.tentative.html @@ -0,0 +1,60 @@ +!DOCTYPE html> +<!-- + Tentative due to: + https://github.com/WICG/capability-delegation +--> +<title>Capability Delegation sender checks</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> +<script src="resources/utils.js"></script> + +<div> + Verifies that capability delegation related error checks in <a + href="https://wicg.github.io/capability-delegation/spec.html#monkey-patch-to-html-initiating-delegation">HTML + postMessage algorithm</a> are enforced correctly. +</div> + +<iframe width="300px" height="50px"></iframe> + +<script> + const frame = frames[0]; + const message = "any_message"; + const activate = false; + + let capability_to_delegate; + + promise_setup(async () => { + capability_to_delegate = await findOneCapabilitySupportingDelegation(); + assert_true(!!capability_to_delegate, "The user agent supports delegating at least one capability"); + }); + + promise_test(async () => { + try { + await postCapabilityDelegationMessage(frame, message, "/", "blah", activate); + assert_unreached(); + } catch (exception) { + assert_equals(exception.name, "NotSupportedError"); + } + }, "Delegating an unsupported capability throws an exception"); + + promise_test(async () => { + try { + await postCapabilityDelegationMessage(frame, message, "*", capability_to_delegate, activate); + assert_unreached(); + } catch (exception) { + assert_equals(exception.name, "NotAllowedError"); + } + }, "Delegating to targetOrigin='*' throws an exception"); + + promise_test(async () => { + try { + await postCapabilityDelegationMessage(frame, message, "/", capability_to_delegate, activate); + assert_unreached(); + } catch (exception) { + assert_equals(exception.name, "NotAllowedError"); + } + }, "Delegating without user activation throws an exception"); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/resources/delegate-fullscreen-request-recipient.html b/testing/web-platform/tests/html/capability-delegation/resources/delegate-fullscreen-request-recipient.html new file mode 100644 index 0000000000..11daf738d6 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/resources/delegate-fullscreen-request-recipient.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<title>Capability Delegation of Fullscreen Requests test recipient</title> +<body>Capability Delegation of Fullscreen Requests test recipient body</body> + +<script> + const initiator = window.opener ? window.opener : window.top; + initiator.postMessage({"type": "recipient-loaded"}, "*"); + + function reportResult(msg) { + initiator.postMessage({"type": "result", "result": msg}, "*"); + } + + document.addEventListener('fullscreenchange', async () => { + if (document.fullscreenElement) { + await document.exitFullscreen(); + reportResult("success"); + } + }); + + document.addEventListener('fullscreenerror', () => { + reportResult("failure"); + }); + + window.addEventListener("message", e => { + if (e.data.type == "make-fullscreen-request") { + document.body.requestFullscreen(); + } + }); +</script> diff --git a/testing/web-platform/tests/html/capability-delegation/resources/utils.js b/testing/web-platform/tests/html/capability-delegation/resources/utils.js new file mode 100644 index 0000000000..37c0226be7 --- /dev/null +++ b/testing/web-platform/tests/html/capability-delegation/resources/utils.js @@ -0,0 +1,55 @@ +// 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); + }); +} + +// A helper that simulates user activation on the current frame if `activate` is true, then posts +// `message` to `frame` with the target `origin` and specified `capability` to delegate. This helper +// awaits and returns a Promise fulfilled with the result message sent in reply from `frame`. +// However, if the `postMessage` call fails, the helper returns a Promise rejected with the +// exception. +async function postCapabilityDelegationMessage(frame, message, origin, capability, activate) { + let result_promise = getMessageData("result", frame); + + if (activate) + await test_driver.bless(); + + let postMessageOptions = {targetOrigin: origin}; + if (capability) + postMessageOptions["delegate"] = capability; + try { + frame.postMessage(message, postMessageOptions); + } catch (exception) { + return Promise.reject(exception); + } + + return await result_promise; +} + +// Returns the name of a capability for which `postMessage` delegation is supported by the user +// agent, or undefined if no such capability is found. +async function findOneCapabilitySupportingDelegation() { + const capabilities = ["fullscreen", "payment"]; + + for (let i = 0; i < capabilities.length; i++) { + try { + await postCapabilityDelegationMessage(window, "any_message", "/", capabilities[i], false); + assert_unreached(); + } catch (exception) { + if (exception.name != "NotSupportedError") + return capabilities[i]; + // Ignore all other exceptions to continue searching through the list. + } + }; + + return undefined; +} |