Bug 1359855 - Prevent loading DevTools when saving session restore data. r=jdescottes
MozReview-Commit-ID: 1d7WmiGRSmp
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -170,24 +170,20 @@ 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()) {
+ if (!this.isInitialized()) {
return [];
}
- if (!this.isInitialized()) {
- this._initDevTools();
- }
-
return this.gDevTools.getOpenedScratchpads();
},
/**
* Called from SessionStore.jsm in mozilla-central when restoring a state that contained
* opened scratchpad windows.
*/
restoreScratchpadSession: function (scratchpads) {
--- a/devtools/shim/tests/unit/test_devtools_shim.js
+++ b/devtools/shim/tests/unit/test_devtools_shim.js
@@ -42,17 +42,16 @@ function createMockDevTools() {
}
return mock;
}
function mockDevToolsInstalled() {
DevToolsShim.isInstalled = () => true;
}
-
function mockDevToolsUninstalled() {
DevToolsShim.isInstalled = () => false;
}
/**
* Check if a given method was called an expected number of times, and finally check the
* arguments provided to the last call, if appropriate.
*/
@@ -200,39 +199,51 @@ function test_events() {
DevToolsShim.unregister();
checkCalls(mock, "emit", 2, ["devtools-unregistered"]);
}
function test_scratchpad_apis() {
mockDevToolsUninstalled();
ok(!DevToolsShim.isInstalled(), "DevTools are not installed");
+ ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
+
+ // Ensure that getOpenedScratchpads doesn't initialize the tools
+ DevToolsShim.getOpenedScratchpads();
+
+ ok(!DevToolsShim.isInstalled(), "DevTools are not installed");
+ ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
// 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();
+ mockDevToolsInstalled();
- mockDevToolsInstalled();
+ ok(DevToolsShim.isInstalled(), "DevTools are installed");
+ ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
+
+ let mock = createMockDevTools();
DevToolsShim._initDevTools = () => {
- // Next call to getOpenedScratchpags is expected to initialize DevTools, which we
+ // Next call to restoreScratchpadSession is expected to initialize DevTools, which we
// simulate here by registering our mock.
DevToolsShim.register(mock);
};
- DevToolsShim.getOpenedScratchpads();
- checkCalls(mock, "getOpenedScratchpads", 1, []);
-
let scratchpadSessions = [{}];
DevToolsShim.restoreScratchpadSession(scratchpadSessions);
checkCalls(mock, "restoreScratchpadSession", 1, [scratchpadSessions]);
+
+ ok(DevToolsShim.isInitialized(), "DevTools are initialized");
+
+ DevToolsShim.getOpenedScratchpads();
+ checkCalls(mock, "getOpenedScratchpads", 1, []);
}
function run_test() {
test_register_unregister();
DevToolsShim.unregister();
test_on_is_forwarded_to_devtools();
DevToolsShim.unregister();