Bug 1254091 - part 2: fix focus messaging from SpecialPowers to refer to the right window, r?enndeakin draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 18 Mar 2016 18:29:27 +0000
changeset 342233 c3c3b938cd3c00b5bdce37ec33132cca1ee7e69d
parent 342232 508a514ca251a5ab1d901a1ede54b496bad8b388
child 342234 e7354e8dfdd62291f1a0b43ffcd6c80fe20b0217
push id13376
push usergijskruitbosch@gmail.com
push dateFri, 18 Mar 2016 18:32:09 +0000
reviewersenndeakin
bugs1254091
milestone48.0a1
Bug 1254091 - part 2: fix focus messaging from SpecialPowers to refer to the right window, r?enndeakin MozReview-Commit-ID: DMnK23GoerQ
testing/specialpowers/content/specialpowersAPI.js
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 /* This code is loaded in every child process that is started by mochitest in
  * order to be used as a replacement for UniversalXPConnect
  */
 
 "use strict";
 
+var global = this;
+
 var Ci = Components.interfaces;
 var Cc = Components.classes;
 var Cu = Components.utils;
 
 Cu.import("chrome://specialpowers/content/MockFilePicker.jsm");
 Cu.import("chrome://specialpowers/content/MockColorPicker.jsm");
 Cu.import("chrome://specialpowers/content/MockPermissionPrompt.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
@@ -1619,17 +1621,24 @@ SpecialPowersAPI.prototype = {
     return this.focusManager.focusedWindow;
   },
 
   focus: function(aWindow) {
     // This is called inside TestRunner._makeIframe without aWindow, because of assertions in oop mochitests
     // With aWindow, it is called in SimpleTest.waitForFocus to allow popup window opener focus switching
     if (aWindow)
       aWindow.focus();
-    sendAsyncMessage("SpecialPowers.Focus", {});
+    var mm = global;
+    if (aWindow) {
+      mm = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                                  .getInterface(Ci.nsIDocShell)
+                                  .QueryInterface(Ci.nsIInterfaceRequestor)
+                                  .getInterface(Ci.nsIContentFrameMessageManager);
+    }
+    mm.sendAsyncMessage("SpecialPowers.Focus", {});
   },
 
   getClipboardData: function(flavor, whichClipboard) {
     if (this._cb == null)
       this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
                             getService(Components.interfaces.nsIClipboard);
     if (whichClipboard === undefined)
       whichClipboard = this._cb.kGlobalClipboard;