<!
DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<
html>
<
head>
<
script src=
"/tests/SimpleTest/SimpleTest.js"></
script>
<
script type=
"text/javascript" src=
"../../../toolkit/components/prompts/test/prompt_common.js"></
script>
</
head>
<
body>
<
script type=
"application/javascript">
async function populateHttpAuthCache() {
await fetch(
"authenticate.sjs");
}
async function clearHttpAuthCacheTest() {
let
script = SpecialPowers.loadChromeScript(function () {
const {addMessageListener, sendAsyncMessage} = this;
addMessageListener(
"start", function () {
try {
let httpAuthCache = Cc[
"@mozilla.org/network/http-auth-cache;1"]
.getService(Ci.nsIHttpAuthCache);
let entries = httpAuthCache.getEntries();
sendAsyncMessage(
"before", entries.length);
for (let entry of entries) {
console.log(entry.realm);
httpAuthCache.clearEntry(entry);
}
let afterEntries = httpAuthCache.getEntries();
sendAsyncMessage(
"after", afterEntries.length);
} catch (e) {
console.error(
"Failed to get or clear the HTTP auth cache", e);
sendAsyncMessage(
"before", -
1);
sendAsyncMessage(
"after", -
1);
}
});
});
script.sendAsyncMessage(
"start");
await
script.promiseOneMessage(
"before").then(val => {
ok(val >
0, `got ${val}, cache size before clearing should be above
0`);
});
await
script.promiseOneMessage(
"after").then(val => {
is(val,
0,
"cache should be empty after clearing");
});
}
add_task(async function () {
const state = {
msg:
"This site is asking you to sign in.",
title:
"Authentication Required",
textValue:
"",
passValue:
"",
iconClass:
"authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg:
"",
checked: false,
focused:
"textField",
defButton:
"button0",
};
const action = {
buttonClick:
"ok",
textField:
"user",
passField:
"pass",
};
let promptDone = handlePrompt(state, action);
await populateHttpAuthCache();
await promptDone;
await clearHttpAuthCacheTest();
});
</
script>
</
body>
</
html>