summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js')
-rw-r--r--devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js106
1 files changed, 106 insertions, 0 deletions
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."
+ );
+});