mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Automatic update from web-platform-tests Add a WPT for payment request delegation. The test verifies that PaymentRequest.show() call from a subframe fails from a cross-origin subframe without user activation unless the top frame has user activation and it delegates the capability to the subframe. Chrome passes this test through "wpt run" with the following command-line flag: --enable-blink-features=PaymentRequestRequiresUserActivation Bug: 1130558, 825270 Change-Id: I7ae26ad46653416aec72e342b7a32c24755e6e3e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3413851 Reviewed-by: Stephen McGruer <[email protected]> Commit-Queue: Mustaq Ahmed <[email protected]> Cr-Commit-Position: refs/heads/main@{#978296} -- wpt-commits: 30d5f8f4c7687a4f2c0a0999872a5767dbd3987c wpt-pr: 33006
82 lines
3.3 KiB
HTML
82 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<title>Payment 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 PaymentRequest.show() call 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="payment" width="300px" height="50px"
|
|
src="https://{{hosts[alt][www]}}:{{ports[https][0]}}/payment-request/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-payment-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");
|
|
}, "Payment-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");
|
|
}, "Payment-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: "payment"});
|
|
let data = await result_promise;
|
|
|
|
assert_equals(data.result, "success");
|
|
}, "Payment-request from a subframe succeeds with delegation when the top frame has user activation");
|
|
|
|
// This test must follow the successful test case above so that the user activation state there
|
|
// gets consumed.
|
|
promise_test(async () => {
|
|
let result_promise = getMessageData("result", frames[0]);
|
|
frames[0].postMessage(request, {targetOrigin: target_origin,
|
|
delegate: "payment"});
|
|
let data = await result_promise;
|
|
|
|
assert_equals(data.result, "failure");
|
|
}, "Payment-request from a subframe fails with delegation when the top frame has no user activation");
|
|
|
|
</script>
|