Bug 1938475 [Wayland] Fallback to monitor screen scale if we're missing wayland surfa...
[gecko.git] / security / manager / ssl / tests / mochitest / browser / browser_clientAuth_fetch_from_extension.js
blob4f9a45f03c5c544eab2faf26194744c497e92093
1 /* Any copyright is dedicated to the Public Domain.
2  * https://creativecommons.org/publicdomain/zero/1.0/ */
4 /* global browser */
6 "use strict";
8 let certDialogShown = false;
9 function onCertDialogLoaded(subject) {
10   certDialogShown = true;
11   // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
12   setTimeout(() => {
13     subject.acceptDialog();
14   }, 0);
17 Services.obs.addObserver(onCertDialogLoaded, "cert-dialog-loaded");
19 function clearClientCertsDecision() {
20   let cars = Cc["@mozilla.org/security/clientAuthRememberService;1"].getService(
21     Ci.nsIClientAuthRememberService
22   );
23   cars.clearRememberedDecisions();
26 registerCleanupFunction(() => {
27   Services.obs.removeObserver(onCertDialogLoaded, "cert-dialog-loaded");
28   // Make sure we don't affect other tests.
29   clearClientCertsDecision();
30 });
32 add_task(async function () {
33   await SpecialPowers.pushPrefEnv({
34     set: [["security.default_personal_cert", "Ask Every Time"]],
35   });
37   clearClientCertsDecision();
39   let extension = ExtensionTestUtils.loadExtension({
40     manifest: {
41       permissions: ["<all_urls>"],
42     },
44     async background() {
45       try {
46         await fetch("https://requireclientcert.example.com/");
47         browser.test.notifyPass("cert_dialog_shown");
48       } catch (error) {
49         browser.test.fail(`${error} :: ${error.stack}`);
50         browser.test.notifyFail("cert_dialog_shown");
51       }
52     },
53   });
55   await extension.startup();
56   await extension.awaitFinish("cert_dialog_shown");
57   await extension.unload();
58   ok(certDialogShown, "Cert dialog was shown");
59 });