Bug 1359855 - Prevent loading DevTools when saving session restore data. r=jdescottes draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 20 Jul 2017 12:38:09 +0200
changeset 614031 7f2d272a1fb00d6fd3e223f9e8f93ba2d4d9449d
parent 614030 b292097ff86a815ab6233e773b84e8b19682eb98
child 614266 0deffef3cb0271b225708bd023f4b1f801b3d963
child 614482 14afea2352ebb9a2de776841ffb43558672a494d
push id69893
push userbmo:poirot.alex@gmail.com
push dateSun, 23 Jul 2017 20:50:47 +0000
reviewersjdescottes
bugs1359855
milestone56.0a1
Bug 1359855 - Prevent loading DevTools when saving session restore data. r=jdescottes 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();