Bug 1837476 [wpt PR 40455] - [FedCM] Move getUserInfo() tests to its own file, a=testonly

Automatic update from web-platform-tests
[FedCM] Move getUserInfo() tests to its own file

This CL moves existing getUserInfo() tests to a separate file, which
lets us not have too many tests in the same file and show coverage for
the feature more easily.

Change-Id: Ib83099ad3cce4aae971b746a087ddec682efe79b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4600295
Reviewed-by: Yi Gu <yigu@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1155048}

--

wpt-commits: 0ef2754742e5e22a2f8926f526ecb1d0fa6cec34
wpt-pr: 40455
This commit is contained in:
Nicolás Peña 2023-06-19 19:56:40 +00:00 коммит произвёл moz-wptsync-bot
Родитель 728b142507
Коммит b80116a63c
2 изменённых файлов: 68 добавлений и 55 удалений

Просмотреть файл

@ -8,8 +8,7 @@
<body>
<script type="module">
import {alt_manifest_origin,
request_options_with_mediation_required,
import {request_options_with_mediation_required,
alt_request_options_with_mediation_required,
request_options_with_mediation_optional,
fedcm_test,
@ -25,16 +24,6 @@ function loadUrlInIframe(url) {
});
}
async function createIframeWithPermissionPolicyAndWaitForMessage(test, iframeUrl) {
const messageWatcher = new EventWatcher(test, window, "message");
let iframe = document.createElement("iframe");
iframe.src = iframeUrl;
iframe.allow = "identity-credentials-get";
document.body.appendChild(iframe);
const message = await messageWatcher.wait_for("message");
return message.data;
}
fedcm_test(async t => {
const cred = await navigator.credentials.get(request_options_with_mediation_required());
assert_equals(cred.token, "token");
@ -201,49 +190,6 @@ fedcm_test(async t => {
assert_equals(query_sw_iframe2.contentDocument.body.textContent, "1");
}, 'Test that service worker cannot observe fetches performed by FedCM API');
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
const iframe_in_idp_scope = `${alt_manifest_origin}/\
credential-management/support/fedcm/userinfo-iframe.html`;
const message = await createIframeWithPermissionPolicyAndWaitForMessage(t, iframe_in_idp_scope);
assert_equals(message.result, "Pass");
assert_equals(message.numAccounts, 1);
assert_equals(message.firstAccountEmail, "john_doe@idp.example");
assert_equals(message.firstAccountName, "John Doe");
assert_equals(message.firstAccountGivenName, "John");
assert_equals(message.firstAccountPicture, "https://idp.example/profile/123");
}, 'Test basic User InFo API flow');
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
const iframe_in_idp_scope = `support/fedcm/userinfo-iframe.html`;
const message = await createIframeWithPermissionPolicyAndWaitForMessage(t, iframe_in_idp_scope);
assert_equals(message.result, "Fail");
}, 'Test that User Info API only works when invoked from iframe that is same origin as the IDP');
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
try {
const manifest_path = `${alt_manifest_origin}/\
credential-management/support/fedcm/manifest.py`;
const user_info = await IdentityProvider.getUserInfo({
configURL: manifest_path,
// Approved client
clientId: '123',
});
assert_unreached("Failure message");
} catch (error) {
assert_equals(error.message, "UserInfo request must be initiated from a frame that is the same origin with the provider.");
// Expect failure
}
}, 'Test that User Info API does not work in the top frame');
fedcm_test(async t => {
let test_options = request_options_with_mediation_optional("manifest_with_single_account.json");
await select_manifest(t, test_options);

Просмотреть файл

@ -0,0 +1,67 @@
<!DOCTYPE html>
<title>Federated Credential Management API getUserInfo() tests.</title>
<link rel="help" href="https://fedidcg.github.io/FedCM">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script type="module">
import {alt_manifest_origin,
alt_request_options_with_mediation_required,
fedcm_test} from './support/fedcm-helper.sub.js';
async function createIframeWithPermissionPolicyAndWaitForMessage(test, iframeUrl) {
const messageWatcher = new EventWatcher(test, window, "message");
let iframe = document.createElement("iframe");
iframe.src = iframeUrl;
iframe.allow = "identity-credentials-get";
document.body.appendChild(iframe);
const message = await messageWatcher.wait_for("message");
return message.data;
}
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
const iframe_in_idp_scope = `${alt_manifest_origin}/\
credential-management/support/fedcm/userinfo-iframe.html`;
const message = await createIframeWithPermissionPolicyAndWaitForMessage(t, iframe_in_idp_scope);
assert_equals(message.result, "Pass");
assert_equals(message.numAccounts, 1);
assert_equals(message.firstAccountEmail, "john_doe@idp.example");
assert_equals(message.firstAccountName, "John Doe");
assert_equals(message.firstAccountGivenName, "John");
assert_equals(message.firstAccountPicture, "https://idp.example/profile/123");
}, 'Test basic User InFo API flow');
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
const iframe_in_idp_scope = `support/fedcm/userinfo-iframe.html`;
const message = await createIframeWithPermissionPolicyAndWaitForMessage(t, iframe_in_idp_scope);
assert_equals(message.result, "Fail");
}, 'Test that User Info API only works when invoked from iframe that is same origin as the IDP');
fedcm_test(async t => {
const cred = await navigator.credentials.get(alt_request_options_with_mediation_required());
assert_equals(cred.token, "token");
try {
const manifest_path = `${alt_manifest_origin}/\
credential-management/support/fedcm/manifest.py`;
const user_info = await IdentityProvider.getUserInfo({
configURL: manifest_path,
// Approved client
clientId: '123',
});
assert_unreached("Failure message");
} catch (error) {
assert_equals(error.message, "UserInfo request must be initiated from a frame that is the same origin with the provider.");
// Expect failure
}
}, 'Test that User Info API does not work in the top frame');
</script>