Skip to content

Commit

Permalink
[FedCM] Handle aborts for multi IDP requests
Browse files Browse the repository at this point in the history
In a single IDP request, an abort will close the FedCM dialog.
Currently, only the first IDP's abort will close the FedCM dialog. Until
we reach a better solution for multi IDP aborts, we allow any IDP's
abort to close the FedCM dialog.

Bug: 1394913
Change-Id: I307ec1335a1359f6fb40598eab95a1855a6ecf08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4160693
Reviewed-by: Christian Biesinger <[email protected]>
Commit-Queue: Zachary Tan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1092659}
  • Loading branch information
tttzach authored and chromium-wpt-export-bot committed Jan 13, 2023
1 parent bb55ed8 commit 816912b
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<title>Federated Credential Management API multi IDP abort first IDP test.</title>
<link rel="help" href="https://fedidcg.github.io/FedCM">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script type="module">
import {
set_fedcm_cookie,
set_alt_fedcm_cookie,
default_request_options,
default_alt_request_options
} from '../support/fedcm-helper.sub.js';

let cookies_promise = Promise.all([set_fedcm_cookie(), set_alt_fedcm_cookie()]);

promise_test(async t => {
let first_controller = new AbortController();
let first_test_options = default_request_options();
first_test_options.signal = first_controller.signal;
const first_cred = navigator.credentials.get(first_test_options);

let second_controller = new AbortController();
let second_test_options = default_alt_request_options();
second_test_options.signal = second_controller.signal;
const second_cred = navigator.credentials.get(second_test_options);

await cookies_promise;
first_controller.abort();
return Promise.all([
promise_rejects_dom(t, 'AbortError', first_cred),
promise_rejects_dom(t, 'AbortError', second_cred)
]);
}, "Test abort signal for a multi IDP request by aborting the first IDP");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<title>Federated Credential Management API multi IDP abort second IDP test.</title>
<link rel="help" href="https://fedidcg.github.io/FedCM">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script type="module">
import {
set_fedcm_cookie,
set_alt_fedcm_cookie,
default_request_options,
default_alt_request_options
} from '../support/fedcm-helper.sub.js';

let cookies_promise = Promise.all([set_fedcm_cookie(), set_alt_fedcm_cookie()]);

promise_test(async t => {
let first_controller = new AbortController();
let first_test_options = default_request_options();
first_test_options.signal = first_controller.signal;
const first_cred = navigator.credentials.get(first_test_options);

let second_controller = new AbortController();
let second_test_options = default_alt_request_options();
second_test_options.signal = second_controller.signal;
const second_cred = navigator.credentials.get(second_test_options);

await cookies_promise;
second_controller.abort();
return Promise.all([
promise_rejects_dom(t, 'AbortError', first_cred),
promise_rejects_dom(t, 'AbortError', second_cred)
]);
}, "Test abort signal for a multi IDP request by aborting the second IDP");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<title>Federated Credential Management API multi IDP get after abort test.</title>
<link rel="help" href="https://fedidcg.github.io/FedCM">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script type="module">
import {
set_fedcm_cookie,
set_alt_fedcm_cookie,
default_request_options,
default_alt_request_options
} from '../support/fedcm-helper.sub.js';

let cookies_promise = Promise.all([set_fedcm_cookie(), set_alt_fedcm_cookie()]);

promise_test(async t => {
let first_controller = new AbortController();
let first_test_options = default_request_options();
first_test_options.signal = first_controller.signal;
const first_cred = navigator.credentials.get(first_test_options);

let second_controller = new AbortController();
let second_test_options = default_alt_request_options();
second_test_options.signal = second_controller.signal;
const second_cred = navigator.credentials.get(second_test_options);

await cookies_promise;
second_controller.abort();
await Promise.all([
promise_rejects_dom(t, 'AbortError', first_cred),
promise_rejects_dom(t, 'AbortError', second_cred)
]);

const third_cred = navigator.credentials.get(default_request_options());
const fourth_cred = navigator.credentials.get(default_alt_request_options());

// NetworkError is returned when another IDP is selected.
await promise_rejects_dom(t, 'NetworkError', fourth_cred);
const cred = await third_cred;
assert_equals(cred.token, "token");
}, "Multiple gets after aborting a multi IDP request should work");
</script>

0 comments on commit 816912b

Please sign in to comment.