Bug 521233 - waitForFocus(callback) times out in browser chrome tests. use it in browser_bug304198.js, r=enn
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 28 Oct 2009 17:22:59 +0100
changeset 34249 032a9a176ee71612fbc62904a9256805163f9751
parent 34248 bd50193c589f61d5994583a75bdbe4a32545ad30
child 34250 24ce78dd533f34bc56aec9715bc005085931571e
push id9979
push usermak77@bonardo.net
push dateWed, 28 Oct 2009 16:23:42 +0000
treeherdermozilla-central@032a9a176ee7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn
bugs521233, 304198
milestone1.9.3a1pre
Bug 521233 - waitForFocus(callback) times out in browser chrome tests. use it in browser_bug304198.js, r=enn
browser/base/content/test/browser_bug304198.js
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/browser/base/content/test/browser_bug304198.js
+++ b/browser/base/content/test/browser_bug304198.js
@@ -33,23 +33,20 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   waitForExplicitFinish();
 
-  if (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow !=
-      window) {
-    setTimeout(test, 0);
-    window.focus();
-    return;
-  }
+  waitForFocus(continue_test);
+}
 
+function continue_test() {
   let charsToDelete, deletedURLTab, fullURLTab, partialURLTab, testPartialURL, testURL;
 
   charsToDelete = 5;
   deletedURLTab = gBrowser.addTab();
   fullURLTab = gBrowser.addTab();
   partialURLTab = gBrowser.addTab();
   testURL = "http://example.org/browser/browser/base/content/test/dummy_page.html";
 
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -233,16 +233,20 @@ SimpleTest.waitForFocus = function (call
       targetWindow = window;
 
     SimpleTest.waitForFocus_started = false;
 
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var fm = Components.classes["@mozilla.org/focus-manager;1"].
                         getService(Components.interfaces.nsIFocusManager);
 
+    var usedTargetWindow = {};
+    fm.getFocusedElementForWindow(targetWindow, true, usedTargetWindow);
+    targetWindow = usedTargetWindow.value;
+
     function debugFocusLog(prefix) {
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
         var baseWindow = targetWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                                      .getInterface(Components.interfaces.nsIWebNavigation)
                                      .QueryInterface(Components.interfaces.nsIBaseWindow);
         ok(true, prefix + " -- loaded: " + targetWindow.document.readyState +
            " active window: " +