summaryrefslogtreecommitdiffstats
path: root/testing/raptor/browsertime/browsertime_scenario.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/raptor/browsertime/browsertime_scenario.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/raptor/browsertime/browsertime_scenario.js')
-rw-r--r--testing/raptor/browsertime/browsertime_scenario.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/testing/raptor/browsertime/browsertime_scenario.js b/testing/raptor/browsertime/browsertime_scenario.js
new file mode 100644
index 0000000000..3abf0d142b
--- /dev/null
+++ b/testing/raptor/browsertime/browsertime_scenario.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* eslint-env node */
+
+module.exports = async function (context, commands) {
+ context.log.info("Starting a browsertime scenario test");
+ let page_cycles = context.options.browsertime.page_cycles;
+ let page_cycle_delay = context.options.browsertime.page_cycle_delay;
+ let post_startup_delay = context.options.browsertime.post_startup_delay;
+ let scenario_time = context.options.browsertime.scenario_time;
+ let background_app = context.options.browsertime.background_app == "true";
+ let app = null;
+
+ if (background_app) {
+ if (!context.options.android) {
+ throw new Error("Cannot background an application on desktop");
+ }
+ app = context.options.firefox.android.package;
+ }
+
+ context.log.info(
+ "Waiting for %d ms (post_startup_delay)",
+ post_startup_delay
+ );
+ await commands.wait.byTime(post_startup_delay);
+
+ for (let count = 0; count < page_cycles; count++) {
+ context.log.info("Navigating to about:blank");
+ await commands.navigate("about:blank");
+
+ context.log.info("Cycle %d, waiting for %d ms", count, page_cycle_delay);
+ await commands.wait.byTime(page_cycle_delay);
+
+ context.log.info("Cycle %d, starting the measure", count);
+
+ if (background_app) {
+ // Background the application and disable doze for it
+ await commands.android.shell(`dumpsys deviceidle whitelist +${app}`);
+ await commands.android.shell(`input keyevent 3`);
+ await commands.wait.byTime(1000);
+ const foreground = await commands.android.shell(
+ "dumpsys window windows | grep mCurrentFocus"
+ );
+ if (foreground.includes(app)) {
+ throw new Error("Application was not backgrounded successfully");
+ } else {
+ context.log.info("Application was backgrounded successfully");
+ }
+ }
+
+ // Run the test
+ await commands.measure.start("about:blank test");
+ context.log.info("Waiting for %d ms for this scenario", scenario_time);
+ await commands.wait.byTime(scenario_time);
+ await commands.measure.stop();
+
+ if (background_app) {
+ // Foreground the application and enable doze again
+ await commands.android.shell(`am start --activity-single-top ${app}`);
+ await commands.android.shell(`dumpsys deviceidle enable`);
+ }
+ }
+ context.log.info("Browsertime scenario test ended.");
+ return true;
+};