зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1366823 - add Scratchpad manager APIs to DevToolsShim;r=ochameau
MozReview-Commit-ID: 5JsSu9Spkgn --HG-- extra : rebase_source : 83d93d5168ddb7f4310543ff6d12e0f809d3db87 extra : source : 62e2f83b5992f2117caf4a7f76202437ce6e3d16
This commit is contained in:
Родитель
a680529295
Коммит
e7209cfe2e
|
@ -14,6 +14,7 @@ loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/targe
|
|||
loader.lazyRequireGetter(this, "Toolbox", "devtools/client/framework/toolbox", true);
|
||||
loader.lazyRequireGetter(this, "ToolboxHostManager", "devtools/client/framework/toolbox-host-manager", true);
|
||||
loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
|
||||
loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
|
||||
|
||||
const {defaultTools: DefaultTools, defaultThemes: DefaultThemes} =
|
||||
require("devtools/client/definitions");
|
||||
|
@ -394,6 +395,27 @@ DevTools.prototype = {
|
|||
return definitions.sort(this.ordinalSort);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the array of currently opened scratchpad windows.
|
||||
*
|
||||
* @return {Array} array of currently opened scratchpad windows.
|
||||
* Empty array if the scratchpad manager is not loaded.
|
||||
*/
|
||||
getOpenedScratchpads: function () {
|
||||
// Check if the module is loaded to avoid loading ScratchpadManager for no reason.
|
||||
if (!Cu.isModuleLoaded("resource://devtools/client/scratchpad/scratchpad-manager.jsm")) {
|
||||
return [];
|
||||
}
|
||||
return ScratchpadManager.getSessionState();
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore the provided array of scratchpad window states.
|
||||
*/
|
||||
restoreScratchpadSession: function (scratchpads) {
|
||||
ScratchpadManager.restoreSession(scratchpads);
|
||||
},
|
||||
|
||||
/**
|
||||
* Show a Toolbox for a target (either by creating a new one, or if a toolbox
|
||||
* already exists for the target, by bring to the front the existing one)
|
||||
|
@ -540,9 +562,14 @@ DevTools.prototype = {
|
|||
|
||||
removeThemeObserver(this._onThemeChanged);
|
||||
|
||||
// Notify the DevToolsShim that DevTools are no longer available, particularly if the
|
||||
// destroy was caused by disabling/removing the DevTools add-on.
|
||||
DevToolsShim.unregister();
|
||||
// Do not unregister devtools from the DevToolsShim if the destroy is caused by an
|
||||
// application shutdown. For instance SessionStore needs to save the Scratchpad
|
||||
// manager state on shutdown.
|
||||
if (!shuttingDown) {
|
||||
// Notify the DevToolsShim that DevTools are no longer available, particularly if
|
||||
// the destroy was caused by disabling/removing the DevTools add-on.
|
||||
DevToolsShim.unregister();
|
||||
}
|
||||
|
||||
// Cleaning down the toolboxes: i.e.
|
||||
// for (let [target, toolbox] of this._toolboxes) toolbox.destroy();
|
||||
|
|
|
@ -153,6 +153,30 @@ this.DevToolsShim = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Called from SessionStore.jsm in mozilla-central when saving the current state.
|
||||
*
|
||||
* @return {Array} array of currently opened scratchpad windows. Empty array if devtools
|
||||
* are not installed
|
||||
*/
|
||||
getOpenedScratchpads: function () {
|
||||
if (!this.isInstalled()) {
|
||||
return [];
|
||||
}
|
||||
return this.gDevTools.getOpenedScratchpads();
|
||||
},
|
||||
|
||||
/**
|
||||
* Called from SessionStore.jsm in mozilla-central when restoring a state that contained
|
||||
* opened scratchpad windows.
|
||||
*/
|
||||
restoreScratchpadSession: function (scratchpads) {
|
||||
if (!this.isInstalled()) {
|
||||
return;
|
||||
}
|
||||
this.gDevTools.restoreScratchpadSession(scratchpads);
|
||||
},
|
||||
|
||||
_onDevToolsRegistered: function () {
|
||||
// Register all pending event listeners on the real gDevTools object.
|
||||
for (let [event, listener] of this.listeners) {
|
||||
|
|
|
@ -22,6 +22,8 @@ function createMockDevTools() {
|
|||
"unregisterTool",
|
||||
"unregisterTheme",
|
||||
"emit",
|
||||
"getOpenedScratchpads",
|
||||
"restoreScratchpadSession",
|
||||
];
|
||||
|
||||
let mock = {
|
||||
|
@ -188,6 +190,30 @@ function test_events() {
|
|||
checkCalls(mock, "emit", 2, ["devtools-unregistered"]);
|
||||
}
|
||||
|
||||
function test_scratchpad_apis() {
|
||||
ok(!DevToolsShim.isInstalled(), "DevTools are not installed");
|
||||
|
||||
// Check that restoreScratchpadSession doesn't crash.
|
||||
DevToolsShim.restoreScratchpadSession([{}]);
|
||||
|
||||
let scratchpads = DevToolsShim.getOpenedScratchpads();
|
||||
equal(scratchpads.length, 0,
|
||||
"getOpenedScratchpads returns [] when DevTools are not installed");
|
||||
|
||||
let mock = createMockDevTools();
|
||||
DevToolsShim.register(mock);
|
||||
|
||||
// Check that calls to restoreScratchpadSession are not held.
|
||||
checkCalls(mock, "restoreScratchpadSession", 0);
|
||||
|
||||
DevToolsShim.getOpenedScratchpads();
|
||||
checkCalls(mock, "getOpenedScratchpads", 1, []);
|
||||
|
||||
let scratchpadSessions = [{}];
|
||||
DevToolsShim.restoreScratchpadSession(scratchpadSessions);
|
||||
checkCalls(mock, "restoreScratchpadSession", 1, [scratchpadSessions]);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
test_register_unregister();
|
||||
DevToolsShim.unregister();
|
||||
|
@ -207,5 +233,8 @@ function run_test() {
|
|||
test_registering_theme();
|
||||
DevToolsShim.unregister();
|
||||
|
||||
test_scratchpad_apis();
|
||||
DevToolsShim.unregister();
|
||||
|
||||
test_events();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче