summaryrefslogtreecommitdiffstats
path: root/testing/raptor/browsertime/upload.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/upload.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/upload.js')
-rw-r--r--testing/raptor/browsertime/upload.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/testing/raptor/browsertime/upload.js b/testing/raptor/browsertime/upload.js
new file mode 100644
index 0000000000..4f46ba0f50
--- /dev/null
+++ b/testing/raptor/browsertime/upload.js
@@ -0,0 +1,86 @@
+/* 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 */
+
+const path = require("path");
+
+async function waitForUpload(timeout, commands, context) {
+ let starttime = await commands.js.run(`return performance.now();`);
+ let status = "";
+
+ while (
+ (await commands.js.run(`return performance.now();`)) - starttime <
+ timeout &&
+ status != "error" &&
+ status != "success"
+ ) {
+ await commands.wait.byTime(10);
+
+ status = await commands.js.run(
+ `return document.getElementById('upload_status').innerHTML;`
+ );
+
+ context.log.info("context.log test: " + status);
+ console.log("test: " + status);
+ }
+
+ let endtime = await commands.js.run(`return performance.now();`);
+
+ return {
+ start: starttime,
+ end: endtime,
+ upload_status: status,
+ };
+}
+
+module.exports = async function (context, commands) {
+ let uploadSiteUrl = "https://uploadtest-381620.uc.r.appspot.com";
+ let iterations = `${context.options.browsertime.upload_iterations}`;
+
+ await commands.measure.start(uploadSiteUrl);
+ let accumulatedResults = [];
+ for (let iteration = 0; iteration < iterations; iteration++) {
+ await commands.navigate(uploadSiteUrl);
+
+ const driver = context.selenium.driver;
+ const webdriver = context.selenium.webdriver;
+
+ const uploadItem = await driver.findElement(webdriver.By.id("fileUpload"));
+
+ if (context.options.browsertime.moz_fetch_dir == "None") {
+ context.log.error(
+ "This test depends on the fetch task. Download the file, 'https://github.com/mozilla/perf-automation/raw/master/test_files/upload-test-32MB.dat' and set the os environment variable MOZ_FETCHES_DIR to that directory."
+ );
+ }
+
+ let localFilePath = path.join(
+ `${context.options.browsertime.moz_fetch_dir}`,
+ "upload-test-32MB.dat"
+ );
+
+ context.log.info("Sending file path: " + localFilePath);
+ await uploadItem.sendKeys(localFilePath);
+
+ // Start the test and wait for the upload to complete
+ let results = await waitForUpload(120000, commands, context);
+ let uploadTime = results.end - results.start;
+
+ // Store result in megabit/seconds, (Upload is a 50 MB file)
+ let uploadBandwidth = (50 * 8) / (uploadTime / 1000.0);
+ context.log.info(
+ "upload results: " +
+ results.upload_status +
+ " duration: " +
+ uploadTime +
+ " uploadBandwidth: " +
+ uploadBandwidth
+ );
+ accumulatedResults.push(uploadBandwidth);
+ }
+
+ commands.measure.addObject({
+ custom_data: { "upload-bandwidth": accumulatedResults },
+ });
+};