Bug 1269497 - Provide toolbox.win getter to make lines shorter in tests;r=jdescottes draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Mon, 02 May 2016 14:54:31 -0700
changeset 362669 46891b760b0bcc40d1e53b3907ead93242462290
parent 362668 e5344982b8ec6626882230f6f348303cf3201d12
child 362670 decf762b5102ba6f2282fe26ceea4c07d86a7d59
push id17008
push userbgrinstead@mozilla.com
push dateMon, 02 May 2016 21:59:43 +0000
reviewersjdescottes
bugs1269497
milestone49.0a1
Bug 1269497 - Provide toolbox.win getter to make lines shorter in tests;r=jdescottes MozReview-Commit-ID: JwisgbTEXDj
devtools/client/debugger/test/mochitest/head.js
devtools/client/framework/test/browser_keybindings_02.js
devtools/client/framework/test/browser_toolbox_custom_host.js
devtools/client/framework/test/browser_toolbox_minimize.js
devtools/client/framework/test/browser_toolbox_tabsswitch_shortcuts.js
devtools/client/framework/test/browser_toolbox_window_reload_target.js
devtools/client/framework/test/browser_toolbox_window_shortcuts.js
devtools/client/framework/test/browser_toolbox_zoom.js
devtools/client/framework/toolbox.js
devtools/client/inspector/inspector-panel.js
devtools/client/inspector/test/head.js
devtools/client/webconsole/test/browser_webconsole_output_dom_elements_02.js
devtools/client/webconsole/test/browser_webconsole_split.js
--- a/devtools/client/debugger/test/mochitest/head.js
+++ b/devtools/client/debugger/test/mochitest/head.js
@@ -1153,17 +1153,17 @@ function source(sourceClient) {
 // console if necessary.  This cleans up the split console pref so
 // it won't pollute other tests.
 function getSplitConsole(toolbox, win) {
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
   });
 
   if (!win) {
-    win = toolbox.doc.defaultView;
+    win = toolbox.win;
   }
 
   if (!toolbox.splitConsole) {
     EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
   }
 
   return new Promise(resolve => {
     toolbox.getPanelWhenReady("webconsole").then(() => {
--- a/devtools/client/framework/test/browser_keybindings_02.js
+++ b/devtools/client/framework/test/browser_keybindings_02.js
@@ -35,17 +35,17 @@ add_task(function*() {
 function zoomWithKey(toolbox, key) {
   if (!key) {
     info("Key was empty, skipping zoomWithKey");
     return;
   }
 
   info("Zooming with key: " + key);
   let currentZoom = toolbox.zoomValue;
-  EventUtils.synthesizeKey(key, {accelKey: true}, toolbox.doc.defaultView);
+  EventUtils.synthesizeKey(key, {accelKey: true}, toolbox.win);
   isnot(toolbox.zoomValue, currentZoom, "The zoom level was changed in the toolbox");
 }
 
 function* checkKeyBindings(toolbox) {
   zoomWithKey(toolbox, toolbox.doc.getElementById("toolbox-zoom-in-key").getAttribute("key"));
   zoomWithKey(toolbox, toolbox.doc.getElementById("toolbox-zoom-in-key2").getAttribute("key"));
   zoomWithKey(toolbox, toolbox.doc.getElementById("toolbox-zoom-in-key3").getAttribute("key"));
 
--- a/devtools/client/framework/test/browser_toolbox_custom_host.js
+++ b/devtools/client/framework/test/browser_toolbox_custom_host.js
@@ -33,17 +33,17 @@ function test() {
       ok("Got the `toolbox-close` message");
       window.removeEventListener("message", onMessage);
       cleanup();
     }
   }
 
   function testCustomHost(t) {
     toolbox = t;
-    is(toolbox.doc.defaultView.top, window, "Toolbox is included in browser.xul");
+    is(toolbox.win.top, window, "Toolbox is included in browser.xul");
     is(toolbox.doc, iframe.contentDocument, "Toolbox is in the custom iframe");
     executeSoon(() => gBrowser.removeCurrentTab());
   }
 
   function cleanup() {
     iframe.remove();
 
     // Even if we received "toolbox-close", the toolbox may still be destroying
--- a/devtools/client/framework/test/browser_toolbox_minimize.js
+++ b/devtools/client/framework/test/browser_toolbox_minimize.js
@@ -48,59 +48,59 @@ add_task(function*() {
   let onMaximized = toolbox._host.once("maximized");
   yield toolbox.selectTool("inspector");
   yield onMaximized;
 
   info("Minimize again and click on the tab of the current tool");
   yield minimize(toolbox);
   onMaximized = toolbox._host.once("maximized");
   let tabButton = toolbox.doc.querySelector("#toolbox-tab-inspector");
-  EventUtils.synthesizeMouseAtCenter(tabButton, {}, toolbox.doc.defaultView);
+  EventUtils.synthesizeMouseAtCenter(tabButton, {}, toolbox.win);
   yield onMaximized;
 
   info("Minimize again and click on the settings tab");
   yield minimize(toolbox);
   onMaximized = toolbox._host.once("maximized");
   let settingsButton = toolbox.doc.querySelector("#toolbox-tab-options");
-  EventUtils.synthesizeMouseAtCenter(settingsButton, {}, toolbox.doc.defaultView);
+  EventUtils.synthesizeMouseAtCenter(settingsButton, {}, toolbox.win);
   yield onMaximized;
 
   info("Switch to a different host");
   yield toolbox.switchHost(Toolbox.HostType.SIDE);
   button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
   ok(!button, "The minimize button doesn't exist in the side host");
 
   Services.prefs.clearUserPref("devtools.toolbox.host");
   yield toolbox.destroy();
   gBrowser.removeCurrentTab();
 });
 
 function* minimize(toolbox) {
   let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
   let onMinimized = toolbox._host.once("minimized");
-  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.doc.defaultView);
+  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
   yield onMinimized;
 }
 
 function* minimizeWithShortcut(toolbox) {
   let key = toolbox.doc.getElementById("toolbox-minimize-key")
                        .getAttribute("key");
   let onMinimized = toolbox._host.once("minimized");
   EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
-                           toolbox.doc.defaultView);
+                           toolbox.win);
   yield onMinimized;
 }
 
 function* maximize(toolbox) {
   let button = toolbox.doc.querySelector("#toolbox-dock-bottom-minimize");
   let onMaximized = toolbox._host.once("maximized");
-  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.doc.defaultView);
+  EventUtils.synthesizeMouseAtCenter(button, {}, toolbox.win);
   yield onMaximized;
 }
 
 function* maximizeWithShortcut(toolbox) {
   let key = toolbox.doc.getElementById("toolbox-minimize-key")
                        .getAttribute("key");
   let onMaximized = toolbox._host.once("maximized");
   EventUtils.synthesizeKey(key, {accelKey: true, shiftKey: true},
-                           toolbox.doc.defaultView);
+                           toolbox.win);
   yield onMaximized;
 }
--- a/devtools/client/framework/test/browser_toolbox_tabsswitch_shortcuts.js
+++ b/devtools/client/framework/test/browser_toolbox_tabsswitch_shortcuts.js
@@ -51,16 +51,16 @@ add_task(function*() {
   gBrowser.removeCurrentTab();
 });
 
 function* testShortcuts(toolbox, index, key, toolIDs) {
   info("Testing shortcut to switch to tool " + index + ":" + toolIDs[index] +
        " using key " + key);
 
   let onToolSelected = toolbox.once("select");
-  EventUtils.synthesizeKey(key, {accelKey: true}, toolbox.doc.defaultView);
+  EventUtils.synthesizeKey(key, {accelKey: true}, toolbox.win);
   let id = yield onToolSelected;
 
   info("toolbox-select event from " + id);
 
   is(toolIDs.indexOf(id), index,
      "Correct tool is selected on pressing the shortcut for " + id);
 }
--- a/devtools/client/framework/test/browser_toolbox_window_reload_target.js
+++ b/devtools/client/framework/test/browser_toolbox_window_reload_target.js
@@ -38,17 +38,17 @@ function startReloadTest(aToolbox) {
     info("Detected reload #"+reloads);
     is(reloads, reloadsSent, "Reloaded from devtools window once and only for "+description+"");
   };
   gBrowser.selectedBrowser.messageManager.addMessageListener("devtools:test:load", reloadCounter);
 
   testAllTheTools("docked", () => {
     let origHostType = toolbox.hostType;
     toolbox.switchHost(Toolbox.HostType.WINDOW).then(() => {
-      toolbox.doc.defaultView.focus();
+      toolbox.win.focus();
       testAllTheTools("undocked", () => {
         toolbox.switchHost(origHostType).then(() => {
           gBrowser.selectedBrowser.messageManager.removeMessageListener("devtools:test:load", reloadCounter);
           // If we finish too early, the inspector breaks promises:
           toolbox.getPanel("inspector").once("new-root", finishUp);
         });
       });
     });
--- a/devtools/client/framework/test/browser_toolbox_window_shortcuts.js
+++ b/devtools/client/framework/test/browser_toolbox_window_shortcuts.js
@@ -54,17 +54,17 @@ function testShortcuts(aToolbox, aIndex)
   let modifiers = {
     accelKey: toolModifiers.includes("accel"),
     altKey: toolModifiers.includes("alt"),
     shiftKey: toolModifiers.includes("shift"),
   };
   idIndex = aIndex;
   info("Testing shortcut for tool " + aIndex + ":" + toolIDs[aIndex] +
        " using key " + key);
-  EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView.parent);
+  EventUtils.synthesizeKey(key, modifiers, toolbox.win.parent);
 }
 
 function selectCB(event, id) {
   info("toolbox-select event from " + id);
 
   is(toolIDs.indexOf(id), idIndex,
      "Correct tool is selected on pressing the shortcut for " + id);
 
--- a/devtools/client/framework/test/browser_toolbox_zoom.js
+++ b/devtools/client/framework/test/browser_toolbox_zoom.js
@@ -40,17 +40,17 @@ function testZoomLevel(type, times, expe
 
   is(toolbox.zoomValue.toFixed(2), expected,
      "saved zoom level is correct after zoom " + type);
 }
 
 function sendZoomKey(id, times) {
   let key = toolbox.doc.getElementById(id).getAttribute("key");
   for (let i = 0; i < times; i++) {
-    EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView);
+    EventUtils.synthesizeKey(key, modifiers, toolbox.win);
   }
 }
 
 function getCurrentZoom() {
   var contViewer = toolbox.frame.docShell.contentViewer;
   return contViewer.fullZoom;
 }
 
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -272,16 +272,23 @@ Toolbox.prototype = {
   /**
    * Get the iframe containing the toolbox UI.
    */
   get frame() {
     return this._host.frame;
   },
 
   /**
+   * Shortcut to the window containing the toolbox UI
+   */
+  get win() {
+    return this.doc.defaultView;
+  },
+
+  /**
    * Shortcut to the document containing the toolbox UI
    */
   get doc() {
     return this.frame.contentDocument;
   },
 
   /**
    * Get current zoom level of toolbox
@@ -720,17 +727,17 @@ Toolbox.prototype = {
   /**
    * Adds the keys and commands to the Toolbox Window in window mode.
    */
   _addKeysToWindow: function() {
     if (this.hostType != Toolbox.HostType.WINDOW) {
       return;
     }
 
-    let doc = this.doc.defaultView.parent.document;
+    let doc = this.win.parent.document;
 
     for (let [id, toolDefinition] of gDevTools.getToolDefinitionMap()) {
       // Prevent multiple entries for the same tool.
       if (!toolDefinition.key || doc.getElementById("key_" + id)) {
         continue;
       }
 
       let toolId = id;
@@ -931,17 +938,17 @@ Toolbox.prototype = {
         // focus to current aria-activedescendant.
         event.preventDefault();
         control.focus();
       }
     }, true)
 
     toolbar.addEventListener("keypress", event => {
       let { key, target } = event;
-      let win = this.doc.defaultView;
+      let win = this.win;
       let elm, type;
       if (key === "Tab") {
         // Tabbing when toolbar or its contents are focused should move focus to
         // next/previous focusable element relative to toolbar itself.
         if (event.shiftKey) {
           elm = toolbar;
           type = Services.focus.MOVEFOCUS_BACKWARD;
         } else {
@@ -1895,17 +1902,17 @@ Toolbox.prototype = {
       radio.parentNode.removeChild(radio);
     }
 
     if (panel) {
       panel.parentNode.removeChild(panel);
     }
 
     if (this.hostType == Toolbox.HostType.WINDOW) {
-      let doc = this.doc.defaultView.parent.document;
+      let doc = this.win.parent.document;
       let key = doc.getElementById("key_" + toolId);
       if (key) {
         key.parentNode.removeChild(key);
       }
     }
     // Emit the event so tools can listen to it from the toolbox level
     // instead of gDevTools
     this.emit("tool-unregistered", toolId);
@@ -2167,17 +2174,17 @@ Toolbox.prototype = {
     let window = this.frame.contentWindow;
     showDoorhanger({ window, type: "deveditionpromo" });
   },
 
   /**
    * Enable / disable necessary textbox menu items using globalOverlay.js.
    */
   _updateTextboxMenuItems: function() {
-    let window = this.doc.defaultView;
+    let window = this.win;
     ["cmd_undo", "cmd_delete", "cmd_cut",
      "cmd_copy", "cmd_paste", "cmd_selectAll"].forEach(window.goUpdateCommand);
   },
 
   /**
    * Connects to the SPS profiler when the developer tools are open. This is
    * necessary because of the WebConsole's `profile` and `profileEnd` methods.
    */
--- a/devtools/client/inspector/inspector-panel.js
+++ b/devtools/client/inspector/inspector-panel.js
@@ -983,17 +983,17 @@ InspectorPanel.prototype = {
 
   _onMarkupFrameLoad: function() {
     this._markupFrame.removeEventListener("load", this._onMarkupFrameLoad, true);
 
     this._markupFrame.contentWindow.focus();
 
     this._markupBox.removeAttribute("collapsed");
 
-    let controllerWindow = this._toolbox.doc.defaultView;
+    let controllerWindow = this._toolbox.win;
     this.markup = new MarkupView(this, this._markupFrame, controllerWindow);
 
     this.emit("markuploaded");
   },
 
   _destroyMarkup: function() {
     let destroyPromise;
 
--- a/devtools/client/inspector/test/head.js
+++ b/devtools/client/inspector/test/head.js
@@ -431,17 +431,17 @@ var clickContainer = Task.async(function
 function mouseLeaveMarkupView(inspector) {
   info("Leaving the markup-view area");
   let def = promise.defer();
 
   // Find another element to mouseover over in order to leave the markup-view
   let btn = inspector.toolbox.doc.querySelector("#toolbox-controls");
 
   EventUtils.synthesizeMouseAtCenter(btn, {type: "mousemove"},
-    inspector.toolbox.doc.defaultView);
+    inspector.toolbox.win);
   executeSoon(def.resolve);
 
   return def.promise;
 }
 
 /**
  * Dispatch the copy event on the given element
  */
--- a/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_02.js
+++ b/devtools/client/webconsole/test/browser_webconsole_output_dom_elements_02.js
@@ -102,17 +102,17 @@ function test() {
         is(attrs[i].value, data.attrs[i].value,
            "The correct node was highlighted");
       }
 
       info("Unhighlight the node by moving away from the markup view");
       let onNodeUnhighlight = toolbox.once("node-unhighlight");
       let btn = inspector.toolbox.doc.querySelector(".toolbox-dock-button");
       EventUtils.synthesizeMouseAtCenter(btn, {type: "mousemove"},
-        inspector.toolbox.doc.defaultView);
+        inspector.toolbox.win);
       yield onNodeUnhighlight;
 
       info("Switching back to the console");
       yield toolbox.selectTool("webconsole");
     }
   }).then(finishTest);
 }
 
--- a/devtools/client/webconsole/test/browser_webconsole_split.js
+++ b/devtools/client/webconsole/test/browser_webconsole_split.js
@@ -55,17 +55,17 @@ function test() {
       yield openAndCheckPanel("netmonitor");
 
       yield checkWebconsolePanelOpened();
       testBottomHost();
     });
   }
 
   function getCurrentUIState() {
-    let win = toolbox.doc.defaultView;
+    let win = toolbox.win;
     let deck = toolbox.doc.querySelector("#toolbox-deck");
     let webconsolePanel = toolbox.webconsolePanel;
     let splitter = toolbox.doc.querySelector("#toolbox-console-splitter");
 
     let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode)
       .getPropertyValue("height"));
     let deckHeight = parseFloat(win.getComputedStyle(deck)
       .getPropertyValue("height"));