Bug 719731 - Get rid of window mediator's getMostRecentBrowserWindow across Tilt codebase; r=rcampbell
authorVictor Porof <vporof@mozilla.com>
Fri, 20 Jan 2012 13:36:48 +0200
changeset 86801 e4216a369836bdb7099131e4000aba19ee755d0c
parent 86800 aa1323985e20a52de7affb922285ca000dbc65c9
child 86802 5cac59d4e1e14c47ce2ade41c30278da2de97dd6
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs719731
milestone12.0a1
Bug 719731 - Get rid of window mediator's getMostRecentBrowserWindow across Tilt codebase; r=rcampbell
browser/devtools/tilt/Tilt.jsm
browser/devtools/tilt/TiltUtils.jsm
browser/devtools/tilt/TiltVisualizer.jsm
browser/devtools/tilt/test/browser_tilt_arcball.js
browser/devtools/tilt/test/browser_tilt_utils06.js
browser/devtools/tilt/test/browser_tilt_visualizer.js
browser/devtools/tilt/test/browser_tilt_zoom.js
browser/devtools/tilt/test/head.js
--- a/browser/devtools/tilt/Tilt.jsm
+++ b/browser/devtools/tilt/Tilt.jsm
@@ -121,20 +121,20 @@ Tilt.prototype = {
     // if the visualizer for the current tab is already open, destroy it now
     if (this.visualizers[id]) {
       this.destroy(id, true);
       return;
     }
 
     // create a visualizer instance for the current tab
     this.visualizers[id] = new TiltVisualizer({
-      parentNode: this.chromeWindow.gBrowser.selectedBrowser.parentNode,
+      chromeWindow: this.chromeWindow,
       contentWindow: this.chromeWindow.gBrowser.selectedBrowser.contentWindow,
+      parentNode: this.chromeWindow.gBrowser.selectedBrowser.parentNode,
       requestAnimationFrame: this.chromeWindow.mozRequestAnimationFrame,
-      inspectorUI: this.chromeWindow.InspectorUI,
       notifications: this.NOTIFICATIONS
     });
 
     // make sure the visualizer object was initialized properly
     if (!this.visualizers[id].isInitialized()) {
       this.destroy(id);
       return;
     }
@@ -178,17 +178,17 @@ Tilt.prototype = {
       let controller = this.visualizers[aId].controller;
       let presenter = this.visualizers[aId].presenter;
 
       let content = presenter.contentWindow;
       let pageXOffset = content.pageXOffset * presenter.transforms.zoom;
       let pageYOffset = content.pageYOffset * presenter.transforms.zoom;
 
       Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYING, null);
-      TiltUtils.setDocumentZoom(presenter.transforms.zoom);
+      TiltUtils.setDocumentZoom(this.chromeWindow, presenter.transforms.zoom);
 
       controller.removeEventListeners();
       controller.arcball.reset([-pageXOffset, -pageYOffset]);
       presenter.executeDestruction(finalize.bind(this, aId));
     }
   },
 
   /**
--- a/browser/devtools/tilt/TiltUtils.jsm
+++ b/browser/devtools/tilt/TiltUtils.jsm
@@ -526,28 +526,16 @@ TiltUtils.destroyObject = function TU_de
   for (let i in aScope) {
     if (aScope.hasOwnProperty(i)) {
       delete aScope[i];
     }
   }
 };
 
 /**
- * Gets the most recent browser window.
- *
- * @return {Window} the window
- */
-TiltUtils.getBrowserWindow = function TU_getBrowserWindow()
-{
-  return Cc["@mozilla.org/appshell/window-mediator;1"]
-    .getService(Ci.nsIWindowMediator)
-    .getMostRecentWindow("navigator:browser");
-};
-
-/**
  * Retrieve the unique ID of a window object.
  *
  * @param {Window} aWindow
  *                 the window to get the ID from
  *
  * @return {Number} the window ID
  */
 TiltUtils.getWindowId = function TU_getWindowId(aWindow)
@@ -559,42 +547,48 @@ TiltUtils.getWindowId = function TU_getW
   return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                 .getInterface(Ci.nsIDOMWindowUtils)
                 .currentInnerWindowID;
 };
 
 /**
  * Gets the markup document viewer zoom for the currently selected browser.
  *
+ * @param {Window} aChromeWindow
+ *                 the top-level browser window
+ *
  * @return {Number} the zoom ammount
  */
-TiltUtils.getDocumentZoom = function TU_getDocumentZoom() {
-  return TiltUtils.getBrowserWindow()
-                  .gBrowser.selectedBrowser.markupDocumentViewer.fullZoom;
+TiltUtils.getDocumentZoom = function TU_getDocumentZoom(aChromeWindow) {
+  return aChromeWindow.gBrowser.selectedBrowser.markupDocumentViewer.fullZoom;
 };
 
 /**
  * Sets the markup document viewer zoom for the currently selected browser.
  *
+ * @param {Window} aChromeWindow
+ *                 the top-level browser window
+ *
  * @param {Number} the zoom ammount
  */
-TiltUtils.setDocumentZoom = function TU_getDocumentZoom(aZoom) {
-  TiltUtils.getBrowserWindow()
-           .gBrowser.selectedBrowser.markupDocumentViewer.fullZoom = aZoom;
+TiltUtils.setDocumentZoom = function TU_setDocumentZoom(aChromeWindow, aZoom) {
+  aChromeWindow.gBrowser.selectedBrowser.markupDocumentViewer.fullZoom = aZoom;
 };
 
 /**
  * Performs a garbage collection.
+ *
+ * @param {Window} aChromeWindow
+ *                 the top-level browser window
  */
-TiltUtils.gc = function TU_gc()
+TiltUtils.gc = function TU_gc(aChromeWindow)
 {
-  TiltUtils.getBrowserWindow()
-           .QueryInterface(Ci.nsIInterfaceRequestor)
-           .getInterface(Ci.nsIDOMWindowUtils)
-           .garbageCollect();
+  aChromeWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIDOMWindowUtils)
+               .garbageCollect();
 };
 
 /**
  * Clears the cache and sets all the variables to null.
  */
 TiltUtils.clearCache = function TU_clearCache()
 {
   TiltUtils.DOM.parentNode = null;
--- a/browser/devtools/tilt/TiltVisualizer.jsm
+++ b/browser/devtools/tilt/TiltVisualizer.jsm
@@ -86,44 +86,49 @@ Cu.import("resource:///modules/devtools/
 
 let EXPORTED_SYMBOLS = ["TiltVisualizer"];
 
 /**
  * Initializes the visualization presenter and controller.
  *
  * @param {Object} aProperties
  *                 an object containing the following properties:
- *       {Element} parentNode: the parent node to hold the visualization
+ *        {Window} chromeWindow: a reference to the top level window
  *        {Window} contentWindow: the content window holding the visualized doc
+ *       {Element} parentNode: the parent node to hold the visualization
  *      {Function} requestAnimationFrame: responsible with scheduling loops
- *   {InspectorUI} inspectorUI: necessary instance of the InspectorUI
  *        {Object} notifications: necessary notifications for Tilt
  *      {Function} onError: optional, function called if initialization failed
  *      {Function} onLoad: optional, function called if initialization worked
  */
 function TiltVisualizer(aProperties)
 {
   // make sure the properties parameter is a valid object
   aProperties = aProperties || {};
 
   /**
+   * Save a reference to the top-level window.
+   */
+  this.chromeWindow = aProperties.chromeWindow;
+
+  /**
    * The canvas element used for rendering the visualization.
    */
   this.canvas = TiltUtils.DOM.initCanvas(aProperties.parentNode, {
     focusable: true,
     append: true
   });
 
   /**
    * Visualization logic and drawing loop.
    */
   this.presenter = new TiltVisualizer.Presenter(this.canvas,
+    aProperties.chromeWindow,
     aProperties.contentWindow,
     aProperties.requestAnimationFrame,
-    aProperties.inspectorUI,
     aProperties.notifications,
     aProperties.onError || null,
     aProperties.onLoad || null);
 
   /**
    * Visualization mouse and keyboard controller.
    */
   this.controller = new TiltVisualizer.Controller(this.canvas, this.presenter);
@@ -158,48 +163,61 @@ TiltVisualizer.prototype = {
   cleanup: function TV_cleanup()
   {
     if (this.controller) {
       TiltUtils.destroyObject(this.controller);
     }
     if (this.presenter) {
       TiltUtils.destroyObject(this.presenter);
     }
+
+    let chromeWindow = this.chromeWindow;
+
     TiltUtils.destroyObject(this);
     TiltUtils.clearCache();
-    TiltUtils.gc();
+    TiltUtils.gc(chromeWindow);
   }
 };
 
 /**
  * This object manages the visualization logic and drawing loop.
  *
  * @param {HTMLCanvasElement} aCanvas
  *                            the canvas element used for rendering
- * @param {Object} aContentWindow
+ * @param {Window} aChromeWindow
+ *                 a reference to the top-level window
+ * @param {Window} aContentWindow
  *                 the content window holding the document to be visualized
  * @param {Function} aRequestAnimationFrame
  *                   function responsible with scheduling loop frames
- * @param {InspectorUI} aInspectorUI
- *                      necessary instance of the InspectorUI
  * @param {Object} aNotifications
  *                 necessary notifications for Tilt
  * @param {Function} onError
  *                   function called if initialization failed
  * @param {Function} onLoad
  *                   function called if initialization worked
  */
 TiltVisualizer.Presenter = function TV_Presenter(
-  aCanvas, aContentWindow, aRequestAnimationFrame, aInspectorUI, aNotifications,
+  aCanvas, aChromeWindow, aContentWindow, aRequestAnimationFrame, aNotifications,
   onError, onLoad)
 {
+  /**
+   * A canvas overlay used for drawing the visualization.
+   */
   this.canvas = aCanvas;
+
+  /**
+   * Save a reference to the top-level window, to access InspectorUI or Tilt.
+   */
+  this.chromeWindow = aChromeWindow;
+
+  /**
+   * The content window generating the visualization
+   */
   this.contentWindow = aContentWindow;
-  this.inspectorUI = aInspectorUI;
-  this.tiltUI = aInspectorUI.chromeWin.Tilt;
 
   /**
    * Shortcut for accessing notifications strings.
    */
   this.NOTIFICATIONS = aNotifications;
 
   /**
    * Create the renderer, containing useful functions for easy drawing.
@@ -230,17 +248,17 @@ TiltVisualizer.Presenter = function TV_P
     v3: vec3.create()
   };
 
   /**
    * Scene transformations, exposing offset, translation and rotation.
    * Modified by events in the controller through delegate functions.
    */
   this.transforms = {
-    zoom: TiltUtils.getDocumentZoom(),
+    zoom: TiltUtils.getDocumentZoom(aChromeWindow),
     offset: vec3.create(),      // mesh offset, aligned to the viewport center
     translation: vec3.create(), // scene translation, on the [x, y, z] axis
     rotation: quat4.create()    // scene rotation, expressed as a quaternion
   };
 
   /**
    * Variables holding information about the initial and current node selected.
    */
@@ -520,23 +538,23 @@ TiltVisualizer.Presenter.prototype = {
     this.meshWireframe = {
       vertices: this.meshStacks.vertices,
       indices: new renderer.IndexBuffer(aData.wireframeIndices)
     };
 
     // if there's no initial selection made, highlight the required node
     if (!this._initialSelection) {
       this._initialSelection = true;
-      this.highlightNode(this.inspectorUI.selection);
+      this.highlightNode(this.chromeWindow.InspectorUI.selection);
     }
 
     if (!this._initialMeshConfiguration) {
       this._initialMeshConfiguration = true;
 
-      let zoom = TiltUtils.getDocumentZoom();
+      let zoom = this.transforms.zoom;
       let width = Math.min(aData.meshWidth * zoom, renderer.width);
       let height = Math.min(aData.meshHeight * zoom, renderer.height);
 
       // set the necessary mesh offsets
       this.transforms.offset[0] = -width * 0.5;
       this.transforms.offset[1] = -height * 0.5;
 
       // make sure the canvas is opaque now that the initialization is finished
@@ -600,17 +618,17 @@ TiltVisualizer.Presenter.prototype = {
     this.contentWindow.addEventListener("resize", this.onResize, false);
   },
 
   /**
    * Called when the content window of the current browser is resized.
    */
   onResize: function TVP_onResize(e)
   {
-    let zoom = TiltUtils.getDocumentZoom();
+    let zoom = TiltUtils.getDocumentZoom(this.chromeWindow);
     let width = e.target.innerWidth * zoom;
     let height = e.target.innerHeight * zoom;
 
     // handle aspect ratio changes to update the projection matrix
     this.renderer.width = width;
     this.renderer.height = height;
 
     this.redraw = true;
@@ -719,18 +737,20 @@ TiltVisualizer.Presenter.prototype = {
     let z = info.depth;
 
     vec3.set([x,     y,     z * STACK_THICKNESS], highlight.v0);
     vec3.set([x + w, y,     z * STACK_THICKNESS], highlight.v1);
     vec3.set([x + w, y + h, z * STACK_THICKNESS], highlight.v2);
     vec3.set([x,     y + h, z * STACK_THICKNESS], highlight.v3);
 
     this._currentSelection = aNodeIndex;
-    this.inspectorUI.inspectNode(node, this.contentWindow.innerHeight < y ||
-                                       this.contentWindow.pageYOffset > 0);
+
+    this.chromeWindow.InspectorUI.inspectNode(node,
+      this.contentWindow.innerHeight < y ||
+      this.contentWindow.pageYOffset > 0);
 
     Services.obs.notifyObservers(null, this.NOTIFICATIONS.HIGHLIGHTING, null);
   },
 
   /**
    * Deletes a node from the visualization mesh.
    *
    * @param {Number} aNodeIndex
@@ -791,17 +811,17 @@ TiltVisualizer.Presenter.prototype = {
         }
       } else {
         if ("function" === typeof aProperties.onfail) {
           aProperties.onfail();
         }
       }
     }, false);
 
-    let zoom = TiltUtils.getDocumentZoom();
+    let zoom = TiltUtils.getDocumentZoom(this.chromeWindow);
     let width = this.renderer.width * zoom;
     let height = this.renderer.height * zoom;
     let mesh = this.meshStacks;
     x *= zoom;
     y *= zoom;
 
     // create a ray following the mouse direction from the near clipping plane
     // to the far clipping plane, to check for intersections with the mesh,
@@ -966,36 +986,44 @@ TiltVisualizer.Presenter.prototype = {
  *
  * @param {HTMLCanvasElement} aCanvas
  *                            the visualization canvas element
  * @param {TiltVisualizer.Presenter} aPresenter
  *                                   the presenter instance to control
  */
 TiltVisualizer.Controller = function TV_Controller(aCanvas, aPresenter)
 {
+  /**
+   * A canvas overlay on which mouse and keyboard event listeners are attached.
+   */
   this.canvas = aCanvas;
+
+  /**
+   * Save a reference to the presenter to modify its model-view transforms.
+   */
   this.presenter = aPresenter;
 
   /**
    * The initial controller dimensions and offset, in pixels.
    */
-  this.left = aPresenter.contentWindow.pageXOffset || 0;
-  this.top = aPresenter.contentWindow.pageYOffset || 0;
+  this.zoom = aPresenter.transforms.zoom;
+  this.left = (aPresenter.contentWindow.pageXOffset || 0) * this.zoom;
+  this.top = (aPresenter.contentWindow.pageYOffset || 0) * this.zoom;
   this.width = aCanvas.width;
   this.height = aCanvas.height;
 
-  this.left *= TiltUtils.getDocumentZoom();
-  this.top *= TiltUtils.getDocumentZoom();
-
   /**
    * Arcball used to control the visualization using the mouse.
    */
-  this.arcball = new TiltVisualizer.Arcball(this.width, this.height, 0,
-    [this.width + this.left < aPresenter.maxTextureSize ? -this.left : 0,
-     this.height + this.top < aPresenter.maxTextureSize ? -this.top : 0]);
+  this.arcball = new TiltVisualizer.Arcball(
+    this.presenter.chromeWindow, this.width, this.height, 0,
+    [
+      this.width + this.left < aPresenter.maxTextureSize ? -this.left : 0,
+      this.height + this.top < aPresenter.maxTextureSize ? -this.top : 0
+    ]);
 
   /**
    * Object containing the rotation quaternion and the translation amount.
    */
   this.coordinates = null;
 
   // bind the owner object to the necessary functions
   TiltUtils.bindObjectFunc(this, "update");
@@ -1187,17 +1215,17 @@ TiltVisualizer.Controller.prototype = {
   },
 
   /**
    * Called when a key is released.
    */
   onKeyUp: function TVC_onKeyUp(e)
   {
     let code = e.keyCode || e.which;
-    let tilt = this.presenter.tiltUI;
+    let tilt = this.presenter.chromeWindow.Tilt;
 
     if (code === e.DOM_VK_ESCAPE) {
       tilt.destroy(tilt.currentWindowId, true);
       return;
     }
     if (code === e.DOM_VK_X) {
       this.presenter.deleteNode();
     }
@@ -1216,17 +1244,17 @@ TiltVisualizer.Controller.prototype = {
     this.arcball.cancelKeyEvents();
   },
 
   /**
    * Called when the content window of the current browser is resized.
    */
   onResize: function TVC_onResize(e)
   {
-    let zoom = TiltUtils.getDocumentZoom();
+    let zoom = TiltUtils.getDocumentZoom(this.presenter.chromeWindow);
     let width = e.target.innerWidth * zoom;
     let height = e.target.innerHeight * zoom;
 
     this.arcball.resize(width, height);
   },
 
   /**
    * Checks if this object was initialized properly.
@@ -1251,31 +1279,38 @@ TiltVisualizer.Controller.prototype = {
   }
 };
 
 /**
  * This is a general purpose 3D rotation controller described by Ken Shoemake
  * in the Graphics Interface ’92 Proceedings. It features good behavior
  * easy implementation, cheap execution.
  *
+ * @param {Window} aChromeWindow
+ *                 a reference to the top-level window
  * @param {Number} aWidth
  *                 the width of canvas
  * @param {Number} aHeight
  *                 the height of canvas
  * @param {Number} aRadius
  *                 optional, the radius of the arcball
  * @param {Array} aInitialTrans
  *                optional, initial vector translation
  * @param {Array} aInitialRot
  *                optional, initial quaternion rotation
  */
 TiltVisualizer.Arcball = function TV_Arcball(
-  aWidth, aHeight, aRadius, aInitialTrans, aInitialRot)
+  aChromeWindow, aWidth, aHeight, aRadius, aInitialTrans, aInitialRot)
 {
   /**
+   * Save a reference to the top-level window to set/remove intervals.
+   */
+  this.chromeWindow = aChromeWindow;
+
+  /**
    * Values retaining the current horizontal and vertical mouse coordinates.
    */
   this._mousePress = vec3.create();
   this._mouseRelease = vec3.create();
   this._mouseMove = vec3.create();
   this._mouseLerp = vec3.create();
   this._mouseButton = -1;
 
@@ -1720,38 +1755,37 @@ TiltVisualizer.Arcball.prototype = {
    */
   reset: function TVA_reset(aFinalTranslation, aFinalRotation)
   {
     if ("function" === typeof this.onResetStart) {
       this.onResetStart();
       this.onResetStart = null;
     }
 
+    let func = this._nextResetIntervalStep.bind(this);
+
     this.cancelMouseEvents();
     this.cancelKeyEvents();
     this._cancelResetInterval();
 
-    let window = TiltUtils.getBrowserWindow();
-    let func = this._nextResetIntervalStep.bind(this);
-
     this._save();
     this._resetFinalTranslation = vec3.create(aFinalTranslation);
     this._resetFinalRotation = quat4.create(aFinalRotation);
-    this._resetInterval = window.setInterval(func, ARCBALL_RESET_INTERVAL);
+    this._resetInterval =
+      this.chromeWindow.setInterval(func, ARCBALL_RESET_INTERVAL);
   },
 
   /**
    * Cancels the current arcball reset animation if there is one.
    */
   _cancelResetInterval: function TVA__cancelResetInterval()
   {
     if (this._resetInterval) {
-      let window = TiltUtils.getBrowserWindow();
+      this.chromeWindow.clearInterval(this._resetInterval);
 
-      window.clearInterval(this._resetInterval);
       this._resetInterval = null;
       this._save();
 
       if ("function" === typeof this.onResetFinish) {
         this.onResetFinish();
         this.onResetFinish = null;
       }
     }
--- a/browser/devtools/tilt/test/browser_tilt_arcball.js
+++ b/browser/devtools/tilt/test/browser_tilt_arcball.js
@@ -23,37 +23,37 @@ function isExpectedUpdate(update1, updat
                                           JSON.stringify(update2) + " instead.");
       return false;
     }
   }
   return true;
 }
 
 function test() {
-  let arcball1 = new TiltVisualizer.Arcball(123, 456);
+  let arcball1 = new TiltVisualizer.Arcball(window, 123, 456);
 
   is(arcball1.width, 123,
     "The first arcball width wasn't set correctly.");
   is(arcball1.height, 456,
     "The first arcball height wasn't set correctly.");
   is(arcball1.radius, 123,
     "The first arcball radius wasn't implicitly set correctly.");
 
 
-  let arcball2 = new TiltVisualizer.Arcball(987, 654);
+  let arcball2 = new TiltVisualizer.Arcball(window, 987, 654);
 
   is(arcball2.width, 987,
     "The second arcball width wasn't set correctly.");
   is(arcball2.height, 654,
     "The second arcball height wasn't set correctly.");
   is(arcball2.radius, 654,
     "The second arcball radius wasn't implicitly set correctly.");
 
 
-  let arcball3 = new TiltVisualizer.Arcball(512, 512);
+  let arcball3 = new TiltVisualizer.Arcball(window, 512, 512);
 
   let sphereVec = vec3.create();
   arcball3.pointToSphere(123, 456, 256, 512, 512, sphereVec);
 
   ok(isApproxVec(sphereVec, [-0.009765625, 0.390625, 0.9204980731010437]),
     "The pointToSphere() function didn't map the coordinates correctly.");
 
   let stack1 = [];
--- a/browser/devtools/tilt/test/browser_tilt_utils06.js
+++ b/browser/devtools/tilt/test/browser_tilt_utils06.js
@@ -38,13 +38,9 @@ function test() {
     "The finalize function wasn't called when an object was destroyed.");
 
 
   TiltUtils.destroyObject(someObject);
   is(typeof someObject.a, "undefined",
     "Not all members of the destroyed object were deleted.");
   is(typeof someObject.func, "undefined",
     "Not all function members of the destroyed object were deleted.");
-
-
-  is(TiltUtils.getBrowserWindow(), window,
-    "The getBrowserWindow() function didn't return the correct window.");
 }
--- a/browser/devtools/tilt/test/browser_tilt_visualizer.js
+++ b/browser/devtools/tilt/test/browser_tilt_visualizer.js
@@ -14,18 +14,19 @@ function test() {
     info("Skipping visualizer test because WebGL isn't supported.");
     return;
   }
 
   let webGLError = false;
   let webGLLoad = false;
 
   let visualizer = new TiltVisualizer({
+    chromeWindow: window,
+    contentWindow: gBrowser.selectedBrowser.contentWindow,
     parentNode: gBrowser.selectedBrowser.parentNode,
-    contentWindow: gBrowser.selectedBrowser.contentWindow,
     requestAnimationFrame: window.mozRequestAnimationFrame,
     inspectorUI: window.InspectorUI,
 
     onError: function onWebGLError()
     {
       webGLError = true;
     },
 
--- a/browser/devtools/tilt/test/browser_tilt_zoom.js
+++ b/browser/devtools/tilt/test/browser_tilt_zoom.js
@@ -4,27 +4,21 @@
 /*global ok, is, info, waitForExplicitFinish, finish, executeSoon, gBrowser */
 /*global isApprox, isTiltEnabled, isWebGLSupported, createTab, createTilt */
 /*global Services, EventUtils, TiltUtils, InspectorUI, DESTROYED */
 "use strict";
 
 const ZOOM = 2;
 const RESIZE = 50;
 
-function setZoom(value) {
-  gBrowser.selectedBrowser.markupDocumentViewer.fullZoom = value;
-}
+function test() {
+  let random = Math.random() * 10;
 
-function getZoom() {
-  return gBrowser.selectedBrowser.markupDocumentViewer.fullZoom;
-}
-
-function test() {
-  TiltUtils.setDocumentZoom(Math.random());
-  is(getZoom(), TiltUtils.getDocumentZoom(),
+  TiltUtils.setDocumentZoom(window, random);
+  ok(isApprox(TiltUtils.getDocumentZoom(window), random),
     "The getDocumentZoom utility function didn't return the expected results.");
 
 
   if (!isTiltEnabled()) {
     info("Skipping controller test because Tilt isn't enabled.");
     return;
   }
   if (!isWebGLSupported()) {
@@ -33,58 +27,58 @@ function test() {
   }
 
   waitForExplicitFinish();
 
   createTab(function() {
     createTilt({
       onInspectorOpen: function()
       {
-        setZoom(ZOOM);
+        TiltUtils.setDocumentZoom(window, ZOOM);
       },
       onTiltOpen: function(instance)
       {
         ok(isApprox(instance.presenter.transforms.zoom, ZOOM),
           "The presenter transforms zoom wasn't initially set correctly.");
 
         let contentWindow = gBrowser.selectedBrowser.contentWindow;
         let initialWidth = contentWindow.innerWidth;
         let initialHeight = contentWindow.innerHeight;
 
         let renderer = instance.presenter.renderer;
         let arcball = instance.controller.arcball;
 
         ok(isApprox(contentWindow.innerWidth * ZOOM, renderer.width, 1),
-          "The renderer width wasn't set correctly.");
+          "The renderer width wasn't set correctly before the resize.");
         ok(isApprox(contentWindow.innerHeight * ZOOM, renderer.height, 1),
-          "The renderer height wasn't set correctly.");
+          "The renderer height wasn't set correctly before the resize.");
 
         ok(isApprox(contentWindow.innerWidth * ZOOM, arcball.width, 1),
-          "The arcball width wasn't set correctly.");
+          "The arcball width wasn't set correctly before the resize.");
         ok(isApprox(contentWindow.innerHeight * ZOOM, arcball.height, 1),
-          "The arcball height wasn't set correctly.");
+          "The arcball height wasn't set correctly before the resize.");
 
 
         window.resizeBy(-RESIZE * ZOOM, -RESIZE * ZOOM);
 
         executeSoon(function() {
           ok(isApprox(contentWindow.innerWidth + RESIZE, initialWidth, 1),
-            "The content window width wasn't set correctly.");
+            "The content window width wasn't set correctly after the resize.");
           ok(isApprox(contentWindow.innerHeight + RESIZE, initialHeight, 1),
-            "The content window height wasn't set correctly.");
+            "The content window height wasn't set correctly after the resize.");
 
           ok(isApprox(contentWindow.innerWidth * ZOOM, renderer.width, 1),
-            "The renderer width wasn't set correctly.");
+            "The renderer width wasn't set correctly after the resize.");
           ok(isApprox(contentWindow.innerHeight * ZOOM, renderer.height, 1),
-            "The renderer height wasn't set correctly.");
+            "The renderer height wasn't set correctly after the resize.");
 
           ok(isApprox(contentWindow.innerWidth * ZOOM, arcball.width, 1),
-            "The arcball width wasn't set correctly.");
+            "The arcball width wasn't set correctly after the resize.");
           ok(isApprox(contentWindow.innerHeight * ZOOM, arcball.height, 1),
-            "The arcball height wasn't set correctly.");
+            "The arcball height wasn't set correctly after the resize.");
 
 
           window.resizeBy(RESIZE * ZOOM, RESIZE * ZOOM);
 
           Services.obs.addObserver(cleanup, DESTROYED, false);
           InspectorUI.closeInspectorUI();
         });
       },
--- a/browser/devtools/tilt/test/head.js
+++ b/browser/devtools/tilt/test/head.js
@@ -24,25 +24,25 @@ let TiltVisualizer = tempScope.TiltVisua
 const DEFAULT_HTML = "data:text/html," +
   "<DOCTYPE html>" +
   "<html>" +
     "<head>" +
       "<title>Three Laws</title>" +
     "</head>" +
     "<body>" +
       "<div id='first-law'>" +
-        "A robot may not injure a human being or, through inaction, allow a" +
+        "A robot may not injure a human being or, through inaction, allow a " +
         "human being to come to harm." +
       "</div>" +
       "<div>" +
-        "A robot must obey the orders given to it by human beings, except" +
+        "A robot must obey the orders given to it by human beings, except " +
         "where such orders would conflict with the First Law." +
       "</div>" +
       "<div>" +
-        "A robot must protect its own existence as long as such protection" +
+        "A robot must protect its own existence as long as such protection " +
         "does not conflict with the First or Second Laws." +
       "</div>" +
     "<body>" +
   "</html>";
 
 const INSPECTOR_OPENED = InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED;
 const INSPECTOR_CLOSED = InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED;