| <!DOCTYPE html> | |
| <title>Federated Credential Management logout() API.</title> | |
| <link rel="help" href="https://wicg.github.io/FedCM"> | |
| <script src="/resources/testharness.js"></script> | |
| <script src="/resources/testharnessreport.js"></script> | |
| <body> | |
| <script> | |
| const url_prefix = 'https://{{host}}:{{ports[https][0]}}/credential-management/support/'; | |
| const test_options = { | |
| federated: { | |
| providers: [{ | |
| url: url_prefix, | |
| clientId: '1', | |
| // hint has to match the account id in support/accounts.json | |
| hint: '1234', | |
| }] | |
| } | |
| }; | |
| const test_options_no_hint = { | |
| federated: { | |
| providers: [{ | |
| url: url_prefix, | |
| clientId: '1', | |
| }] | |
| } | |
| }; | |
| const login_options = { | |
| nonce: '2', | |
| }; | |
| async function set_cookie() { | |
| // Wait for the identity provider's cookie to be installed. | |
| await new Promise(resolve => { | |
| const img = document.createElement('img'); | |
| img.addEventListener('error', resolve); | |
| img.src = url_prefix + 'set_cookie'; | |
| document.body.appendChild(img); | |
| }); | |
| } | |
| promise_test(async t => { | |
| await set_cookie(); | |
| const cred = await navigator.credentials.get(test_options); | |
| const token = await cred.login(login_options); | |
| assert_equals(token.idToken, "token"); | |
| await cred.logout(); | |
| }, "logout should not throw an exception."); | |
| promise_test(async t => { | |
| const cred = await navigator.credentials.get(test_options); | |
| return promise_rejects_dom(t, "InvalidStateError", cred.logout()); | |
| }, "logout should throw an exception when not logged in."); | |
| promise_test(async t => { | |
| await set_cookie(); | |
| const cred = await navigator.credentials.get(test_options_no_hint); | |
| const token = await cred.login(login_options); | |
| assert_equals(token.idToken, "token"); | |
| return promise_rejects_dom(t, "InvalidStateError", cred.logout()); | |
| }, "logout should require a hint."); | |
| </script> |