tor-browser

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

perftest_http3_lucasquicfetch.js (3758B)


      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 /* eslint-env node */
      5 
      6 /*
      7 Ensure the `--firefox.preference=network.http.http3.enable:true` is
      8 set for this test.
      9 */
     10 
     11 async function getNumLoaded(commands) {
     12  return commands.js.run(`
     13    let sum = 0;
     14    document.querySelectorAll("#imgContainer img").forEach(e => {
     15      sum += e.complete & e.naturalHeight != 0;
     16    });
     17    return sum;
     18  `);
     19 }
     20 
     21 async function waitForImgLoadEnd(
     22  prevCount,
     23  maxStableCount,
     24  timeout,
     25  commands,
     26  context
     27 ) {
     28  let starttime = await commands.js.run(`return performance.now();`);
     29  let endtime = await commands.js.run(`return performance.now();`);
     30  let changing = true;
     31  let newCount = -1;
     32  let stableCount = 0;
     33 
     34  while (
     35    ((await commands.js.run(`return performance.now();`)) - starttime <
     36      timeout) &
     37    changing
     38  ) {
     39    // Wait a bit before making another round
     40    await commands.wait.byTime(100);
     41    newCount = await getNumLoaded(commands);
     42    context.log.debug(`${newCount}, ${prevCount}, ${stableCount}`);
     43 
     44    // Check if we are approaching stability
     45    if (newCount == prevCount) {
     46      // Gather the end time now
     47      if (stableCount == 0) {
     48        endtime = await commands.js.run(`return performance.now();`);
     49      }
     50      stableCount++;
     51    } else {
     52      prevCount = newCount;
     53      stableCount = 0;
     54    }
     55 
     56    if (stableCount >= maxStableCount) {
     57      // Stability achieved
     58      changing = false;
     59    }
     60  }
     61 
     62  return {
     63    start: starttime,
     64    end: endtime,
     65    numResources: newCount,
     66  };
     67 }
     68 
     69 async function test(context, commands) {
     70  let rootUrl = "https://lucaspardue.com/quictilesfetch.html";
     71  let cycles = 5;
     72 
     73  if (
     74    (typeof context.options.browsertime !== "undefined") &
     75    (typeof context.options.browsertime.cycles !== "undefined")
     76  ) {
     77    cycles = context.options.browsertime.cycles;
     78  }
     79 
     80  // Make firefox learn of HTTP/3 server
     81  // XXX: Need to build an HTTP/3-specific conditioned profile
     82  // to handle these pre-navigations.
     83  await commands.navigate(rootUrl);
     84 
     85  let combos = [
     86    [100, 1],
     87    [100, 100],
     88    [300, 300],
     89  ];
     90  for (let cycle = 0; cycle < cycles; cycle++) {
     91    for (let combo = 0; combo < combos.length; combo++) {
     92      await commands.measure.start("pageload");
     93      await commands.navigate(rootUrl);
     94      await commands.measure.stop();
     95      let last = commands.measure.result.length - 1;
     96      commands.measure.result[last].browserScripts.pageinfo.url =
     97        `LucasQUIC (r=${combos[combo][0]}, p=${combos[combo][1]})`;
     98 
     99      // Set the input fields
    100      await commands.js.runAndWait(`
    101        document.querySelector("#maxReq").setAttribute(
    102          "value",
    103          ${combos[combo][0]}
    104        )
    105      `);
    106      await commands.js.runAndWait(`
    107        document.querySelector("#reqGroup").setAttribute(
    108          "value",
    109          ${combos[combo][1]}
    110        )
    111      `);
    112 
    113      // Start the test and wait for the images to finish loading
    114      commands.click.byJs(`document.querySelector("button")`);
    115      let results = await waitForImgLoadEnd(0, 40, 120000, commands, context);
    116 
    117      commands.measure.result[last].browserScripts.pageinfo.resourceLoadTime =
    118        results.end - results.start;
    119      commands.measure.result[last].browserScripts.pageinfo.imagesLoaded =
    120        results.numResources;
    121      commands.measure.result[last].browserScripts.pageinfo.imagesMissed =
    122        combos[combo][0] - results.numResources;
    123    }
    124  }
    125 }
    126 
    127 module.exports = {
    128  test,
    129  owner: "Network Team",
    130  name: "lq-fetch",
    131  component: "netwerk",
    132  description: "Measures the amount of time it takes to load a set of images.",
    133 };