| <!DOCTYPE html> |
| <meta charset="utf-8"> |
| <title>FederatedCredential.revoke() promise resolution</title> |
| <link rel="author" title="Christian Biesinger" href="mailto:cbiesinger@chromium.org"> |
| <link rel="help" href="https://fedidcg.github.io/FedCM/#browser-api-revocation"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| |
| <script type="module"> |
| import {set_fedcm_cookie} from './support/fedcm-helper.js'; |
| const url_prefix = 'https://{{host}}:{{ports[https][0]}}/credential-management/support/'; |
| |
| async function getCredential(provider_url) { |
| const provider = { |
| url: provider_url || url_prefix, |
| clientId: "1234", |
| }; |
| return await navigator.credentials.get({ |
| federated: { |
| providers: [provider], |
| }, |
| }); |
| } |
| |
| promise_test(async t => { |
| await set_fedcm_cookie(); |
| await (await getCredential()).login({nonce: '1'}); |
| await (await getCredential()).revoke("1234"); |
| |
| // Second revoke should now fail since the first revoke should revoke |
| // the permission. |
| const result = (await getCredential()).revoke("1234"); |
| return promise_rejects_dom(t, "NetworkError", result); |
| }, "Successfully revoking a token should resolve the promise."); |
| |
| promise_test(async t => { |
| // Have to first login or the request will be rejected before it reaches |
| // the server. |
| await set_fedcm_cookie(); |
| await (await getCredential()).login({nonce: '1'}); |
| await (await getCredential()).revoke("1234"); |
| |
| const result = (await getCredential()).revoke("fail"); |
| return promise_rejects_dom(t, "NetworkError", result); |
| }, "Error should reject the promise."); |
| |
| promise_test(async t => { |
| const result = (await getCredential()).revoke(""); |
| return promise_rejects_dom(t, "InvalidStateError", result); |
| }, "Empty hint should reject the promise."); |
| |
| promise_test(async t => { |
| const result = getCredential("https://other-idp.example/").then((c) => c.revoke("foo@bar.com")); |
| return promise_rejects_dom(t, "NetworkError", result); |
| }, "Provider URL should honor Content-Security-Policy."); |
| </script> |