tor-browser

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

perftest_http3_youtube_watch_scroll.js (2616B)


      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 test(context, commands) {
     12  let rootUrl = "https://www.youtube.com/watch?v=COU5T-Wafa4";
     13  let waitTime = 20000;
     14 
     15  if (
     16    (typeof context.options.browsertime !== "undefined") &
     17    (typeof context.options.browsertime.waitTime !== "undefined")
     18  ) {
     19    waitTime = context.options.browsertime.waitTime;
     20  }
     21 
     22  // Make firefox learn of HTTP/3 server
     23  await commands.navigate(rootUrl);
     24 
     25  let cycles = 1;
     26  for (let cycle = 0; cycle < cycles; cycle++) {
     27    await commands.measure.start("pageload");
     28    await commands.navigate(rootUrl);
     29 
     30    // Make sure the video is running
     31    // XXX: Should we start the video ourself?
     32    if (
     33      await commands.js.run(`return document.querySelector("video").paused;`)
     34    ) {
     35      throw new Error("Video should be running but it's paused");
     36    }
     37 
     38    // Disable youtube autoplay
     39    await commands.click.byIdAndWait("toggleButton");
     40 
     41    // Start playback quality measurements
     42    const start = await commands.js.run(`return performance.now();`);
     43    let counter = 1;
     44    let direction = 0;
     45    while (
     46      !(await commands.js.run(`
     47          return document.querySelector("video").ended;
     48      `)) &
     49      !(await commands.js.run(`
     50          return document.querySelector("video").paused;
     51      `)) &
     52      ((await commands.js.run(`return performance.now();`)) - start < waitTime)
     53    ) {
     54      // Reset the scroll after going down 10 times
     55      direction = counter * 1000;
     56      if (direction > 10000) {
     57        counter = -1;
     58      }
     59      counter++;
     60 
     61      await commands.js.runAndWait(
     62        `window.scrollTo({ top: ${direction}, behavior: 'smooth' })`
     63      );
     64      context.log.info("playing while scrolling...");
     65    }
     66 
     67    // Video done, now gather metrics
     68    const playbackQuality = await commands.js.run(
     69      `return document.querySelector("video").getVideoPlaybackQuality();`
     70    );
     71    await commands.measure.stop();
     72 
     73    commands.measure.result[0].browserScripts.pageinfo.droppedFrames =
     74      playbackQuality.droppedVideoFrames;
     75    commands.measure.result[0].browserScripts.pageinfo.decodedFrames =
     76      playbackQuality.totalVideoFrames;
     77  }
     78 }
     79 
     80 module.exports = {
     81  test,
     82  owner: "Network Team",
     83  component: "netwerk",
     84  name: "youtube-scroll",
     85  description: "Measures quality of the video being played.",
     86 };