Bug 1262806 - Close button doesn't work for the RDM tool if tab is detached from the current window; r=jryans draft
authorMatteo Ferretti <mferretti@mozilla.com>
Fri, 21 Oct 2016 14:01:43 +0200
changeset 429192 74c2f8b0d528444a20e694a323de1b7ffd464667
parent 428660 dfe968527d9b17e118c15881a10325ae54f6295b
child 534918 0ae49e21920c3c8e1ce54a0085ce39b60c3c54ac
push id33506
push userbmo:zer0@mozilla.com
push dateTue, 25 Oct 2016 12:41:14 +0000
reviewersjryans
bugs1262806
milestone52.0a1
Bug 1262806 - Close button doesn't work for the RDM tool if tab is detached from the current window; r=jryans MozReview-Commit-ID: FQqkkqBLp5v
devtools/client/responsive.html/test/browser/browser_exit_button.js
devtools/client/responsivedesign/responsivedesign-child.js
--- a/devtools/client/responsive.html/test/browser/browser_exit_button.js
+++ b/devtools/client/responsive.html/test/browser/browser_exit_button.js
@@ -1,30 +1,70 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-// Test global exit button
-
 const TEST_URL = "data:text/html;charset=utf-8,";
 
-addRDMTask(TEST_URL, function* ({ ui, manager }) {
-  let { toolWindow } = ui;
+// Test global exit button
+addRDMTask(TEST_URL, function* (...args) {
+  yield testExitButton(...args);
+});
+
+// Test global exit button on detached tab.
+// See Bug 1262806
+add_task(function* () {
+  let tab = yield addTab(TEST_URL);
+  let { ui, manager } = yield openRDM(tab);
+
+  yield waitBootstrap(ui);
+
+  let waitTabIsDetached = Promise.all([
+    once(tab, "TabClose"),
+    once(tab.linkedBrowser, "SwapDocShells")
+  ]);
+
+  // Detach the tab with RDM open.
+  let newWindow = gBrowser.replaceTabWithWindow(tab);
+
+  // Waiting the tab is detached.
+  yield waitTabIsDetached;
+
+  // Get the new tab instance.
+  tab = newWindow.gBrowser.tabs[0];
+
+  // Detaching a tab closes RDM.
+  ok(!manager.isActiveForTab(tab),
+    "Responsive Design Mode is not active for the tab");
+
+  // Reopen the RDM and test the exit button again.
+  yield testExitButton(yield openRDM(tab));
+  yield BrowserTestUtils.closeWindow(newWindow);
+});
+
+function* waitBootstrap(ui) {
+  let { toolWindow, tab } = ui;
   let { store } = toolWindow;
+  let url = String(tab.linkedBrowser.currentURI.spec);
 
-  // Wait until the viewport has been added
+  // Wait until the viewport has been added.
   yield waitUntilState(store, state => state.viewports.length == 1);
 
-  let exitButton = toolWindow.document.getElementById("global-exit-button");
+  // Wait until the document has been loaded.
+  yield waitForFrameLoad(ui, url);
+}
 
-  yield waitForFrameLoad(ui, TEST_URL);
+function* testExitButton({ui, manager}) {
+  yield waitBootstrap(ui);
+
+  let exitButton = ui.toolWindow.document.getElementById("global-exit-button");
 
   ok(manager.isActiveForTab(ui.tab),
     "Responsive Design Mode active for the tab");
 
   exitButton.click();
 
   yield once(manager, "off");
 
   ok(!manager.isActiveForTab(ui.tab),
     "Responsive Design Mode is not active for the tab");
-});
+}
--- a/devtools/client/responsivedesign/responsivedesign-child.js
+++ b/devtools/client/responsivedesign/responsivedesign-child.js
@@ -36,17 +36,18 @@ var global = this;
    */
   function isActive() {
     sendAsyncMessage("ResponsiveMode:IsActive:Done", { active });
   }
 
   function startResponsiveMode({data:data}) {
     debug("START");
     if (active) {
-      debug("ALREADY STARTED, ABORT");
+      debug("ALREADY STARTED");
+      sendAsyncMessage("ResponsiveMode:Start:Done");
       return;
     }
     addMessageListener("ResponsiveMode:RequestScreenshot", screenshot);
     let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress);
     webProgress.addProgressListener(WebProgressListener, Ci.nsIWebProgress.NOTIFY_ALL);
     docShell.deviceSizeIsPageSize = true;
     gRequiresFloatingScrollbars = data.requiresFloatingScrollbars;
     if (data.notifyOnResize) {