Automatic update from web-platform-tests [wpt] Fix testdriver.js portability issues in `digital-credentials/` Some testdriver.js implementations use `postMessage()` to send testdriver commands from a cross-origin iframe to the testharness browsing context. [0] and [1] must be respected for testdriver.js to work in those environments. This is a no-op change when running the tests with content shell, which implements testdriver.js with nonstandard JS bindings. [0]: https://web-platform-tests.org/writing-tests/testdriver.html#using-test-driver-in-other-browsing-contexts [1]: https://web-platform-tests.org/writing-tests/testdriver.html#markup: > The testdriver.js and testdriver-vendor.js must both be included ... > in the top-level test document when using testdriver from a different > context Bug: None Change-Id: Idacd0b65d03d4feb77883927a5d90e61eb59797b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5922668 Reviewed-by: Weizhong Xia <weizhong@google.com> Commit-Queue: Jonathan Lee <jonathanjlee@google.com> Cr-Commit-Position: refs/heads/main@{#1370211} -- wpt-commits: f29200eabb447101ecbb2681aee9d57b7cac1a87 wpt-pr: 48681
138 lines
5.5 KiB
HTML
138 lines
5.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>
|
|
Test allow attribute with "digital-credentials-get" and
|
|
CredentialsContainer's .get() method
|
|
</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-vendor.js"></script>
|
|
<script>
|
|
const hostInfo = get_host_info();
|
|
const iframeDetails = [
|
|
{
|
|
policy: null,
|
|
crossOrigin: false,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: null,
|
|
crossOrigin: true,
|
|
expectIsAllowed: false,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get",
|
|
crossOrigin: false,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get",
|
|
crossOrigin: true,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get *",
|
|
crossOrigin: false,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get *",
|
|
crossOrigin: true,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get 'none'",
|
|
crossOrigin: false,
|
|
expectIsAllowed: false,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get 'none'",
|
|
crossOrigin: true,
|
|
expectIsAllowed: false,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get 'self'",
|
|
crossOrigin: false,
|
|
expectIsAllowed: true,
|
|
},
|
|
{
|
|
policy: "digital-credentials-get 'self'",
|
|
crossOrigin: true,
|
|
expectIsAllowed: false,
|
|
},
|
|
{
|
|
policy: `digital-credentials-get ${hostInfo.HTTPS_REMOTE_ORIGIN}`,
|
|
crossOrigin: false,
|
|
expectIsAllowed: false,
|
|
},
|
|
{
|
|
policy: `digital-credentials-get ${hostInfo.HTTPS_REMOTE_ORIGIN}`,
|
|
crossOrigin: true,
|
|
expectIsAllowed: true,
|
|
},
|
|
];
|
|
|
|
async function loadIframe({ policy, crossOrigin, expectIsAllowed }) {
|
|
const iframe = document.createElement("iframe");
|
|
if (policy !== null) {
|
|
iframe.allow = policy;
|
|
}
|
|
|
|
await new Promise((resolve) => {
|
|
iframe.onload = resolve;
|
|
iframe.src = new URL(
|
|
"/digital-credentials/support/iframe.html",
|
|
crossOrigin
|
|
? hostInfo.HTTPS_REMOTE_ORIGIN
|
|
: location.origin
|
|
).href;
|
|
iframe.dataset.expectIsAllowed = expectIsAllowed;
|
|
document.body.appendChild(iframe);
|
|
});
|
|
iframe.focus();
|
|
return iframe;
|
|
}
|
|
|
|
function runTests() {
|
|
for (const details of iframeDetails) {
|
|
promise_test(async (test) => {
|
|
const iframe = await loadIframe(details);
|
|
const { expectIsAllowed } = details;
|
|
const action = "get";
|
|
const options = {
|
|
digital: {
|
|
// Results in TypeError when allowed, NotAllowedError when disallowed
|
|
providers: [],
|
|
},
|
|
};
|
|
const { data } = await new Promise((resolve) => {
|
|
window.addEventListener("message", resolve, {
|
|
once: true,
|
|
});
|
|
iframe.contentWindow.postMessage(
|
|
{ action, options, needsActivation: true },
|
|
"*"
|
|
);
|
|
});
|
|
const { name, message } = data;
|
|
if (expectIsAllowed) {
|
|
assert_true(name == "TypeError" ||
|
|
(name == "NotAllowedError" && message.includes("transient activation")),
|
|
`${iframe.outerHTML} - ${message}`);
|
|
} else {
|
|
assert_equals(name, "NotAllowedError", `${iframe.outerHTML} - ${message}`);
|
|
assert_false(message.includes("transient activation"),
|
|
`${iframe.outerHTML} - ${message}`);
|
|
}
|
|
iframe.remove();
|
|
}, `Policy to use: ${details.policy}, is cross-origin: ${details.crossOrigin}, is allowed by policy: ${details.expectIsAllowed}`);
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="runTests()"></body>
|
|
</html>
|