Bug 1392339 - Fix misuse of nsIDOMWindow in API docs. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 21 Aug 2017 18:52:18 +0100
changeset 650077 f0cc8020252cb5d85808a8a982912cad56fa79fb
parent 650074 a9d372645a32b8d23d44244f351639af9d73b96a
child 650078 6ebe77e8ce30ec9eb5fadb78b45dca30582ee639
push id75256
push userbmo:ato@sny.no
push dateMon, 21 Aug 2017 17:57:12 +0000
reviewersautomatedtester
bugs1392339
milestone57.0a1
Bug 1392339 - Fix misuse of nsIDOMWindow in API docs. r?automatedtester nsIDOMWindow is the XPCOM interface and not what we mean in all these cases. We either want to refer to the ChromeWindow or to the WindowProxy, depending on the context of the code. MozReview-Commit-ID: 405po1XLXRi
testing/marionette/action.js
testing/marionette/browser.js
testing/marionette/driver.js
testing/marionette/element.js
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -1116,86 +1116,89 @@ function toEvents(tickDuration, seenEls,
 
 /**
  * Dispatch a keyDown action equivalent to pressing a key on a keyboard.
  *
  * @param {action.Action} a
  *     Action to dispatch.
  * @param {action.InputState} inputState
  *     Input state for this action's input source.
- * @param {nsIDOMWindow} win
- *     Current window.
+ * @param {WindowProxy} window
+ *     Current window global.
  *
  * @return {Promise}
  *     Promise to dispatch at least a keydown event, and keypress if
  *     appropriate.
  */
-function dispatchKeyDown(a, inputState, win) {
+function dispatchKeyDown(a, inputState, window) {
   return new Promise(resolve => {
     let keyEvent = new action.Key(a.value);
     keyEvent.repeat = inputState.isPressed(keyEvent.key);
     inputState.press(keyEvent.key);
     if (keyEvent.key in MODIFIER_NAME_LOOKUP) {
       inputState.setModState(keyEvent.key, true);
     }
+
     // Append a copy of |a| with keyUp subtype
     action.inputsToCancel.push(Object.assign({}, a, {subtype: action.KeyUp}));
     keyEvent.update(inputState);
-    event.sendKeyDown(a.value, keyEvent, win);
+    event.sendKeyDown(a.value, keyEvent, window);
 
     resolve();
   });
 }
 
 /**
  * Dispatch a keyUp action equivalent to releasing a key on a keyboard.
  *
  * @param {action.Action} a
  *     Action to dispatch.
  * @param {action.InputState} inputState
  *     Input state for this action's input source.
- * @param {nsIDOMWindow} win
- *     Current window.
+ * @param {WindowProxy} window
+ *     Current window global.
  *
  * @return {Promise}
  *     Promise to dispatch a keyup event.
  */
-function dispatchKeyUp(a, inputState, win) {
+function dispatchKeyUp(a, inputState, window) {
   return new Promise(resolve => {
     let keyEvent = new action.Key(a.value);
+
     if (!inputState.isPressed(keyEvent.key)) {
       resolve();
       return;
     }
+
     if (keyEvent.key in MODIFIER_NAME_LOOKUP) {
       inputState.setModState(keyEvent.key, false);
     }
     inputState.release(keyEvent.key);
     keyEvent.update(inputState);
-    event.sendKeyUp(a.value, keyEvent, win);
 
+    event.sendKeyUp(a.value, keyEvent, window);
     resolve();
   });
 }
 
 /**
  * Dispatch a pointerDown action equivalent to pressing a pointer-device
  * button.
  *
  * @param {action.Action} a
  *     Action to dispatch.
  * @param {action.InputState} inputState
  *     Input state for this action's input source.
- * @param {nsIDOMWindow} win
- *     Current window.
+ * @param {WindowProxy} window
+ *     Current window global.
  *
  * @return {Promise}
  *     Promise to dispatch at least a pointerdown event.
  */
-function dispatchPointerDown(a, inputState, win) {
+function dispatchPointerDown(a, inputState, window) {
   return new Promise(resolve => {
     if (inputState.isPressed(a.button)) {
       resolve();
       return;
     }
 
     inputState.press(a.button);
     // Append a copy of |a| with pointerUp subtype
@@ -1205,25 +1208,25 @@ function dispatchPointerDown(a, inputSta
     switch (inputState.subtype) {
       case action.PointerType.Mouse:
         let mouseEvent = new action.Mouse("mousedown", a.button);
         mouseEvent.update(inputState);
         event.synthesizeMouseAtPoint(
             inputState.x,
             inputState.y,
             mouseEvent,
-            win);
+            window);
         if (event.MouseButton.isSecondary(a.button)) {
           let contextMenuEvent = Object.assign({},
               mouseEvent, {type: "contextmenu"});
           event.synthesizeMouseAtPoint(
               inputState.x,
               inputState.y,
               contextMenuEvent,
-              win);
+              window);
         }
         break;
 
       case action.PointerType.Pen:
       case action.PointerType.Touch:
         throw new UnsupportedOperationError("Only 'mouse' pointer type is supported");
 
       default:
@@ -1237,42 +1240,47 @@ function dispatchPointerDown(a, inputSta
 /**
  * Dispatch a pointerUp action equivalent to releasing a pointer-device
  * button.
  *
  * @param {action.Action} a
  *     Action to dispatch.
  * @param {action.InputState} inputState
  *     Input state for this action's input source.
- * @param {nsIDOMWindow} win
- *     Current window.
+ * @param {WindowProxy} window
+ *     Current window global.
  *
  * @return {Promise}
  *     Promise to dispatch at least a pointerup event.
  */
-function dispatchPointerUp(a, inputState, win) {
+function dispatchPointerUp(a, inputState, window) {
   return new Promise(resolve => {
     if (!inputState.isPressed(a.button)) {
       resolve();
       return;
     }
+
     inputState.release(a.button);
+
     switch (inputState.subtype) {
       case action.PointerType.Mouse:
         let mouseEvent = new action.Mouse("mouseup", a.button);
         mouseEvent.update(inputState);
-        event.synthesizeMouseAtPoint(inputState.x, inputState.y,
-            mouseEvent, win);
+        event.synthesizeMouseAtPoint(
+            inputState.x, inputState.y, mouseEvent, window);
         break;
+
       case action.PointerType.Pen:
       case action.PointerType.Touch:
         throw new UnsupportedOperationError("Only 'mouse' pointer type is supported");
+
       default:
         throw new TypeError(`Unknown pointer type: ${inputState.subtype}`);
     }
+
     resolve();
   });
 }
 
 /**
  * Dispatch a pointerMove action equivalent to moving pointer device in
  * a line.
  *
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -41,61 +41,56 @@ browser.getBrowserForTab = function(tab)
   }
 
   return null;
 };
 
 /**
  * Return the tab browser for the specified chrome window.
  *
- * @param {nsIDOMWindow} win
- *     The window whose tabbrowser needs to be accessed.
+ * @param {ChromeWindow} win
+ *     Window whose <code>tabbrowser</code> needs to be accessed.
  *
  * @return {Tab}
  *     Tab browser or null if it's not a browser window.
  */
-browser.getTabBrowser = function(win) {
+browser.getTabBrowser = function(window) {
   // Fennec
-  if ("BrowserApp" in win) {
-    return win.BrowserApp;
+  if ("BrowserApp" in window) {
+    return window.BrowserApp;
 
   // Firefox
-  } else if ("gBrowser" in win) {
-    return win.gBrowser;
+  } else if ("gBrowser" in window) {
+    return window.gBrowser;
   }
 
   return null;
 };
 
 /**
  * Creates a browsing context wrapper.
  *
  * Browsing contexts handle interactions with the browser, according to
  * the current environment (Firefox, Fennec).
- *
- * @param {nsIDOMWindow} win
- *     The window whose browser needs to be accessed.
- * @param {GeckoDriver} driver
- *     Reference to the driver the browser is attached to.
  */
 browser.Context = class {
 
   /**
    * @param {ChromeWindow} win
    *     ChromeWindow that contains the top-level browsing context.
    * @param {GeckoDriver} driver
    *     Reference to driver instance.
    */
-  constructor(win, driver) {
-    this.window = win;
+  constructor(window, driver) {
+    this.window = window;
     this.driver = driver;
 
     // In Firefox this is <xul:tabbrowser> (not <xul:browser>!)
     // and BrowserApp in Fennec
-    this.tabBrowser = browser.getTabBrowser(win);
+    this.tabBrowser = browser.getTabBrowser(this.window);
 
     this.knownFrames = [];
 
     // Used to set curFrameId upon new session
     this.newSession = true;
 
     this.seenEls = new element.Store();
 
@@ -293,29 +288,29 @@ browser.Context = class {
   }
 
   /**
    * Set the current tab.
    *
    * @param {number=} index
    *     Tab index to switch to. If the parameter is undefined,
    *     the currently selected tab will be used.
-   * @param {nsIDOMWindow=} win
+   * @param {ChromeWindow=} window
    *     Switch to this window before selecting the tab.
    * @param {boolean=} focus
    *      A boolean value which determins whether to focus
    *      the window. Defaults to true.
    *
    * @throws UnsupportedOperationError
    *     If tab handling for the current application isn't supported.
    */
-  switchToTab(index, win, focus = true) {
-    if (win) {
-      this.window = win;
-      this.tabBrowser = browser.getTabBrowser(win);
+  switchToTab(index, window = undefined, focus = true) {
+    if (window) {
+      this.window = window;
+      this.tabBrowser = browser.getTabBrowser(this.window);
     }
 
     if (!this.tabBrowser) {
       return;
     }
 
     if (typeof index == "undefined") {
       this.tab = this.tabBrowser.selectedTab;
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -456,66 +456,66 @@ GeckoDriver.prototype.addFrameCloseListe
     }
   };
   win.addEventListener("mozbrowserclose", this.mozBrowserClose, true);
 };
 
 /**
  * Create a new browsing context for window and add to known browsers.
  *
- * @param {nsIDOMWindow} win
+ * @param {ChromeWindow} win
  *     Window for which we will create a browsing context.
  *
  * @return {string}
  *     Returns the unique server-assigned ID of the window.
  */
-GeckoDriver.prototype.addBrowser = function(win) {
-  let bc = new browser.Context(win, this);
-  let winId = getOuterWindowId(win);
+GeckoDriver.prototype.addBrowser = function(window) {
+  let bc = new browser.Context(window, this);
+  let winId = getOuterWindowId(window);
 
   this.browsers[winId] = bc;
   this.curBrowser = this.browsers[winId];
   if (!this.wins.has(winId)) {
     // add this to seenItems so we can guarantee
     // the user will get winId as this window's id
-    this.wins.set(winId, win);
+    this.wins.set(winId, window);
   }
 };
 
 /**
  * Registers a new browser, win, with Marionette.
  *
  * If we have not seen the browser content window before, the listener
  * frame script will be loaded into it.  If isNewSession is true, we will
  * switch focus to the start frame when it registers.
  *
- * @param {nsIDOMWindow} win
+ * @param {ChromeWindow} win
  *     Window whose browser we need to access.
  * @param {boolean=} [false] isNewSession
  *     True if this is the first time we're talking to this browser.
  */
-GeckoDriver.prototype.startBrowser = function(win, isNewSession = false) {
-  this.mainFrame = win;
+GeckoDriver.prototype.startBrowser = function(window, isNewSession = false) {
+  this.mainFrame = window;
   this.curFrame = null;
-  this.addBrowser(win);
+  this.addBrowser(window);
   this.curBrowser.isNewSession = isNewSession;
-  this.whenBrowserStarted(win, isNewSession);
+  this.whenBrowserStarted(window, isNewSession);
 };
 
 /**
  * Callback invoked after a new session has been started in a browser.
  * Loads the Marionette frame script into the browser if needed.
  *
- * @param {nsIDOMWindow} win
+ * @param {ChromeWindow} window
  *     Window whose browser we need to access.
  * @param {boolean} isNewSession
  *     True if this is the first time we're talking to this browser.
  */
-GeckoDriver.prototype.whenBrowserStarted = function(win, isNewSession) {
-  let mm = win.window.messageManager;
+GeckoDriver.prototype.whenBrowserStarted = function(window, isNewSession) {
+  let mm = window.messageManager;
   if (mm) {
     if (!isNewSession) {
       // Loading the frame script corresponds to a situation we need to
       // return to the server. If the messageManager is a message broadcaster
       // with no children, we don't have a hope of coming back from this
       // call, so send the ack here. Otherwise, make a note of how many
       // child scripts will be loaded so we known when it's safe to return.
       // Child managers may not have child scripts yet (e.g. socialapi),
@@ -534,18 +534,17 @@ GeckoDriver.prototype.whenBrowserStarted
     if (!Preferences.get(CONTENT_LISTENER_PREF) || !isNewSession) {
       // load listener into the remote frame
       // and any applicable new frames
       // opened after this call
       mm.loadFrameScript(FRAME_SCRIPT, true);
       Preferences.set(CONTENT_LISTENER_PREF, true);
     }
   } else {
-    logger.error(
-        `Could not load listener into content for page ${win.location.href}`);
+    logger.error("Unable to load content frame script");
   }
 };
 
 /**
  * Recursively get all labeled text.
  *
  * @param {nsIDOMElement} el
  *     The parent element.
@@ -3696,22 +3695,13 @@ function copy(obj) {
   if (Array.isArray(obj)) {
     return obj.slice();
   } else if (typeof obj == "object") {
     return Object.assign({}, obj);
   }
   return obj;
 }
 
-/**
- * Get the outer window ID for the specified window.
- *
- * @param {nsIDOMWindow} win
- *     Window whose browser we need to access.
- *
- * @return {string}
- *     Returns the unique window ID.
- */
 function getOuterWindowId(win) {
   return win.QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIDOMWindowUtils)
       .outerWindowID;
 }
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -150,18 +150,18 @@ element.Store = class {
     return Object.keys(this.els).includes(uuid);
   }
 
   /**
    * Retrieve a DOM element by its unique web element reference/UUID.
    *
    * @param {string} uuid
    *     Web element reference, or UUID.
-   * @param {(nsIDOMWindow|ShadowRoot)} container
-   * Window and an optional shadow root that contains the element.
+   * @param {Object.<string, (WindowProxy|Element)} container
+   *     Window and an optional shadow root that contains the element.
    *
    * @returns {nsIDOMElement}
    *     Element associated with reference.
    *
    * @throws {NoSuchElementError}
    *     If the provided reference is unknown.
    * @throws {StaleElementReferenceError}
    *     If element has gone stale, indicating it is no longer attached to
@@ -876,34 +876,35 @@ element.isObscured = function(el) {
 
 // TODO(ato): Only used by deprecated action API
 // https://bugzil.la/1354578
 /**
  * Calculate the in-view centre point of the area of the given DOM client
  * rectangle that is inside the viewport.
  *
  * @param {DOMRect} rect
- *     Element off a DOMRect sequence produced by calling |getClientRects|
- *     on a |DOMElement|.
- * @param {nsIDOMWindow} win
- *     Current browsing context.
+ *     Element off a DOMRect sequence produced by calling
+ *     <code>getClientRects</code> on an {@link Element}.
+ * @param {WindowProxy} window
+ *     Current window global.
  *
  * @return {Map.<string, number>}
- *     X and Y coordinates that denotes the in-view centre point of |rect|.
+ *     X and Y coordinates that denotes the in-view centre point of
+ *     <var>rect</var>.
  */
-element.getInViewCentrePoint = function(rect, win) {
+element.getInViewCentrePoint = function(rect, window) {
   const {max, min} = Math;
 
   let x = {
     left: max(0, min(rect.x, rect.x + rect.width)),
-    right: min(win.innerWidth, max(rect.x, rect.x + rect.width)),
+    right: min(window.innerWidth, max(rect.x, rect.x + rect.width)),
   };
   let y = {
     top: max(0, min(rect.y, rect.y + rect.height)),
-    bottom: min(win.innerHeight, max(rect.y, rect.y + rect.height)),
+    bottom: min(window.innerHeight, max(rect.y, rect.y + rect.height)),
   };
 
   return {
     x: (x.left + x.right) / 2,
     y: (y.top + y.bottom) / 2,
   };
 };