tor-browser

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

motionmark-1-3.js (4016B)


      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 // index for the CSS selector in developer.html
     10 const suiteSelectorNumber = {
     11  MotionMark: 1,
     12  "HTML suite": 2,
     13 };
     14 
     15 module.exports = logTest(
     16  "MotionMark 1.3 test",
     17  async function (context, commands) {
     18    context.log.info("Starting MotionMark 1.3 test");
     19    let url = context.options.browsertime.url;
     20    let page_cycles = context.options.browsertime.page_cycles;
     21    let suite_name = context.options.browsertime.suite_name;
     22    let page_cycle_delay = context.options.browsertime.page_cycle_delay;
     23    let post_startup_delay = context.options.browsertime.post_startup_delay;
     24    let page_timeout = context.options.timeouts.pageLoad;
     25    let expose_profiler = context.options.browsertime.expose_profiler;
     26 
     27    context.log.info(
     28      "Waiting for %d ms (post_startup_delay)",
     29      post_startup_delay
     30    );
     31    await commands.wait.byTime(post_startup_delay);
     32 
     33    for (let count = 0; count < page_cycles; count++) {
     34      await logTask(context, "cycle " + count, async function () {
     35        context.log.info("Navigating to about:blank");
     36        await commands.navigate("about:blank");
     37 
     38        context.log.info(
     39          "Cycle %d, waiting for %d ms",
     40          count,
     41          page_cycle_delay
     42        );
     43        await commands.wait.byTime(page_cycle_delay);
     44 
     45        context.log.info("Cycle %d, starting the measure", count);
     46        if (expose_profiler === "true") {
     47          context.log.info("Custom profiler start!");
     48          if (context.options.browser === "firefox") {
     49            await commands.profiler.start();
     50          } else if (context.options.browser === "chrome") {
     51            await commands.trace.start();
     52          }
     53        }
     54        await commands.measure.start(url);
     55 
     56        let suite_selector = `#suites > ul > li:nth-child(${suiteSelectorNumber[suite_name]}) > label > input[type="checkbox"]`;
     57 
     58        await commands.mouse.singleClick.bySelector(suite_selector);
     59        await commands.js.runAndWait(`
     60      this.benchmarkController.startBenchmark()
     61    `);
     62 
     63        let data_exists = null;
     64        let starttime = await commands.js.run(`return performance.now();`);
     65        while (
     66          (data_exists == null || !Object.keys(data_exists).length) &&
     67          (await commands.js.run(`return performance.now();`)) - starttime <
     68            page_timeout
     69        ) {
     70          let wait_time = 3000;
     71          context.log.info(
     72            "Waiting %d ms for data from %s...",
     73            wait_time,
     74            suite_name
     75          );
     76          await commands.wait.byTime(wait_time);
     77 
     78          data_exists = await commands.js.run(`
     79        return window.benchmarkRunnerClient.results.data
     80      `);
     81        }
     82 
     83        if (expose_profiler === "true") {
     84          context.log.info("Custom profiler stop!");
     85          if (context.options.browser === "firefox") {
     86            await commands.profiler.stop();
     87          } else if (context.options.browser === "chrome") {
     88            await commands.trace.stop();
     89          }
     90        }
     91        if (
     92          !data_exists &&
     93          (await commands.js.run(`return performance.now();`)) - starttime >=
     94            page_timeout
     95        ) {
     96          context.log.error("Benchmark timed out. Aborting...");
     97          return false;
     98        }
     99 
    100        let data = null;
    101        data = await commands.js.run(`
    102      const score = window.benchmarkRunnerClient.results.score;
    103      const results = window.benchmarkRunnerClient.results.results[0].testsResults;
    104      return {
    105        score,
    106        results,
    107      };
    108    `);
    109        data.suite_name = suite_name;
    110 
    111        commands.measure.addObject({ mm_res: data });
    112        context.log.info("Value of summarized benchmark data: ", data);
    113        return true;
    114      });
    115    }
    116 
    117    return true;
    118  }
    119 );