Bug 1359855 - Prevent loading DevTools when saving session restore data. r=jdescottes,mossop
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 20 Jul 2017 12:38:09 +0200
changeset 614707 ff507dd06af9bce63188818602b624f5de3d1412
parent 614706 4ec28f94e2848a73f357c965c92bf133b221e937
child 614708 1b4dea0fe0213d36833103764921046ec41bcca6
push id70091
push userhikezoe@mozilla.com
push dateMon, 24 Jul 2017 22:05:18 +0000
reviewersjdescottes, mossop
bugs1359855
milestone56.0a1
Bug 1359855 - Prevent loading DevTools when saving session restore data. r=jdescottes,mossop MozReview-Commit-ID: 1d7WmiGRSmp
devtools/shim/DevToolsShim.jsm
devtools/shim/tests/unit/test_devtools_shim.js
--- 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();