tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_http_scheme_no_upgrade.js (2112B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => {
      7  const { UrlbarTestUtils: module } = ChromeUtils.importESModule(
      8    "resource://testing-common/UrlbarTestUtils.sys.mjs"
      9  );
     10  module.init(this);
     11  return module;
     12 });
     13 
     14 add_task(async function test_scheme_modification() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [
     17      ["dom.security.https_first", true],
     18      ["dom.security.https_first_schemeless", true],
     19    ],
     20  });
     21 
     22  await BrowserTestUtils.withNewTab("example.net", async function (browser) {
     23    is(browser.currentURI.schemeIs("https"), true, "Do upgrade schemeless");
     24 
     25    {
     26      await UrlbarTestUtils.promiseAutocompleteResultPopup({
     27        window,
     28        value: "example.org",
     29      });
     30      const onLoad = BrowserTestUtils.browserLoaded(
     31        gBrowser.selectedBrowser,
     32        false,
     33        null
     34      );
     35      EventUtils.synthesizeKey("KEY_Enter");
     36      await onLoad;
     37 
     38      is(browser.currentURI.schemeIs("https"), true, "Do upgrade schemeless");
     39    }
     40 
     41    {
     42      await UrlbarTestUtils.promiseAutocompleteResultPopup({
     43        window,
     44        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     45        value: "http://example.com",
     46      });
     47      const onLoad = BrowserTestUtils.browserLoaded(
     48        gBrowser.selectedBrowser,
     49        false,
     50        null
     51      );
     52      EventUtils.synthesizeKey("KEY_Enter");
     53      await onLoad;
     54 
     55      is(
     56        browser.currentURI.schemeIs("http"),
     57        true,
     58        "Do not upgrade a scheme of http"
     59      );
     60    }
     61 
     62    {
     63      await UrlbarTestUtils.promiseAutocompleteResultPopup({
     64        window,
     65        value: "example.com",
     66      });
     67      const onLoad = BrowserTestUtils.browserLoaded(
     68        gBrowser.selectedBrowser,
     69        false,
     70        null
     71      );
     72      EventUtils.synthesizeKey("KEY_Enter");
     73      await onLoad;
     74 
     75      is(
     76        browser.currentURI.schemeIs("http"),
     77        true,
     78        "Do not upgrade schemeless inputs after we have an exception"
     79      );
     80    }
     81  });
     82 });