Bug 1503175 - Restore the previous inspector layout when reopening. r=gl, a=jcristau
authorVincent R <grosbouddha@gmail.com>
Fri, 09 Nov 2018 18:56:05 +0100
changeset 501488 a2b5b227742b
parent 501487 ceab3f2abadf
child 501489 e4c03449c5ec
push id1891
push userjcristau@mozilla.com
push dateTue, 08 Jan 2019 16:05:30 +0000
treeherdermozilla-release@c58ea2229c33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl, jcristau
bugs1503175
milestone64.0.2
Bug 1503175 - Restore the previous inspector layout when reopening. r=gl, a=jcristau
devtools/client/inspector/inspector.js
devtools/client/inspector/test/browser.ini
devtools/client/inspector/test/browser_inspector_pane_state_restore.js
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -1406,16 +1406,18 @@ Inspector.prototype = {
 
     if (this.walker) {
       this.walker.off("new-root", this.onNewRoot);
       this.pageStyle = null;
     }
 
     this.cancelUpdate();
 
+    this.sidebar.destroy();
+
     this.panelWin.removeEventListener("resize", this.onPanelWindowResize, true);
     this.selection.off("new-node-front", this.onNewSelection);
     this.selection.off("detached-front", this.onDetached);
     this.sidebar.off("select", this.onSidebarSelect);
     this.sidebar.off("show", this.onSidebarShown);
     this.sidebar.off("hide", this.onSidebarHidden);
     this.sidebar.off("destroy", this.onSidebarHidden);
     this.target.off("will-navigate", this._onBeforeNavigate);
--- a/devtools/client/inspector/test/browser.ini
+++ b/devtools/client/inspector/test/browser.ini
@@ -155,16 +155,17 @@ skip-if = (os == 'linux' && bits == 32 &
 subsuite = clipboard
 skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_inspector_menu-04-use-in-console.js]
 [browser_inspector_menu-05-attribute-items.js]
 [browser_inspector_menu-06-other.js]
 [browser_inspector_navigation.js]
 [browser_inspector_navigate_to_errors.js]
 [browser_inspector_open_on_neterror.js]
+[browser_inspector_pane_state_restore.js]
 [browser_inspector_pane-toggle-01.js]
 [browser_inspector_pane-toggle-02.js]
 [browser_inspector_pane-toggle-03.js]
 [browser_inspector_pane-toggle-04.js]
 [browser_inspector_picker-stop-on-destroy.js]
 [browser_inspector_picker-stop-on-tool-change.js]
 [browser_inspector_portrait_mode.js]
 [browser_inspector_pseudoclass-lock.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/test/browser_inspector_pane_state_restore.js
@@ -0,0 +1,55 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Tests that the previous inspector split box sizes are restored when reopening the
+// inspector.
+
+const EXPECTED_INITIAL_WIDTH = 101;
+const EXPECTED_INITIAL_HEIGHT = 102;
+const EXPECTED_INITIAL_SIDEBAR_WIDTH = 103;
+
+const EXPECTED_NEW_WIDTH = 150;
+const EXPECTED_NEW_HEIGHT = 100;
+const EXPECTED_NEW_SIDEBAR_WIDTH = 250;
+
+add_task(async function() {
+  // Simulate that the user has already stored their preferred split boxes widths.
+  await pushPref("devtools.toolsidebar-width.inspector", EXPECTED_INITIAL_WIDTH);
+  await pushPref("devtools.toolsidebar-height.inspector", EXPECTED_INITIAL_HEIGHT);
+  await pushPref("devtools.toolsidebar-width.inspector.splitsidebar",
+    EXPECTED_INITIAL_SIDEBAR_WIDTH);
+
+  const { inspector } = await openInspectorForURL("about:blank");
+
+  info("Check the initial size of the inspector.");
+  const { width, height, splitSidebarWidth } = inspector.getSidebarSize();
+  is(width, EXPECTED_INITIAL_WIDTH, "Got correct initial width.");
+  is(height, EXPECTED_INITIAL_HEIGHT, "Got correct initial height.");
+  is(splitSidebarWidth, EXPECTED_INITIAL_SIDEBAR_WIDTH,
+    "Got correct initial split sidebar width.");
+
+  info("Simulate updates to the dimensions of the various splitboxes.");
+  inspector.splitBox.setState({
+    width: EXPECTED_NEW_WIDTH,
+    height: EXPECTED_NEW_HEIGHT,
+  });
+  inspector.sidebarSplitBox.setState({
+    width: EXPECTED_NEW_SIDEBAR_WIDTH,
+  });
+
+  await closeToolbox();
+
+  info("Check the stored sizes of the inspector in the preferences when the inspector " +
+    "is closed");
+  const storedWidth = Services.prefs.getIntPref("devtools.toolsidebar-width.inspector");
+  const storedHeight = Services.prefs.getIntPref("devtools.toolsidebar-height.inspector");
+  const storedSplitSidebarWidth =
+    Services.prefs.getIntPref("devtools.toolsidebar-width.inspector.splitsidebar");
+  is(storedWidth, EXPECTED_NEW_WIDTH, "Got correct stored width.");
+  is(storedHeight, EXPECTED_NEW_HEIGHT, "Got correct stored height");
+  is(storedSplitSidebarWidth, EXPECTED_NEW_SIDEBAR_WIDTH,
+    "Got correct stored split sidebar width.");
+});