Bug 736529 - Calling waitForFocus() and then finishing before you get focus should cause the test to fail; r=jmaher
authorAryeh Gregor <ayg@aryeh.name>
Mon, 19 Mar 2012 13:09:48 -0400
changeset 93475 54cb23113c6f00fe2cb0ae64fb5b687b4b4f92f0
parent 93474 ff86ef0b6b1c1435a27f809f296da5475e19144d
child 93476 93fc7bf5e5be1c0e647abbcf5675fdfbc028c4e7
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs736529
milestone14.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 736529 - Calling waitForFocus() and then finishing before you get focus should cause the test to fail; r=jmaher
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -462,16 +462,17 @@ SimpleTest.requestLongerTimeout = functi
     if (parentRunner) {
         parentRunner.requestLongerTimeout(factor);
     }
 }
 
 SimpleTest.waitForFocus_started = false;
 SimpleTest.waitForFocus_loaded = false;
 SimpleTest.waitForFocus_focused = false;
+SimpleTest._pendingWaitForFocusCount = 0;
 
 /**
  * If the page is not yet loaded, waits for the load event. In addition, if
  * the page is not yet focused, focuses and waits for the window to be
  * focused. Calls the callback when completed. If the current page is
  * 'about:blank', then the page is assumed to not yet be loaded. Pass true for
  * expectBlankPage to not make this assumption if you expect a blank page to
  * be present.
@@ -482,16 +483,17 @@ SimpleTest.waitForFocus_focused = false;
  * @param callback
  *        function called when load and focus are complete
  * @param targetWindow
  *        optional window to be loaded and focused, defaults to 'window'
  * @param expectBlankPage
  *        true if targetWindow.location is 'about:blank'. Defaults to false
  */
 SimpleTest.waitForFocus = function (callback, targetWindow, expectBlankPage) {
+    SimpleTest._pendingWaitForFocusCount++;
     if (!targetWindow)
       targetWindow = window;
 
     SimpleTest.waitForFocus_started = false;
     expectBlankPage = !!expectBlankPage;
 
     var childTargetWindow = {};
     SpecialPowers.getFocusedElementForWindow(targetWindow, true, childTargetWindow);
@@ -503,16 +505,17 @@ SimpleTest.waitForFocus = function (call
     function getHref(aWindow) {
       return SpecialPowers.getPrivilegedProps(aWindow, 'location.href');
     }
 
     function maybeRunTests() {
         if (SimpleTest.waitForFocus_loaded &&
             SimpleTest.waitForFocus_focused &&
             !SimpleTest.waitForFocus_started) {
+            SimpleTest._pendingWaitForFocusCount--;
             SimpleTest.waitForFocus_started = true;
             setTimeout(callback, 0, targetWindow);
         }
     }
 
     function waitForEvent(event) {
         try {
             // Check to make sure that this isn't a load event for a blank or
@@ -670,16 +673,25 @@ SimpleTest.executeSoon = function(aFunc)
 /**
  * Finishes the tests. This is automatically called, except when
  * SimpleTest.waitForExplicitFinish() has been invoked.
 **/
 SimpleTest.finish = function () {
     if (SimpleTest._expectingUncaughtException) {
         SimpleTest.ok(false, "expectUncaughtException was called but no uncaught exception was detected!");
     }
+    if (SimpleTest._pendingWaitForFocusCount != 0) {
+        SimpleTest.is(SimpleTest._pendingWaitForFocusCount, 0,
+                      "[SimpleTest.finish()] waitForFocus() was called a "
+                      + "different number of times from the number of "
+                      + "callbacks run.  Maybe the test terminated "
+                      + "prematurely -- be sure to use "
+                      + "SimpleTest.waitForExplicitFinish().");
+    }
+
     if (parentRunner) {
         /* We're running in an iframe, and the parent has a TestRunner */
         parentRunner.testFinished(SimpleTest._tests);
     } else {
         SimpleTest.showReport();
     }
 };