blob: ad775d8bd21107ab0e79194536e95667ddcec43c [file] [log] [blame]
<!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 type="module">
import {set_fedcm_cookie} from './support/fedcm-helper.js';
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',
};
promise_test(async t => {
await set_fedcm_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_fedcm_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>