Bug 1773746 [wpt PR 34376] - Reland "[FedCM] Make revoke test do actual network reque...
[gecko.git] / testing / web-platform / tests / credential-management / fedcm-revoke.sub.https.html
blob79a9a872f46cddfc7c64333caab59c4f31e621ed
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>FederatedCredential.revoke() promise resolution</title>
4 <link rel="author" title="Christian Biesinger" href="mailto:cbiesinger@chromium.org">
5 <link rel="help" href="https://fedidcg.github.io/FedCM/#browser-api-revocation">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
9 <script type="module">
10 import {set_fedcm_cookie} from './support/fedcm-helper.js';
11 const url_prefix = 'https://{{host}}:{{ports[https][0]}}/credential-management/support/';
13 async function getCredential(provider_url) {
14 const provider = {
15 url: provider_url || url_prefix,
16 clientId: "1234",
18 return await navigator.credentials.get({
19 federated: {
20 providers: [provider],
22 });
25 promise_test(async t => {
26 await set_fedcm_cookie();
27 await (await getCredential()).login({nonce: '1'});
28 await (await getCredential()).revoke("1234");
30 // Second revoke should now fail since the first revoke should revoke
31 // the permission.
32 const result = (await getCredential()).revoke("1234");
33 return promise_rejects_dom(t, "NetworkError", result);
34 }, "Successfully revoking a token should resolve the promise.");
36 promise_test(async t => {
37 // Have to first login or the request will be rejected before it reaches
38 // the server.
39 await set_fedcm_cookie();
40 await (await getCredential()).login({nonce: '1'});
41 await (await getCredential()).revoke("1234");
43 const result = (await getCredential()).revoke("fail");
44 return promise_rejects_dom(t, "NetworkError", result);
45 }, "Error should reject the promise.");
47 promise_test(async t => {
48 const result = (await getCredential()).revoke("");
49 return promise_rejects_dom(t, "InvalidStateError", result);
50 }, "Empty hint should reject the promise.");
52 promise_test(async t => {
53 const result = getCredential("https://other-idp.example/").then((c) => c.revoke("foo@bar.com"));
54 return promise_rejects_dom(t, "NetworkError", result);
55 }, "Provider URL should honor Content-Security-Policy.");
56 </script>