tor-browser

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

jetstream3.js (4561B)


      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, logTask } = require("./utils/profiling");
      8 
      9 module.exports = logTest(
     10  "JetStream 3 test",
     11  async function (context, commands) {
     12    context.log.info("Starting JetStream 3 test");
     13    let url = context.options.browsertime.url;
     14    let page_cycles = context.options.browsertime.page_cycles;
     15    let suite_name = context.options.browsertime.suite_name;
     16    let page_cycle_delay = context.options.browsertime.page_cycle_delay;
     17    let post_startup_delay = context.options.browsertime.post_startup_delay;
     18    let page_timeout = context.options.timeouts.pageLoad;
     19    let expose_profiler = context.options.browsertime.expose_profiler;
     20 
     21    context.log.info(
     22      "Waiting for %d ms (post_startup_delay)",
     23      post_startup_delay
     24    );
     25    await commands.wait.byTime(post_startup_delay);
     26 
     27    for (let count = 0; count < page_cycles; count++) {
     28      await logTask(context, "cycle " + count, async function () {
     29        context.log.info("Navigating to about:blank");
     30        await commands.navigate("about:blank");
     31 
     32        context.log.info(
     33          "Cycle %d, waiting for %d ms",
     34          count,
     35          page_cycle_delay
     36        );
     37        await commands.wait.byTime(page_cycle_delay);
     38 
     39        context.log.info("Cycle %d, starting the measure", count);
     40        if (expose_profiler === "true") {
     41          context.log.info("Custom profiler start!");
     42          if (context.options.browser === "firefox") {
     43            await commands.profiler.start();
     44          } else if (context.options.browser === "chrome") {
     45            await commands.trace.start();
     46          }
     47        }
     48        await commands.measure.start(url);
     49 
     50        // Wait up to 30s for the UI to fully intialize. In particular, for the
     51        // status button to be ready.
     52        await commands.js.runAndWait(`
     53          return new Promise(resolve => {
     54            let tries = 0;
     55            // 300 * 100ms = 30 seconds
     56            const maxTries = 300;
     57            const waitForJetStreamUIReady = () => {
     58              const status = document.getElementById("status");
     59              if (status && typeof status.onclick === "function") {
     60                JetStream.start();
     61                resolve("Started JetStream after UI ready");
     62              } else if (++tries > maxTries) {
     63                resolve("Timed out waiting for JetStream UI readiness");
     64              } else {
     65                setTimeout(waitForJetStreamUIReady, 100);
     66              }
     67            };
     68            waitForJetStreamUIReady();
     69          });
     70        `);
     71 
     72        let data_exists = null;
     73        let starttime = await commands.js.run(`return performance.now();`);
     74        while (
     75          (data_exists == null || !Object.keys(data_exists).length) &&
     76          (await commands.js.run(`return performance.now();`)) - starttime <
     77            page_timeout
     78        ) {
     79          let wait_time = 3000;
     80          context.log.info(
     81            "Waiting %d ms for data from %s...",
     82            wait_time,
     83            suite_name
     84          );
     85          await commands.wait.byTime(wait_time);
     86 
     87          data_exists = await commands.js.run(`
     88            return new Promise(resolve => {
     89                globalThis.addEventListener("JetStreamDone", (event) => {
     90                    resolve(event.detail);
     91                }, { once: true });
     92            });
     93        `);
     94        }
     95 
     96        if (expose_profiler === "true") {
     97          context.log.info("Custom profiler stop!");
     98          if (context.options.browser === "firefox") {
     99            await commands.profiler.stop();
    100          } else if (context.options.browser === "chrome") {
    101            await commands.trace.stop();
    102          }
    103        }
    104        if (
    105          !data_exists &&
    106          (await commands.js.run(`return performance.now();`)) - starttime >=
    107            page_timeout
    108        ) {
    109          context.log.error("Benchmark timed out. Aborting...");
    110          return false;
    111        }
    112 
    113        let data = null;
    114 
    115        const score = data_exists[suite_name].metrics.Score;
    116        const tests = data_exists[suite_name].tests;
    117 
    118        data = {
    119          score,
    120          tests,
    121        };
    122        data.suite_name = suite_name;
    123 
    124        commands.measure.addObject({ js3_res: data });
    125        context.log.info("Value of summarized benchmark data: ", data);
    126        return true;
    127      });
    128    }
    129 
    130    return true;
    131  }
    132 );