2 <title>Federated Credential Management API network request tests.
</title>
3 <link rel=
"help" href=
"https://fedidcg.github.io/FedCM">
4 <script src=
"/resources/testharness.js"></script>
5 <script src=
"/resources/testharnessreport.js"></script>
10 import {set_fedcm_cookie} from './support/fedcm-helper.js';
12 const url_prefix = 'https://{{host}}:{{ports[https][
0]}}/credential-management/support/';
13 const test_options = {
21 const login_options = {
25 promise_test(async t =
> {
26 await set_fedcm_cookie();
27 const cred = await navigator.credentials.get(test_options);
28 const token = await cred.login(login_options);
29 assert_equals(token.idToken,
"token");
30 },
"Successfully obtaining id_token should resolve the promise.");
32 promise_test(async t =
> {
33 await set_fedcm_cookie();
34 const first = await navigator.credentials.get(test_options);
35 const second = await navigator.credentials.get(test_options);
36 const first_cred = first.login(login_options);
37 const second_cred = second.login(login_options);
38 // We have to call promise_rejects_dom here, because if we call it after
39 // the promise gets rejected, the unhandled rejection event handler is called
40 // and fails the test even if we handle the rejection later.
41 const rej = promise_rejects_dom(t, 'AbortError', second_cred);
43 const first_token = await first_cred;
44 assert_equals(first_token.idToken,
"token");
47 "When there's a pending request, a second `get` call should be rejected. ");
49 promise_test(async t =
> {
50 const result = navigator.credentials.get({
58 return promise_rejects_js(t, TypeError, result);
59 },
"Reject when url is missing" );
61 promise_test(async t =
> {
62 const result = navigator.credentials.get({
70 return promise_rejects_dom(t,
"InvalidStateError", result);
71 },
"Reject when url is invalid");
73 promise_test(async t =
> {
74 const result = navigator.credentials.get({
77 url: 'https://idp.test',
82 return promise_rejects_dom(t,
"InvalidStateError", result);
83 },
"Reject when clientId is empty");
85 promise_test(async t =
> {
86 const cred = await navigator.credentials.get(test_options);
87 const token = await cred.login({});
89 assert_equals(token.idToken,
"token");
90 },
"nonce is not required in FederatedIdentityProvider.");
92 promise_test(async t =
> {
93 const result = navigator.credentials.get({
96 url: 'https://idp.test',
100 return promise_rejects_js(t, TypeError, result);
101 },
"Reject when clientId is missing" );
103 promise_test(async t =
> {
104 let controller = new AbortController();
105 const cred = await navigator.credentials.get(test_options);
106 const token_promise = cred.login({
108 signal: controller.signal,
111 return promise_rejects_dom(t, 'AbortError', token_promise);
112 },
"test the abort signal");
114 promise_test(async t =
> {
115 let controller = new AbortController();
116 const cred = await navigator.credentials.get(test_options);
117 const token_promise = cred.login({
119 signal: controller.signal,
122 await promise_rejects_dom(t, 'AbortError', token_promise);
124 const cred2 = await navigator.credentials.get(test_options);
125 const token = await cred2.login(login_options);
126 assert_equals(token.idToken,
"token");
127 },
"get after abort should work");
129 promise_test(async t =
> {
130 const result = navigator.credentials.get({
133 url: 'https://other-idp.test/',
138 return promise_rejects_dom(t,
"NetworkError", result);
139 },
"Provider URL should honor Content-Security-Policy.");
141 promise_test(async t =
> {
142 await set_fedcm_cookie();
143 const result = await navigator.credentials.get(test_options);
144 const token = await result.login(login_options);
145 assert_equals(token.idToken, 'token');
146 }, 'Test that COEP policy do not apply to FedCM requests');
148 promise_test(async t =
> {
149 await set_fedcm_cookie();
150 const result = await navigator.credentials.get({
153 url: url_prefix +
"fedcm-manifest-not-in-list/",
158 return promise_rejects_dom(t, 'NetworkError', result.login(login_options));
159 }, 'Test that the promise is rejected if the manifest is not in the manifest list');