Bug 1299503 - Cleanup browser_toolbox_sidebar toolboxes at test end to prevent crashes. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 01 Sep 2016 02:17:22 -0700
changeset 420138 4f98317489d28c2a503c9d593699ef7e02b024a1
parent 420137 65c30a37abb8a311302e74ed0c757c832e1d4b28
child 532730 f851f245d463833e3468ab80062df6306240afae
push id31105
push userbmo:poirot.alex@gmail.com
push dateMon, 03 Oct 2016 13:54:40 +0000
reviewersjryans
bugs1299503
milestone52.0a1
Bug 1299503 - Cleanup browser_toolbox_sidebar toolboxes at test end to prevent crashes. r=jryans MozReview-Commit-ID: BWdbWELzBos
devtools/client/framework/test/browser_toolbox_sidebar.js
devtools/client/framework/test/browser_toolbox_sidebar_events.js
devtools/client/framework/test/browser_toolbox_sidebar_existing_tabs.js
devtools/client/framework/test/browser_toolbox_sidebar_overflow_menu.js
--- a/devtools/client/framework/test/browser_toolbox_sidebar.js
+++ b/devtools/client/framework/test/browser_toolbox_sidebar.js
@@ -45,16 +45,17 @@ function test() {
   };
 
   gDevTools.registerTool(toolDefinition);
 
   addTab("about:blank").then(function (aTab) {
     let target = TargetFactory.forTab(aTab);
     gDevTools.showToolbox(target, toolDefinition.id).then(function (toolbox) {
       let panel = toolbox.getPanel(toolDefinition.id);
+      panel.toolbox = toolbox;
       ok(true, "Tool open");
 
       let tabbox = panel.panelDoc.getElementById("sidebar");
       panel.sidebar = new ToolSidebar(tabbox, panel, "testbug865688", true);
 
       panel.sidebar.on("new-tab-registered", function (event, id) {
         registeredTabs[id] = true;
       });
@@ -162,17 +163,19 @@ function test() {
       is(panel.panelDoc.getElementById("sidebar").width, 420, "Width restored");
 
       finishUp(panel);
     });
   }
 
   function finishUp(panel) {
     panel.sidebar.destroy();
-    gDevTools.unregisterTool(toolDefinition.id);
+    panel.toolbox.destroy().then(function () {
+      gDevTools.unregisterTool(toolDefinition.id);
 
-    gBrowser.removeCurrentTab();
+      gBrowser.removeCurrentTab();
 
-    executeSoon(function () {
-      finish();
+      executeSoon(function () {
+        finish();
+      });
     });
   }
 }
--- a/devtools/client/framework/test/browser_toolbox_sidebar_events.js
+++ b/devtools/client/framework/test/browser_toolbox_sidebar_events.js
@@ -75,17 +75,19 @@ function test() {
   function finishUp(panel) {
     panel.sidebar.hide();
     panel.sidebar.destroy();
 
     let events = collectedEvents.join(":");
     is(events, "sidebar-created:show:hide:sidebar-destroyed",
       "Found the right amount of collected events.");
 
-    gDevTools.unregisterTool(toolDefinition.id);
-    gBrowser.removeCurrentTab();
+    panel.toolbox.destroy().then(function () {
+      gDevTools.unregisterTool(toolDefinition.id);
+      gBrowser.removeCurrentTab();
 
-    executeSoon(function () {
-      finish();
+      executeSoon(function () {
+        finish();
+      });
     });
   }
 }
 
--- a/devtools/client/framework/test/browser_toolbox_sidebar_existing_tabs.js
+++ b/devtools/client/framework/test/browser_toolbox_sidebar_existing_tabs.js
@@ -67,11 +67,12 @@ add_task(function* () {
   is(sidebar.getCurrentTabID(), "tab1", "getCurrentTabID returns the expected id");
 
   info("Removing a tab");
   sidebar.removeTab("tab2", "tabpanel2");
   ok(!sidebar.getTab("tab2"), "Tab 2 was removed correctly");
   ok(!sidebar.getTabPanel("tabpanel2"), "Tabpanel 2 was removed correctly");
 
   sidebar.destroy();
+  yield toolbox.destroy();
   gDevTools.unregisterTool(testToolDefinition.id);
   gBrowser.removeCurrentTab();
 });
--- a/devtools/client/framework/test/browser_toolbox_sidebar_overflow_menu.js
+++ b/devtools/client/framework/test/browser_toolbox_sidebar_overflow_menu.js
@@ -69,11 +69,12 @@ add_task(function* () {
       "The selected tab is now nb " + nb);
   }
 
   info("Fake an underflow event so that the all-tabs menu gets hidden");
   sidebar._onTabBoxUnderflow();
   is(allTabsMenu.getAttribute("hidden"), "true", "The all-tabs menu is hidden");
 
   yield sidebar.destroy();
+  yield toolbox.destroy();
   gDevTools.unregisterTool(testToolDefinition.id);
   gBrowser.removeCurrentTab();
 });