Bug 1744358 move MediaEngineDefault-specific MediaEngineSource classes out of header...
[gecko.git] / testing / performance / perftest_record.js
blobf513e9837ec52c2873d59bdb1858ac613d509a8e
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 "use strict";
7 async function pageload_test(context, commands) {
8   let testUrl = context.options.browsertime.url;
9   let secondaryUrl = context.options.browsertime.secondary_url;
10   let testName = context.options.browsertime.testName;
12   // Wait for browser to settle
13   await commands.wait.byTime(1000);
15   await commands.measure.start(testUrl);
16   commands.screenshot.take("test_url_" + testName);
18   if (secondaryUrl !== null) {
19     // Wait for browser to settle
20     await commands.wait.byTime(1000);
22     await commands.measure.start(secondaryUrl);
23     commands.screenshot.take("secondary_url_" + testName);
24   }
26   // Wait for browser to settle
27   await commands.wait.byTime(1000);
30 async function get_command_function(cmd, commands) {
31   /*
32   Converts a string such as `measure.start` into the actual
33   function that is found in the `commands` module.
35   XXX: Find a way to share this function between
36   perftest_record.js and browsertime_interactive.js
37   */
38   if (cmd == "") {
39     throw new Error("A blank command was given.");
40   } else if (cmd.endsWith(".")) {
41     throw new Error(
42       "An extra `.` was found at the end of this command: " + cmd
43     );
44   }
46   // `func` will hold the actual method that needs to be called,
47   // and the `parent_mod` is the context required to run the `func`
48   // method. Without that context, `this` becomes undefined in the browsertime
49   // classes.
50   let func = null;
51   let parent_mod = null;
52   for (let func_part of cmd.split(".")) {
53     if (func_part == "") {
54       throw new Error(
55         "An empty function part was found in the command: " + cmd
56       );
57     }
59     if (func === null) {
60       parent_mod = commands;
61       func = commands[func_part];
62     } else if (func !== undefined) {
63       parent_mod = func;
64       func = func[func_part];
65     } else {
66       break;
67     }
68   }
70   if (func == undefined) {
71     throw new Error(
72       "The given command could not be found as a function: " + cmd
73     );
74   }
76   return [func, parent_mod];
79 async function interactive_test(input_cmds, context, commands) {
80   let cmds = input_cmds.split(";;;");
82   await commands.navigate("about:blank");
84   for (let cmdstr of cmds) {
85     let [cmd, ...args] = cmdstr.split(":::");
86     let [func, parent_mod] = await get_command_function(cmd, commands);
88     try {
89       await func.call(parent_mod, ...args);
90     } catch (e) {
91       context.log.info(
92         `Exception found while running \`commands.${cmd}(${args})\`: ` + e
93       );
94     }
95   }
98 async function test(context, commands) {
99   let input_cmds = context.options.browsertime.commands;
100   if (input_cmds) {
101     await interactive_test(input_cmds, context, commands);
102   } else {
103     await pageload_test(context, commands);
104   }
105   return true;
108 module.exports = {
109   test,
110   owner: "Bebe fstrugariu@mozilla.com",
111   name: "Mozproxy recording generator",
112   component: "raptor",
113   description: ` This test generates fresh MozProxy recordings. It iterates through a list of 
114       websites provided in *_sites.json and for each one opens a browser and 
115       records all the associated HTTP traffic`,
116   usage:
117     "mach perftest --proxy --hooks testing/raptor/recorder/hooks.py testing/raptor/recorder/perftest_record.js",