mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
Bug 1579530 - Validate the popup preferences; r=julienw
Differential Revision: https://phabricator.services.mozilla.com/D45077 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
34f0900f51
commit
e6f2eda3d9
@ -17,6 +17,7 @@ DevToolsModules(
|
||||
)
|
||||
|
||||
MOCHITEST_CHROME_MANIFESTS += ['test/chrome/chrome.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini']
|
||||
|
||||
with Files('**'):
|
||||
BUG_COMPONENT = ('DevTools', 'Performance Tools (Profiler/Timeline)')
|
||||
|
@ -37,6 +37,10 @@ loader.lazyRequireGetter(
|
||||
// a string key based off of the debug name and breakpad id.
|
||||
const PROFILER_STATE_PREF = "devtools.performance.popup";
|
||||
const DEFAULT_WINDOW_LENGTH = 20; // 20sec
|
||||
const DEFAULT_INTERVAL = 1; // 1ms
|
||||
const DEFAULT_BUFFER_SIZE = 10000000; // 90MB
|
||||
const DEFAULT_THREADS = "GeckoMain,Compositor";
|
||||
const DEFAULT_STACKWALK_FEATURE = true;
|
||||
|
||||
// This Map caches the symbols from the shared libraries.
|
||||
const symbolCache = new Map();
|
||||
@ -47,7 +51,20 @@ const primeSymbolStore = libs => {
|
||||
}
|
||||
};
|
||||
|
||||
const state = intializeState();
|
||||
const state = initializeState();
|
||||
|
||||
const forTestsOnly = {
|
||||
DEFAULT_BUFFER_SIZE,
|
||||
DEFAULT_STACKWALK_FEATURE,
|
||||
initializeState,
|
||||
adjustState,
|
||||
getState() {
|
||||
return state;
|
||||
},
|
||||
revertPrefs() {
|
||||
Services.prefs.clearUserPref(PROFILER_STATE_PREF);
|
||||
},
|
||||
};
|
||||
|
||||
function adjustState(newState) {
|
||||
// Deep clone the object, since this can be called through popup.xhtml,
|
||||
@ -320,12 +337,7 @@ function setRecordingPreferencesOnBrowser(settings) {
|
||||
);
|
||||
}
|
||||
|
||||
function intializeState() {
|
||||
const storedState = getStoredStateOrNull();
|
||||
if (storedState) {
|
||||
return storedState;
|
||||
}
|
||||
|
||||
function initializeState() {
|
||||
const features = {
|
||||
java: false,
|
||||
js: true,
|
||||
@ -335,7 +347,7 @@ function intializeState() {
|
||||
responsiveness: true,
|
||||
screenshots: false,
|
||||
seqstyle: false,
|
||||
stackwalk: true,
|
||||
stackwalk: DEFAULT_STACKWALK_FEATURE,
|
||||
tasktracer: false,
|
||||
trackopts: false,
|
||||
jstracer: false,
|
||||
@ -348,14 +360,47 @@ function intializeState() {
|
||||
features.java = true;
|
||||
}
|
||||
|
||||
const storedState = getStoredStateOrNull();
|
||||
|
||||
if (storedState && storedState.features) {
|
||||
const storedFeatures = storedState.features;
|
||||
// Validate the stored state. It's possible a feature was added or removed
|
||||
// since the profiler was last run.
|
||||
for (const key of Object.keys(features)) {
|
||||
features[key] =
|
||||
key in storedFeatures ? Boolean(storedFeatures[key]) : features[key];
|
||||
}
|
||||
}
|
||||
|
||||
// This function is created inline to make it easy to validate
|
||||
// the stored state using the captured storedState value.
|
||||
function validateStoredState(key, type, defaultValue) {
|
||||
if (!storedState) {
|
||||
return defaultValue;
|
||||
}
|
||||
const storedValue = storedState[key];
|
||||
return typeof storedValue === type ? storedValue : defaultValue;
|
||||
}
|
||||
|
||||
return {
|
||||
isRunning: false,
|
||||
// These values are stale, and need to be re-generated.
|
||||
isRunning: Services.profiler.IsActive(),
|
||||
settingsOpen: false,
|
||||
buffersize: 10000000, // 90MB
|
||||
windowLength: DEFAULT_WINDOW_LENGTH,
|
||||
interval: 1,
|
||||
features,
|
||||
threads: "GeckoMain,Compositor",
|
||||
|
||||
// Look these up from stored state.
|
||||
buffersize: validateStoredState(
|
||||
"buffersize",
|
||||
"number",
|
||||
DEFAULT_BUFFER_SIZE
|
||||
),
|
||||
windowLength: validateStoredState(
|
||||
"windowLength",
|
||||
"number",
|
||||
DEFAULT_WINDOW_LENGTH
|
||||
),
|
||||
interval: validateStoredState("interval", "number", DEFAULT_INTERVAL),
|
||||
threads: validateStoredState("threads", "string", DEFAULT_THREADS),
|
||||
};
|
||||
}
|
||||
|
||||
@ -377,4 +422,5 @@ var EXPORTED_SYMBOLS = [
|
||||
"platform",
|
||||
"getRecordingPreferencesFromBrowser",
|
||||
"setRecordingPreferencesOnBrowser",
|
||||
"forTestsOnly",
|
||||
];
|
||||
|
3
devtools/client/performance-new/test/xpcshell/head.js
Normal file
3
devtools/client/performance-new/test/xpcshell/head.js
Normal file
@ -0,0 +1,3 @@
|
||||
/* 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/. */
|
@ -0,0 +1,67 @@
|
||||
/* 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() {
|
||||
const background = ChromeUtils.import(
|
||||
"resource://devtools/client/performance-new/popup/background.jsm"
|
||||
);
|
||||
return background;
|
||||
}
|
||||
|
||||
add_task(function test() {
|
||||
info("Test that we get the default values from state.");
|
||||
const {
|
||||
getState,
|
||||
revertPrefs,
|
||||
DEFAULT_BUFFER_SIZE,
|
||||
DEFAULT_STACKWALK_FEATURE,
|
||||
} = setupBackgroundJsm().forTestsOnly;
|
||||
|
||||
Assert.equal(
|
||||
getState().buffersize,
|
||||
DEFAULT_BUFFER_SIZE,
|
||||
"The initial state has the default buffersize."
|
||||
);
|
||||
Assert.equal(
|
||||
getState().features.stackwalk,
|
||||
DEFAULT_STACKWALK_FEATURE,
|
||||
"The stackwalk feature is initialized to the default."
|
||||
);
|
||||
revertPrefs();
|
||||
});
|
||||
|
||||
add_task(function test() {
|
||||
info("Test that the state and features are properly validated.");
|
||||
const {
|
||||
getState,
|
||||
adjustState,
|
||||
revertPrefs,
|
||||
initializeState,
|
||||
DEFAULT_STACKWALK_FEATURE,
|
||||
} = setupBackgroundJsm().forTestsOnly;
|
||||
|
||||
info("Manipulate the state.");
|
||||
const state = getState();
|
||||
state.features.stackwalk = !DEFAULT_STACKWALK_FEATURE;
|
||||
state.features.UNKNOWN_FEATURE_FOR_TESTS = true;
|
||||
adjustState(state);
|
||||
adjustState(initializeState());
|
||||
|
||||
Assert.equal(
|
||||
getState().features.UNKNOWN_FEATURE_FOR_TESTS,
|
||||
undefined,
|
||||
"The unknown feature is removed."
|
||||
);
|
||||
Assert.equal(
|
||||
getState().features.stackwalk,
|
||||
!DEFAULT_STACKWALK_FEATURE,
|
||||
"The stackwalk preference is still flipped from the default."
|
||||
);
|
||||
revertPrefs();
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
[DEFAULT]
|
||||
tags = devtools
|
||||
head = head.js
|
||||
firefox-appdir = browser
|
||||
|
||||
[test_popup_initial_state.js]
|
Loading…
Reference in New Issue
Block a user