tor-browser

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

browser_httpsfirst_speculative_connect.js (1928B)


      1 "use strict";
      2 
      3 const TEST_PATH_HTTP = getRootDirectory(gTestPath).replace(
      4  "chrome://mochitests/content",
      5  "http://example.com"
      6 );
      7 
      8 let console_messages = [
      9  {
     10    description: "Speculative Connection should get logged",
     11    expectLogLevel: Ci.nsIConsoleMessage.warn,
     12    expectIncludes: [
     13      "Upgrading insecure speculative TCP connection",
     14      "to use",
     15      "example.com",
     16      "file_httpsfirst_speculative_connect.html",
     17    ],
     18  },
     19  {
     20    description: "Upgrade should get logged",
     21    expectLogLevel: Ci.nsIConsoleMessage.warn,
     22    expectIncludes: [
     23      "Upgrading insecure request",
     24      "to use",
     25      "example.com",
     26      "file_httpsfirst_speculative_connect.html",
     27    ],
     28  },
     29 ];
     30 
     31 function on_new_console_messages(msgObj) {
     32  const message = msgObj.message;
     33  const logLevel = msgObj.logLevel;
     34 
     35  if (message.includes("HTTPS-First Mode:")) {
     36    for (let i = 0; i < console_messages.length; i++) {
     37      const testCase = console_messages[i];
     38      // Check if log-level matches
     39      if (logLevel !== testCase.expectLogLevel) {
     40        continue;
     41      }
     42      // Check if all substrings are included
     43      if (testCase.expectIncludes.some(str => !message.includes(str))) {
     44        continue;
     45      }
     46      ok(true, testCase.description);
     47      console_messages.splice(i, 1);
     48      break;
     49    }
     50  }
     51 }
     52 
     53 add_task(async function () {
     54  requestLongerTimeout(4);
     55 
     56  await SpecialPowers.pushPrefEnv({
     57    set: [["dom.security.https_first", true]],
     58  });
     59  Services.console.registerListener(on_new_console_messages);
     60 
     61  let promiseLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
     62  BrowserTestUtils.startLoadingURIString(
     63    gBrowser.selectedBrowser,
     64    `${TEST_PATH_HTTP}file_httpsfirst_speculative_connect.html`
     65  );
     66  await promiseLoaded;
     67 
     68  await BrowserTestUtils.waitForCondition(() => console_messages.length === 0);
     69 
     70  Services.console.unregisterListener(on_new_console_messages);
     71 });