summaryrefslogtreecommitdiffstats
path: root/testing/raptor/browsertime/browsertime_interactive.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_interactive.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_interactive.js')
-rw-r--r--testing/raptor/browsertime/browsertime_interactive.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/testing/raptor/browsertime/browsertime_interactive.js b/testing/raptor/browsertime/browsertime_interactive.js
new file mode 100644
index 0000000000..20ce23ccf1
--- /dev/null
+++ b/testing/raptor/browsertime/browsertime_interactive.js
@@ -0,0 +1,103 @@
+/* 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 */
+
+async function get_command_function(cmd, commands) {
+ /*
+ Converts a string such as `measure.start` into the actual
+ function that is found in the `commands` module.
+
+ XXX: Find a way to share this function between
+ perftest_record.js and browsertime_interactive.js
+ */
+ if (cmd == "") {
+ throw new Error("A blank command was given.");
+ } else if (cmd.endsWith(".")) {
+ throw new Error(
+ "An extra `.` was found at the end of this command: " + cmd
+ );
+ }
+
+ // `func` will hold the actual method that needs to be called,
+ // and the `parent_mod` is the context required to run the `func`
+ // method. Without that context, `this` becomes undefined in the browsertime
+ // classes.
+ let func = null;
+ let parent_mod = null;
+ for (let func_part of cmd.split(".")) {
+ if (func_part == "") {
+ throw new Error(
+ "An empty function part was found in the command: " + cmd
+ );
+ }
+
+ if (func === null) {
+ parent_mod = commands;
+ func = commands[func_part];
+ } else if (func !== undefined) {
+ parent_mod = func;
+ func = func[func_part];
+ } else {
+ break;
+ }
+ }
+
+ if (func == undefined) {
+ throw new Error(
+ "The given command could not be found as a function: " + cmd
+ );
+ }
+
+ return [func, parent_mod];
+}
+
+module.exports = async function (context, commands) {
+ context.log.info("Starting an interactive browsertime test");
+ let page_cycles = context.options.browsertime.page_cycles;
+ let post_startup_delay = context.options.browsertime.post_startup_delay;
+ let input_cmds = context.options.browsertime.commands;
+
+ context.log.info(
+ "Waiting for %d ms (post_startup_delay)",
+ post_startup_delay
+ );
+ await commands.wait.byTime(post_startup_delay);
+
+ // unpack commands from python
+ let cmds = input_cmds.split(";;;");
+
+ for (let count = 0; count < page_cycles; count++) {
+ context.log.info("Navigating to about:blank w/nav, count: " + count);
+ await commands.navigate("about:blank");
+
+ let pages_visited = [];
+ for (let cmdstr of cmds) {
+ let [cmd, ...args] = cmdstr.split(":::");
+
+ if (cmd == "measure.start") {
+ if (args[0] != "") {
+ pages_visited.push(args[0]);
+ }
+ }
+
+ let [func, parent_mod] = await get_command_function(cmd, commands);
+
+ try {
+ await func.call(parent_mod, ...args);
+ } catch (e) {
+ context.log.info(
+ `Exception found while running \`commands.${cmd}(${args})\`: `
+ );
+ context.log.info(e.stack);
+ }
+ }
+
+ // Log the number of pages visited for results parsing
+ context.log.info("[] metrics: pages_visited: " + pages_visited);
+ }
+
+ context.log.info("Browsertime pageload ended.");
+ return true;
+};