summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/performance-new/test/xpcshell
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/performance-new/test/xpcshell')
-rw-r--r--devtools/client/performance-new/test/xpcshell/.eslintrc.js6
-rw-r--r--devtools/client/performance-new/test/xpcshell/head.js12
-rw-r--r--devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js106
-rw-r--r--devtools/client/performance-new/test/xpcshell/test_remove_common_path_prefix.js121
-rw-r--r--devtools/client/performance-new/test/xpcshell/test_webchannel-urls.js63
-rw-r--r--devtools/client/performance-new/test/xpcshell/xpcshell.ini8
6 files changed, 316 insertions, 0 deletions
diff --git a/devtools/client/performance-new/test/xpcshell/.eslintrc.js b/devtools/client/performance-new/test/xpcshell/.eslintrc.js
new file mode 100644
index 0000000000..b6aacf458f
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ // Extend from the shared list of defined globals for xpcshell tests.
+ extends: "../../../../.eslintrc.xpcshell.js",
+};
diff --git a/devtools/client/performance-new/test/xpcshell/head.js b/devtools/client/performance-new/test/xpcshell/head.js
new file mode 100644
index 0000000000..83812e9dc1
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/head.js
@@ -0,0 +1,12 @@
+/* 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/. */
+"use strict";
+
+registerCleanupFunction(() => {
+ // Always clean up the prefs after every test.
+ const { revertRecordingSettings } = ChromeUtils.import(
+ "resource://devtools/client/performance-new/shared/background.jsm.js"
+ );
+ revertRecordingSettings();
+});
diff --git a/devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js b/devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js
new file mode 100644
index 0000000000..821d9af2c2
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js
@@ -0,0 +1,106 @@
+/* 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/. */
+"use strict";
+
+/**
+ * Tests the initial state of the background script for the popup.
+ */
+
+function setupBackgroundJsm() {
+ return ChromeUtils.import(
+ "resource://devtools/client/performance-new/shared/background.jsm.js"
+ );
+}
+
+add_task(function test() {
+ info("Test that we get the default preference values from the browser.");
+ const { getRecordingSettings } = setupBackgroundJsm();
+
+ const preferences = getRecordingSettings(
+ "aboutprofiling",
+ Services.profiler.GetFeatures()
+ );
+
+ Assert.notEqual(
+ preferences.entries,
+ undefined,
+ "The initial state has the default entries."
+ );
+ Assert.notEqual(
+ preferences.interval,
+ undefined,
+ "The initial state has the default interval."
+ );
+ Assert.notEqual(
+ preferences.features,
+ undefined,
+ "The initial state has the default features."
+ );
+ Assert.equal(
+ preferences.features.includes("js"),
+ true,
+ "The js feature is initialized to the default."
+ );
+ Assert.notEqual(
+ preferences.threads,
+ undefined,
+ "The initial state has the default threads."
+ );
+ Assert.equal(
+ preferences.threads.includes("GeckoMain"),
+ true,
+ "The GeckoMain thread is initialized to the default."
+ );
+ Assert.notEqual(
+ preferences.objdirs,
+ undefined,
+ "The initial state has the default objdirs."
+ );
+ Assert.notEqual(
+ preferences.duration,
+ undefined,
+ "The duration is initialized to the duration."
+ );
+});
+
+add_task(function test() {
+ info(
+ "Test that the state and features are properly validated. This ensures that as " +
+ "we add and remove features, the stored preferences do not cause the Gecko " +
+ "Profiler interface to crash with invalid values."
+ );
+ const { getRecordingSettings, setRecordingSettings, changePreset } =
+ setupBackgroundJsm();
+
+ const supportedFeatures = Services.profiler.GetFeatures();
+
+ changePreset("aboutprofiling", "custom", supportedFeatures);
+
+ Assert.ok(
+ getRecordingSettings("aboutprofiling", supportedFeatures).features.includes(
+ "js"
+ ),
+ "The js preference is present initially."
+ );
+
+ const settings = getRecordingSettings("aboutprofiling", supportedFeatures);
+ settings.features = settings.features.filter(feature => feature !== "js");
+ settings.features.push("UNKNOWN_FEATURE_FOR_TESTS");
+ setRecordingSettings("aboutprofiling", settings);
+
+ Assert.ok(
+ !getRecordingSettings(
+ "aboutprofiling",
+ supportedFeatures
+ ).features.includes("UNKNOWN_FEATURE_FOR_TESTS"),
+ "The unknown feature is removed."
+ );
+ Assert.ok(
+ !getRecordingSettings(
+ "aboutprofiling",
+ supportedFeatures
+ ).features.includes("js"),
+ "The js preference is still flipped from the default."
+ );
+});
diff --git a/devtools/client/performance-new/test/xpcshell/test_remove_common_path_prefix.js b/devtools/client/performance-new/test/xpcshell/test_remove_common_path_prefix.js
new file mode 100644
index 0000000000..563f0c43b4
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/test_remove_common_path_prefix.js
@@ -0,0 +1,121 @@
+/* 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/. */
+
+"use strict";
+
+const { require } = ChromeUtils.importESModule(
+ "resource://devtools/shared/loader/Loader.sys.mjs"
+);
+const {
+ withCommonPathPrefixRemoved,
+} = require("resource://devtools/client/performance-new/shared/utils.js");
+
+add_task(function test() {
+ info(
+ "withCommonPathPrefixRemoved() removes the common prefix from an array " +
+ "of paths. This test ensures that the paths are correctly removed."
+ );
+
+ if (Services.appinfo.OS === "WINNT") {
+ info("Check Windows paths");
+
+ deepEqual(withCommonPathPrefixRemoved([]), [], "Windows empty paths");
+
+ deepEqual(
+ withCommonPathPrefixRemoved(["source\\file1.js", "source\\file2.js"]),
+ ["source\\file1.js", "source\\file2.js"],
+ "Windows relative paths"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
+ "D:\\Users\\SomeUser\\Desktop\\source\\file2.js",
+ ]),
+ [
+ "C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
+ "D:\\Users\\SomeUser\\Desktop\\source\\file2.js",
+ ],
+ "Windows multiple disks"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
+ "C:\\Users\\SomeUser\\Desktop\\source\\file2.js",
+ ]),
+ ["file1.js", "file2.js"],
+ "Windows full path match"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
+ "C:\\Users\\SomeUser\\file2.js",
+ ]),
+ ["Desktop\\source\\file1.js", "file2.js"],
+ "Windows path match at level 3"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
+ "C:\\Users\\SomeUser\\file2.js",
+ "C:\\Users\\file3.js",
+ ]),
+ ["SomeUser\\Desktop\\source\\file1.js", "SomeUser\\file2.js", "file3.js"],
+ "Windows path match at level 2"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved(["C:\\dev"]),
+ ["C:\\dev"],
+ "Windows path match at level 1"
+ );
+ } else {
+ info("Check UNIX paths");
+
+ deepEqual(withCommonPathPrefixRemoved([]), [], "UNIX empty paths");
+
+ deepEqual(
+ withCommonPathPrefixRemoved(["source/file1.js", "source/file2.js"]),
+ ["source/file1.js", "source/file2.js"],
+ "UNIX relative paths"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "/home/someuser/Desktop/source/file1.js",
+ "/home/someuser/Desktop/source/file2.js",
+ ]),
+ ["file1.js", "file2.js"],
+ "UNIX full path match"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "/home/someuser/Desktop/source/file1.js",
+ "/home/someuser/file2.js",
+ ]),
+ ["Desktop/source/file1.js", "file2.js"],
+ "UNIX path match at level 3"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved([
+ "/home/someuser/Desktop/source/file1.js",
+ "/home/someuser/file2.js",
+ "/home/file3.js",
+ ]),
+ ["someuser/Desktop/source/file1.js", "someuser/file2.js", "file3.js"],
+ "UNIX path match at level 2"
+ );
+
+ deepEqual(
+ withCommonPathPrefixRemoved(["/bin"]),
+ ["/bin"],
+ "UNIX path match at level 1"
+ );
+ }
+});
diff --git a/devtools/client/performance-new/test/xpcshell/test_webchannel-urls.js b/devtools/client/performance-new/test/xpcshell/test_webchannel-urls.js
new file mode 100644
index 0000000000..0c1a03eb0e
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/test_webchannel-urls.js
@@ -0,0 +1,63 @@
+/* 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/. */
+
+"use strict";
+
+const { validateProfilerWebChannelUrl } = ChromeUtils.importESModule(
+ "resource:///modules/DevToolsStartup.sys.mjs"
+);
+
+add_task(function test() {
+ info(
+ "Since the WebChannel can communicate with a content page, test that only " +
+ "trusted URLs can be used with this mechanism."
+ );
+
+ const { checkUrlIsValid, checkUrlIsInvalid } = setup();
+
+ info("Check all of the valid URLs");
+ checkUrlIsValid("https://profiler.firefox.com");
+ checkUrlIsValid("http://example.com");
+ checkUrlIsValid("http://localhost:4242");
+ checkUrlIsValid("http://localhost:32343434");
+ checkUrlIsValid("http://localhost:4242/");
+ checkUrlIsValid("https://deploy-preview-1234--perf-html.netlify.com");
+ checkUrlIsValid("https://deploy-preview-1234--perf-html.netlify.com/");
+ checkUrlIsValid("https://deploy-preview-1234--perf-html.netlify.app");
+ checkUrlIsValid("https://deploy-preview-1234--perf-html.netlify.app/");
+ checkUrlIsValid("https://main--perf-html.netlify.app/");
+
+ info("Check all of the invalid URLs");
+ checkUrlIsInvalid("https://profiler.firefox.com/some-other-path");
+ checkUrlIsInvalid("http://localhost:4242/some-other-path");
+ checkUrlIsInvalid("http://profiler.firefox.com.example.com");
+ checkUrlIsInvalid("http://mozilla.com");
+ checkUrlIsInvalid("https://deploy-preview-1234--perf-html.netlify.dev");
+ checkUrlIsInvalid("https://anything--perf-html.netlify.app/");
+});
+
+function setup() {
+ function checkUrlIsValid(url) {
+ info(`Check that ${url} is valid`);
+ equal(
+ validateProfilerWebChannelUrl(url),
+ url,
+ `"${url}" is a valid WebChannel URL.`
+ );
+ }
+
+ function checkUrlIsInvalid(url) {
+ info(`Check that ${url} is invalid`);
+ equal(
+ validateProfilerWebChannelUrl(url),
+ "https://profiler.firefox.com",
+ `"${url}" was not valid, and was reset to the base URL.`
+ );
+ }
+
+ return {
+ checkUrlIsValid,
+ checkUrlIsInvalid,
+ };
+}
diff --git a/devtools/client/performance-new/test/xpcshell/xpcshell.ini b/devtools/client/performance-new/test/xpcshell/xpcshell.ini
new file mode 100644
index 0000000000..b609fdf3d9
--- /dev/null
+++ b/devtools/client/performance-new/test/xpcshell/xpcshell.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+tags = devtools
+head = head.js
+firefox-appdir = browser
+
+[test_popup_initial_state.js]
+[test_remove_common_path_prefix.js]
+[test_webchannel-urls.js]