Bug 1492950 - Don't allow CPOW windows to be passed to SimpleTest.waitForFocus. r=NeilDeakin
authorMike Conley <mconley@mozilla.com>
Tue, 02 Oct 2018 17:53:12 +0000
changeset 494956 a1b2eb69cd3c3c99091518ef41dee7f9efd06373
parent 494955 492867ee197fedaa3fde8526e913cb6e59c4dab2
child 494957 1940595cb776790de40008a4b90d54356f5e5753
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1492950
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1492950 - Don't allow CPOW windows to be passed to SimpleTest.waitForFocus. r=NeilDeakin Depends on D6714 Differential Revision: https://phabricator.services.mozilla.com/D6715
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -726,17 +726,17 @@ SimpleTest.promiseFocus = function (targ
  * targetWindow should be specified if it is different than 'window'. The actual
  * focused window may be a descendant of targetWindow.
  *
  * @param callback
  *        function called when load and focus are complete
  * @param targetWindow
  *        optional window to be loaded and focused, defaults to 'window'.
  *        This may also be a <browser> element, in which case the window within
- *        that browser will be focused.
+ *        that browser will be focused. This cannot be a window CPOW.
  * @param expectBlankPage
  *        true if targetWindow.location is 'about:blank'. Defaults to false
  */
 SimpleTest.waitForFocus = function (callback, targetWindow, expectBlankPage) {
     // A separate method is used that is serialized and passed to the child
     // process via loadFrameScript. Once the child window is focused, the
     // child will send the WaitForFocus:ChildFocused notification to the parent.
     // If a child frame in a child process must be focused, a
@@ -883,45 +883,25 @@ SimpleTest.waitForFocus = function (call
     var browser = null;
     if (typeof(XULElement) != "undefined" &&
         targetWindow instanceof XULElement &&
         targetWindow.localName == "browser") {
         browser = targetWindow;
     }
 
     var isWrapper = Cu.isCrossProcessWrapper(targetWindow);
-    if (isWrapper || (browser && browser.isRemoteBrowser)) {
-        var mustFocusSubframe = false;
-        if (isWrapper) {
-            // Look for a tabbrowser and see if targetWindow corresponds to one
-            // within that tabbrowser. If not, just return.
-            var tabBrowser = window.gBrowser || null;
-            browser = tabBrowser ? tabBrowser.getBrowserForContentWindow(targetWindow.top) : null;
-            if (!browser) {
-                SimpleTest.info("child process window cannot be focused");
-                return;
-            }
-
-            mustFocusSubframe = (targetWindow != targetWindow.top);
-        }
+    if (isWrapper) {
+        throw new Error("Can't pass CPOW to SimpleTest.focus as the content window.");
+    }
 
-        // If a subframe in a child process needs to be focused, first focus the
-        // parent frame, then send a WaitForFocus:FocusChild message to the child
-        // containing the subframe to focus.
+    if (browser && browser.isRemoteBrowser) {
         browser.messageManager.addMessageListener("WaitForFocus:ChildFocused", function waitTest(msg) {
-            if (mustFocusSubframe) {
-                mustFocusSubframe = false;
-                var mm = gBrowser.selectedBrowser.messageManager;
-                mm.sendAsyncMessage("WaitForFocus:FocusChild", {}, { child: targetWindow } );
-            }
-            else {
-                browser.messageManager.removeMessageListener("WaitForFocus:ChildFocused", waitTest);
-                SimpleTest._pendingWaitForFocusCount--;
-                setTimeout(callback, 0, browser ? browser.contentWindowAsCPOW : targetWindow);
-            }
+            browser.messageManager.removeMessageListener("WaitForFocus:ChildFocused", waitTest);
+            SimpleTest._pendingWaitForFocusCount--;
+            setTimeout(callback, 0, browser);
         });
 
         // Serialize the waitForFocusInner function and run it in the child process.
         var frameScript = "data:,(" + waitForFocusInner.toString() +
                           ")(content, true, " + expectBlankPage + ");";
         browser.messageManager.loadFrameScript(frameScript, true);
         browser.focus();
     }