summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/helpers/prefs.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/performance/test/helpers/prefs.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/performance/test/helpers/prefs.js')
-rw-r--r--devtools/client/performance/test/helpers/prefs.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/devtools/client/performance/test/helpers/prefs.js b/devtools/client/performance/test/helpers/prefs.js
new file mode 100644
index 000000000..4d17afe12
--- /dev/null
+++ b/devtools/client/performance/test/helpers/prefs.js
@@ -0,0 +1,72 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+const Services = require("Services");
+const { Preferences } = require("resource://gre/modules/Preferences.jsm");
+
+// Prefs to revert to default once tests finish. Keep these in sync with
+// all the preferences defined in devtools/client/preferences/devtools.js.
+exports.MEMORY_SAMPLE_PROB_PREF = "devtools.performance.memory.sample-probability";
+exports.MEMORY_MAX_LOG_LEN_PREF = "devtools.performance.memory.max-log-length";
+exports.PROFILER_BUFFER_SIZE_PREF = "devtools.performance.profiler.buffer-size";
+exports.PROFILER_SAMPLE_RATE_PREF = "devtools.performance.profiler.sample-frequency-khz";
+
+exports.UI_EXPERIMENTAL_PREF = "devtools.performance.ui.experimental";
+exports.UI_INVERT_CALL_TREE_PREF = "devtools.performance.ui.invert-call-tree";
+exports.UI_INVERT_FLAME_PREF = "devtools.performance.ui.invert-flame-graph";
+exports.UI_FLATTEN_RECURSION_PREF = "devtools.performance.ui.flatten-tree-recursion";
+exports.UI_SHOW_PLATFORM_DATA_PREF = "devtools.performance.ui.show-platform-data";
+exports.UI_SHOW_IDLE_BLOCKS_PREF = "devtools.performance.ui.show-idle-blocks";
+exports.UI_ENABLE_FRAMERATE_PREF = "devtools.performance.ui.enable-framerate";
+exports.UI_ENABLE_MEMORY_PREF = "devtools.performance.ui.enable-memory";
+exports.UI_ENABLE_ALLOCATIONS_PREF = "devtools.performance.ui.enable-allocations";
+exports.UI_ENABLE_MEMORY_FLAME_CHART = "devtools.performance.ui.enable-memory-flame";
+
+exports.DEFAULT_PREF_VALUES = [
+ "devtools.debugger.log",
+ "devtools.performance.enabled",
+ "devtools.performance.timeline.hidden-markers",
+ exports.MEMORY_SAMPLE_PROB_PREF,
+ exports.MEMORY_MAX_LOG_LEN_PREF,
+ exports.PROFILER_BUFFER_SIZE_PREF,
+ exports.PROFILER_SAMPLE_RATE_PREF,
+ exports.UI_EXPERIMENTAL_PREF,
+ exports.UI_INVERT_CALL_TREE_PREF,
+ exports.UI_INVERT_FLAME_PREF,
+ exports.UI_FLATTEN_RECURSION_PREF,
+ exports.UI_SHOW_PLATFORM_DATA_PREF,
+ exports.UI_SHOW_IDLE_BLOCKS_PREF,
+ exports.UI_ENABLE_FRAMERATE_PREF,
+ exports.UI_ENABLE_MEMORY_PREF,
+ exports.UI_ENABLE_ALLOCATIONS_PREF,
+ exports.UI_ENABLE_MEMORY_FLAME_CHART,
+ "devtools.performance.ui.show-jit-optimizations",
+ "devtools.performance.ui.show-triggers-for-gc-types",
+].reduce((prefValues, prefName) => {
+ prefValues[prefName] = Preferences.get(prefName);
+ return prefValues;
+}, {});
+
+/**
+ * Invokes callback when a pref which is not in the `DEFAULT_PREF_VALUES` store
+ * is changed. Returns a cleanup function.
+ */
+exports.whenUnknownPrefChanged = function (branch, callback) {
+ function onObserve(subject, topic, data) {
+ if (!(data in exports.DEFAULT_PREF_VALUES)) {
+ callback(data);
+ }
+ }
+ Services.prefs.addObserver(branch, onObserve, false);
+ return () => Services.prefs.removeObserver(branch, onObserve);
+};
+
+/**
+ * Reverts all known preferences to their default values.
+ */
+exports.rollbackPrefsToDefault = function () {
+ for (let prefName of Object.keys(exports.DEFAULT_PREF_VALUES)) {
+ Preferences.set(prefName, exports.DEFAULT_PREF_VALUES[prefName]);
+ }
+};