tor-browser

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

speculative-connect.js (1600B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* eslint-env node */
      6 
      7 const { logTest } = require("./utils/profiling");
      8 
      9 module.exports = logTest(
     10  "speculative connect pageload",
     11  async function (context, commands) {
     12    context.log.info(
     13      "Starting a pageload for which we will first make a speculative connection to the host"
     14    );
     15 
     16    const url = "https://en.wikipedia.org/wiki/Barack_Obama";
     17 
     18    await commands.navigate("about:blank");
     19    await commands.wait.byTime(1000);
     20 
     21    context.log.debug("Make privileged call to speculativeConnect");
     22    const script = `
     23    var URI = Services.io.newURI("${url}");
     24    var principal = Services.scriptSecurityManager.createContentPrincipal(URI, {});
     25    Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(URI, principal, null, false);
     26  `;
     27 
     28    commands.js.runPrivileged(script);
     29 
     30    // More than enough time for the connection to be made
     31    await commands.wait.byTime(1000);
     32 
     33    await commands.measure.start();
     34    await commands.navigate(url);
     35    await commands.measure.stop();
     36 
     37    let connect_time = await commands.js.run(
     38      `return (window.performance.timing.connectEnd - window.performance.timing.navigationStart);`
     39    );
     40    context.log.info("connect_time: " + connect_time);
     41 
     42    await commands.measure.addObject({
     43      custom_data: { connect_time },
     44    });
     45 
     46    context.log.info("Speculative connect test finished.");
     47    return true;
     48  }
     49 );