Bug 1773793 [wpt PR 34381] - [FedCM] Move most tests to fedcm-network-requests, a...
[gecko.git] / testing / web-platform / tests / credential-management / fedcm-network-requests.sub.https.html
blob75b80afb383098ae1da1db5133fd15d9123f1c91
1 <!DOCTYPE html>
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>
7 <body>
9 <script type="module">
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 = {
14 federated: {
15 providers: [{
16 url: url_prefix,
17 clientId: '1',
21 const login_options = {
22 nonce: '2',
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");
45 return rej;
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({
51 federated: {
52 providers: [{
53 clientId: '1',
54 nonce: '2',
57 });
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({
63 federated: {
64 providers: [{
65 url: 'test',
66 clientId: '1',
69 });
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({
75 federated: {
76 providers: [{
77 url: 'https://idp.test',
78 clientId: '',
81 });
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({
94 federated: {
95 providers: [{
96 url: 'https://idp.test',
99 });
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({
107 nonce: '2',
108 signal: controller.signal,
110 controller.abort();
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({
118 nonce: '2',
119 signal: controller.signal,
121 controller.abort();
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({
131 federated: {
132 providers: [{
133 url: 'https://other-idp.test/',
134 clientId: '1',
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({
151 federated: {
152 providers: [{
153 url: url_prefix + "fedcm-manifest-not-in-list/",
154 clientId: '1',
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');
161 </script>