summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html')
-rw-r--r--testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html b/testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html
new file mode 100644
index 0000000000..f65763932b
--- /dev/null
+++ b/testing/web-platform/tests/credential-management/support/fedcm/disconnect-iframe.html
@@ -0,0 +1,61 @@
+<!doctype html>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script type="module">
+ import {disconnect_options,
+ request_options_with_mediation_required,
+ set_fedcm_cookie, manifest_origin} from './../fedcm-helper.sub.js';
+
+// Loading this iframe in the test will make a FedCM call on load, and
+// trigger a postMessage upon completion.
+//
+// message {
+// string result: "Pass" | "Failed get" | "Failed disconnect"
+// string errorType: error.name
+// }
+async function attemptDisconnect() {
+ try {
+ await IdentityCredential.disconnect(disconnect_options("1234"));
+ window.top.postMessage({result: "Pass"}, "*");
+ } catch (error) {
+ window.top.postMessage({result: "Failed disconnect", errorType: error.name},
+ "*");
+ }
+}
+
+window.onload = async () => {
+ const params = new URLSearchParams(document.location.search);
+ if (params.has("skip_get")) {
+ attemptDisconnect();
+ return;
+ }
+
+ // Use this variable to stop trying to select an account once the get()
+ // promise is resolved.
+ let cancelHelper = false;
+ try {
+ const credentialPromise = navigator.credentials.get(request_options_with_mediation_required());
+ async function helper() {
+ try {
+ if (cancelHelper)
+ return;
+
+ await window.test_driver.select_fedcm_account(0);
+ } catch (ex) {
+ setTimeout(helper, 100);
+ }
+ }
+ helper();
+ const cred = await credentialPromise;
+ await set_fedcm_cookie(manifest_origin);
+ // Now that we have a get(), attempt to disconnect permission.
+ attemptDisconnect();
+ } catch (error) {
+ window.top.postMessage({result: "Failed get", errorType: error.name}, '*');
+ }
+ // In case the get() call fails and no accounts may be selected, force the
+ // helper function to stop calling itself.
+ cancelHelper = true;
+};
+</script>
+