summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/fedcm-login-status
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/credential-management/fedcm-login-status')
-rw-r--r--testing/web-platform/tests/credential-management/fedcm-login-status/confirm-idp-login.https.html41
-rw-r--r--testing/web-platform/tests/credential-management/fedcm-login-status/cross-origin-status.https.html87
-rw-r--r--testing/web-platform/tests/credential-management/fedcm-login-status/logged-out.https.html47
3 files changed, 175 insertions, 0 deletions
diff --git a/testing/web-platform/tests/credential-management/fedcm-login-status/confirm-idp-login.https.html b/testing/web-platform/tests/credential-management/fedcm-login-status/confirm-idp-login.https.html
new file mode 100644
index 0000000000..0f8df72b61
--- /dev/null
+++ b/testing/web-platform/tests/credential-management/fedcm-login-status/confirm-idp-login.https.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>FedCM IDP log-in status API tests</title>
+<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 type="module">
+import {request_options_with_mediation_required,
+ fedcm_test,
+ fedcm_get_dialog_type_promise,
+ select_manifest,
+ mark_signed_in} from '../support/fedcm-helper.sub.js';
+
+fedcm_test(async t => {
+ await mark_signed_in();
+
+ let test_options = request_options_with_mediation_required("manifest_with_variable_accounts.json");
+ await select_manifest(t, test_options);
+
+ let cred_promise = navigator.credentials.get(test_options);
+ let type = await fedcm_get_dialog_type_promise(t);
+ assert_equals(type, "ConfirmIdpLogin");
+
+ // Manifest selection only persists for a single fetch, so we need to set it
+ // again because Chrome's implementation re-fetches the manifest as well, not
+ // just the accounts endpoint.
+ // (This is not technically spec-compliant)
+ await select_manifest(t, test_options);
+ await window.test_driver.click_fedcm_dialog_button("ConfirmIdpLoginContinue");
+
+ // Now wait for the account chooser.
+ type = await fedcm_get_dialog_type_promise(t);
+ assert_equals(type, "AccountChooser");
+ window.test_driver.select_fedcm_account(0);
+
+ let cred = await cred_promise;
+ assert_equals(cred.token, "account_id=1234");
+}, 'Tests the IDP login dialog and subsequent account chooser.');
+</script>
diff --git a/testing/web-platform/tests/credential-management/fedcm-login-status/cross-origin-status.https.html b/testing/web-platform/tests/credential-management/fedcm-login-status/cross-origin-status.https.html
new file mode 100644
index 0000000000..f32e18d40e
--- /dev/null
+++ b/testing/web-platform/tests/credential-management/fedcm-login-status/cross-origin-status.https.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>FedCM IDP login status API tests</title>
+<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 type="module">
+import {fedcm_test,
+ alt_manifest_origin,
+ same_site_manifest_origin,
+ set_fedcm_cookie,
+ select_manifest,
+ request_options_with_mediation_required,
+ alt_request_options_with_mediation_required,
+ fedcm_get_and_select_first_account,
+ open_and_wait_for_popup,
+ mark_signed_out} from '../support/fedcm-helper.sub.js';
+
+const path = '/credential-management/support/'
+const url_prefix = alt_manifest_origin + path;
+const same_site_url_prefix = same_site_manifest_origin + path;
+
+fedcm_test(async t => {
+ await set_fedcm_cookie(same_site_manifest_origin);
+ await mark_signed_out(same_site_manifest_origin);
+ // The header should be processed successfully because it is same-site.
+ const fetch_result = await fetch(same_site_url_prefix + "mark_signedin");
+ assert_true(fetch_result.ok);
+
+ const config = request_options_with_mediation_required(undefined, same_site_manifest_origin);
+ await select_manifest(t, config);
+ const cred = await fedcm_get_and_select_first_account(t, config);
+ assert_equals(cred.token, "token");
+}, 'Cross-origin same-site status header should work from fetch()');
+
+fedcm_test(async t => {
+ await mark_signed_out(alt_manifest_origin);
+ // The header should be ignored because it's a cross-site fetch.
+ const fetch_result = await fetch(url_prefix + "mark_signedin");
+ assert_true(fetch_result.ok);
+
+ const config = alt_request_options_with_mediation_required();
+ const result = navigator.credentials.get(config);
+ return promise_rejects_dom(t, 'NetworkError', result);
+}, 'Cross-origin status header should be ignored from fetch()');
+
+fedcm_test(async t => {
+ await mark_signed_out(alt_manifest_origin);
+ // The header should be ignored because it's a cross-site iframe.
+ let iframe = document.createElement("iframe");
+ let iframe_load = new Promise(resolve => {iframe.onload = resolve;});
+ iframe.src = url_prefix + "mark_signedin";
+ document.body.appendChild(iframe);
+ await iframe_load;
+
+ const config = alt_request_options_with_mediation_required();
+ const result = navigator.credentials.get(config);
+ return promise_rejects_dom(t, 'NetworkError', result);
+}, 'Status header should be ignored from cross-site iframe');
+
+fedcm_test(async t => {
+ await mark_signed_out(alt_manifest_origin);
+ // The header in the subresource should be ignored because the iframe is cross-site.
+ let iframe = document.createElement("iframe");
+ let iframe_load = new Promise(resolve => {iframe.onload = resolve;});
+ iframe.src = url_prefix + "iframe-mark-signedin.html";
+ document.body.appendChild(iframe);
+ await iframe_load;
+
+ const config = alt_request_options_with_mediation_required();
+ const result = navigator.credentials.get(config);
+ return promise_rejects_dom(t, 'NetworkError', result);
+}, 'Status header should be ignored from cross-site iframe that contains a subresource with the header');
+
+fedcm_test(async t => {
+ await mark_signed_out(alt_manifest_origin);
+ await open_and_wait_for_popup(alt_manifest_origin, "/credential-management/support/fencedframe-mark-signedin.html");
+
+ const config = alt_request_options_with_mediation_required();
+ const result = navigator.credentials.get(config);
+ return promise_rejects_dom(t, 'NetworkError', result);
+}, 'Status header should be ignored from a fenced frame, even if it is same-origin');
+
+</script>
+
diff --git a/testing/web-platform/tests/credential-management/fedcm-login-status/logged-out.https.html b/testing/web-platform/tests/credential-management/fedcm-login-status/logged-out.https.html
new file mode 100644
index 0000000000..09750ff096
--- /dev/null
+++ b/testing/web-platform/tests/credential-management/fedcm-login-status/logged-out.https.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>FedCM IDP sign-in status API tests</title>
+<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 type="module">
+import {request_options_with_mediation_required,
+ fedcm_test,
+ alt_manifest_origin,
+ alt_request_options_with_mediation_required,
+ fedcm_get_and_select_first_account,
+ mark_signed_out} 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 => {
+ await mark_signed_out();
+ const config = request_options_with_mediation_required();
+ const result = navigator.credentials.get(config);
+ return promise_rejects_dom(t, 'NetworkError', result);
+}, 'FedCM request should fail because we are marked as not logged in');
+
+fedcm_test(async t => {
+ // Log in so that the browser allows the later user info request.
+ const cred = await fedcm_get_and_select_first_account(t, alt_request_options_with_mediation_required());
+ assert_equals(cred.token, "token");
+
+ await mark_signed_out(alt_manifest_origin);
+
+ 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, "Fail");
+
+}, 'User info request should fail because we are marked as not logged in');
+</script>