Bug 442125: check Date.now() to try to diagnose focus failures. r=ted
authorAndrew Schultz <ajschult@verizon.net>
Wed, 23 Jul 2008 13:32:30 -0400
changeset 16155 abd8bf7d25ca78c8915fac8623044e576d5977e5
parent 16148 403582828a52ea820cc2128b023efa2c163ae77d
child 16156 640290e9059cccf7aeb649762a1c3c001fe0e81f
push idunknown
push userunknown
push dateunknown
reviewersted
bugs442125
milestone1.9.1a2pre
Bug 442125: check Date.now() to try to diagnose focus failures. r=ted
testing/mochitest/tests/SimpleTest/TestRunner.js
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -64,33 +64,34 @@ TestRunner._toggle = function(el) {
         el.style.cssText = "width:0px; height:0px; border:0px;";
     }
 };
 
 
 /**
  * Creates the iframe that contains a test
 **/
-TestRunner._makeIframe = function (url, retry) {
+TestRunner._makeIframe = function (url, retry, startTime) {
     var iframe = $('testframe');
     window.scrollTo(0, $('indicator').offsetTop);
     if (url != "about:blank" && (!document.hasFocus() ||
         document.activeElement != iframe)) {
         // typically calling ourselves from setTimeout is sufficient
         // but we'll try focus() just in case that's needed
         window.focus();
         iframe.focus();
         if (retry < 3) {
-            window.setTimeout('TestRunner._makeIframe("'+url+'", '+(retry+1)+')', 1000);
+            window.setTimeout('TestRunner._makeIframe("'+url+'", '+(retry+1)+', '+startTime+')', 1000);
             return;
         }
 
         var frameWindow = $('testframe').contentWindow.wrappedJSObject ||
                           $('testframe').contentWindow;
-        frameWindow.SimpleTest.ok(false, "Unable to restore focus ("+
+        frameWindow.SimpleTest.ok(false, "Unable to restore focus after "+
+            ((Date.now()-startTime)/1000)+" seconds ("+
             (document.hasFocus() ? document.activeElement : "[none]")+
             "), expect failures and timeouts.");
     }
     iframe.src = url;
     iframe.name = url; 
     iframe.width = "500";
     return iframe;
 };
@@ -125,20 +126,20 @@ TestRunner.runNextTest = function() {
 
         $("current-test-path").innerHTML = url;
         
         TestRunner._currentTestStartTime = new Date().valueOf();
 
         if (TestRunner.logEnabled)
             TestRunner.logger.log("Running " + url + "...");
         
-        TestRunner._makeIframe(url, 0);
+        TestRunner._makeIframe(url, 0, Date.now());
     }  else {
         $("current-test").innerHTML = "<b>Finished</b>";
-        TestRunner._makeIframe("about:blank", 0);
+        TestRunner._makeIframe("about:blank", 0, Date.now());
         if (TestRunner.logEnabled) {
             TestRunner.logger.log("Passed: " + $("pass-count").innerHTML);
             TestRunner.logger.log("Failed: " + $("fail-count").innerHTML);
             TestRunner.logger.log("Todo:   " + $("todo-count").innerHTML);
             TestRunner.logger.log("SimpleTest FINISHED");
         }
         if (TestRunner.onComplete)
             TestRunner.onComplete();