commit 8a09ee0f8cd84f87ffb6777a75d9b924e9c9de21
parent 087fe5a98792580fc2850b876b5eeb8831ddd531
Author: Valentin Gosu <valentin.gosu@gmail.com>
Date: Wed, 17 Dec 2025 13:37:37 +0000
Bug 1915371 - Part 3: Make test_http_auth_cache mochitest automatically accept password prompt r=necko-reviewers,jesup
Differential Revision: https://phabricator.services.mozilla.com/D271583
Diffstat:
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/netwerk/test/mochitests/mochitest.toml b/netwerk/test/mochitests/mochitest.toml
@@ -141,7 +141,10 @@ skip-if = [
["test_fetch_lnk.html"]
["test_http_auth_cache.html"]
-support-files = ["authenticate.sjs"]
+support-files = ["authenticate.sjs", "../../../toolkit/components/prompts/test/prompt_common.js", "../../../toolkit/components/prompts/test/chromeScript.js"]
+skip-if = [
+ "os == 'android'", # bug 1267092: auth prompt helpers don't work on android
+]
["test_idn_redirect.html"]
skip-if = [
diff --git a/netwerk/test/mochitests/test_http_auth_cache.html b/netwerk/test/mochitests/test_http_auth_cache.html
@@ -4,27 +4,24 @@
<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">
- SimpleTest.waitForExplicitFinish();
-
async function populateHttpAuthCache() {
await fetch("authenticate.sjs");
}
async function clearHttpAuthCacheTest() {
let script = SpecialPowers.loadChromeScript(function () {
- /* eslint-env mozilla/frame-script */
+ /* eslint-env mozilla/chrome-script */
+ const {addMessageListener, sendAsyncMessage} = this;
addMessageListener("start", function () {
try {
let httpAuthCache = Cc["@mozilla.org/network/http-auth-cache;1"]
.getService(Ci.nsIHttpAuthCache);
- // for(let k in httpAuthCache) {
- // console.log("Method:", k);
- // }
let entries = httpAuthCache.getEntries();
sendAsyncMessage("before", entries.length);
@@ -33,7 +30,7 @@
httpAuthCache.clearEntry(entry);
}
- let afterEntries = httpAuthCache.getEntries(1);
+ let afterEntries = httpAuthCache.getEntries();
sendAsyncMessage("after", afterEntries.length);
} catch (e) {
console.error("Failed to get or clear the HTTP auth cache", e);
@@ -52,11 +49,33 @@
});
}
- add_task(async function () {
- await populateHttpAuthCache();
- await clearHttpAuthCacheTest();
- SimpleTest.finish();
- });
+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>