summaryrefslogtreecommitdiffstats
path: root/dom/security/test/https-only/browser_continue_button_delay.js
blob: 6bdee1610e05c0d08cb77fd3be906fb5c2201a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";

function waitForEnabledButton() {
  return new Promise(resolve => {
    const button = content.document.getElementById("openInsecure");
    const observer = new content.MutationObserver(mutations => {
      for (const mutation of mutations) {
        if (
          mutation.type === "attributes" &&
          mutation.attributeName === "inert" &&
          !mutation.target.inert
        ) {
          resolve();
        }
      }
    });
    observer.observe(button, { attributeFilter: ["inert"] });
    ok(
      button.inert,
      "The 'Continue to HTTP Site' button should be inert right after the error page is loaded."
    );
  });
}

add_task(async function () {
  waitForExplicitFinish();

  await SpecialPowers.pushPrefEnv({
    set: [["dom.security.https_only_mode", true]],
  });

  const specifiedDelay = Services.prefs.getIntPref(
    "security.dialog_enable_delay",
    1000
  );

  let loaded = BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser);
  info("Loading insecure page");
  const startTime = Date.now();
  BrowserTestUtils.startLoadingURIString(
    gBrowser,
    // We specifically want a insecure url here that will fail to upgrade
    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    "http://untrusted.example.com:80"
  );
  await loaded;
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], waitForEnabledButton);
  const endTime = Date.now();

  const observedDelay = endTime - startTime;

  Assert.greater(
    observedDelay,
    specifiedDelay - 100,
    `The observed delay (${observedDelay}ms) should be roughly the same or greater than the delay specified in "security.dialog_enable_delay" (${specifiedDelay}ms)`
  );

  finish();
});