Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test failed 61 times in the preceding 30 days. quicksearch this test
- Manifest: dom/credentialmanagement/identity/tests/browser/browser.toml
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
"use strict";
XPCOMUtils.defineLazyServiceGetter(
this,
"IdentityCredentialStorageService",
"@mozilla.org/browser/identity-credential-storage-service;1",
"nsIIdentityCredentialStorageService"
);
add_task(async function test_auto_reauthentication_doesnt_show_ui() {
const idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
{}
);
const rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
{}
);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
let unlinked = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
async function () {
let promise = content.navigator.credentials.get({
identity: {
mode: "passive",
providers: [
{
configURL:
clientId: "123",
nonce: "nonce",
},
],
},
});
try {
let cred = await promise;
return cred.token;
} catch (err) {
return err;
}
}
);
ok(unlinked, "expect a result from the second request.");
ok(unlinked.name, "expect a DOMException which must have a name.");
// Set account as registered
IdentityCredentialStorageService.setState(
rpPrincipal,
idpPrincipal,
"connected",
true,
false
);
Services.perms.addFromPrincipal(
rpPrincipal,
"credential-allow-silent-access",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.addFromPrincipal(
rpPrincipal,
"credential-allow-silent-access^" + idpPrincipal.origin,
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
let popupShown = BrowserTestUtils.waitForEvent(
PopupNotifications.panel,
"popupshown"
);
let notApprovedPromise = SpecialPowers.spawn(
tab.linkedBrowser,
[],
async function () {
let promise = content.navigator.credentials.get({
identity: {
mode: "passive",
providers: [
{
configURL:
clientId: "test",
nonce: "nonce",
},
],
},
});
try {
let cred = await promise;
return cred.token;
} catch (err) {
return err;
}
}
);
await popupShown;
tab.linkedBrowser.browsingContext.topChromeWindow.document
.getElementsByClassName("popup-notification-secondary-button")[0]
.click();
let notApproved = await notApprovedPromise;
ok(notApproved, "expect a result from the second request.");
ok(notApproved.name, "expect a DOMException which must have a name.");
let approvedAndLinked = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
async function () {
let promise = content.navigator.credentials.get({
identity: {
mode: "passive",
providers: [
{
configURL:
clientId: "123",
nonce: "nonce",
},
],
},
});
try {
let cred = await promise;
return cred.token;
} catch (err) {
return err;
}
}
);
is(approvedAndLinked, "result", "Result obtained!");
// Clear state
IdentityCredentialStorageService.disconnect(rpPrincipal, idpPrincipal);
// Close tabs.
await BrowserTestUtils.removeTab(tab);
await SpecialPowers.popPrefEnv();
});