tor-browser

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

browsertime_scenario.js (2906B)


      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  "browsertime scenario test",
     11  async function (context, commands) {
     12    context.log.info("Starting a browsertime scenario test");
     13    let page_cycles = context.options.browsertime.page_cycles;
     14    let page_cycle_delay = context.options.browsertime.page_cycle_delay;
     15    let post_startup_delay = context.options.browsertime.post_startup_delay;
     16    let scenario_time = context.options.browsertime.scenario_time;
     17    let background_app = context.options.browsertime.background_app == "true";
     18    let app = null;
     19 
     20    if (background_app) {
     21      if (!context.options.android) {
     22        throw new Error("Cannot background an application on desktop");
     23      }
     24      app = context.options.firefox.android.package;
     25    }
     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 
     47        if (background_app) {
     48          // Background the application and disable doze for it
     49          await commands.android.shell(`dumpsys deviceidle whitelist +${app}`);
     50          await commands.android.shell(`input keyevent 3`);
     51          await commands.wait.byTime(1000);
     52          const foreground = await commands.android.shell(
     53            "dumpsys window windows | grep mCurrentFocus"
     54          );
     55          if (foreground.includes(app)) {
     56            throw new Error("Application was not backgrounded successfully");
     57          } else {
     58            context.log.info("Application was backgrounded successfully");
     59          }
     60        }
     61 
     62        // Run the test
     63        await commands.measure.start("about:blank test");
     64        context.log.info("Waiting for %d ms for this scenario", scenario_time);
     65        await commands.wait.byTime(scenario_time);
     66        await commands.measure.stop();
     67 
     68        if (background_app) {
     69          // Foreground the application and enable doze again
     70          await commands.android.shell(`am start --activity-single-top ${app}`);
     71          await commands.android.shell(`dumpsys deviceidle enable`);
     72        }
     73      });
     74    }
     75    context.log.info("Browsertime scenario test ended.");
     76    return true;
     77  }
     78 );