Bug 529860 - Provide a method to enlarge timeout for some browser chrome tests, r=gavin
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 04 Dec 2009 15:13:22 +0100
changeset 37497 baaa8aea09abcdcd073e3cf8545dd41247c2367f
parent 37496 cd5868a825d86e29e495e5452421660893078858
child 37498 635d36218771d24c949f3a9b55fa21648b0ea3ec
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs529860
milestone1.9.3a1pre
Bug 529860 - Provide a method to enlarge timeout for some browser chrome tests, r=gavin
testing/mochitest/browser-test.js
testing/mochitest/tests/browser/Makefile.in
testing/mochitest/tests/browser/browser_requestLongerTimeout.js
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -202,16 +202,25 @@ Tester.prototype = {
     // If the test ran synchronously, move to the next test, otherwise the test
     // will trigger the next test when it is done.
     if (this.currentTest.scope.__done) {
       this.nextTest();
     }
     else {
       var self = this;
       this.currentTest.scope.__waitTimer = setTimeout(function() {
+        if (--self.currentTest.scope.__timeoutFactor > 0) {
+          // We were asked to wait a bit longer.
+          self.currentTest.scope.info(
+            "Longer timeout required, waiting longer...  Remaining timeouts: " +
+            self.currentTest.scope.__timeoutFactor);
+          self.currentTest.scope.__waitTimer =
+            setTimeout(arguments.callee, TIMEOUT_SECONDS * 1000);
+          return;
+        }
         self.currentTest.addResult(new testResult(false, "Timed out", "", false));
         self.currentTest.scope.__waitTimer = null;
         self.nextTest();
       }, TIMEOUT_SECONDS * 1000);
     }
   },
 
   QueryInterface: function(aIID) {
@@ -302,16 +311,20 @@ function testScope(aTester, aTest) {
   this.waitForFocus = function test_waitForFocus(callback, targetWindow) {
     self.SimpleTest.waitForFocus(callback, targetWindow);
   };
 
   this.registerCleanupFunction = function test_registerCleanupFunction(aFunction) {
     self.__cleanupFunctions.push(aFunction);
   };
 
+  this.requestLongerTimeout = function test_requestLongerTimeout(aFactor) {
+    self.__timeoutFactor = aFactor;
+  };
+
   this.finish = function test_finish() {
     self.__done = true;
     if (self.__waitTimer) {
       self.executeSoon(function() {
         if (self.__done && self.__waitTimer) {
           clearTimeout(self.__waitTimer);
           self.__waitTimer = null;
           self.__tester.nextTest();
@@ -319,12 +332,13 @@ function testScope(aTester, aTest) {
       });
     }
   };
 }
 testScope.prototype = {
   __done: true,
   __waitTimer: null,
   __cleanupFunctions: [],
+  __timeoutFactor: 1,
 
   EventUtils: {},
   SimpleTest: {}
 };
--- a/testing/mochitest/tests/browser/Makefile.in
+++ b/testing/mochitest/tests/browser/Makefile.in
@@ -53,12 +53,14 @@ include $(topsrcdir)/config/rules.mk
 # Disabled, these are only good for testing the harness' failure reporting
 #	                  browser_zz_fail_openwindow.js \
 #	                  browser_fail.js \
 #	                  browser_fail_async_throw.js \
 #	                  browser_fail_fp.js \
 #	                  browser_fail_pf.js \
 #	                  browser_fail_throw.js \
 #	                  browser_fail_timeout.js \
+# Disabled because it would take too long, useful to check functionality though.
+#	                  browser_requestLongerTimeout.js \
 	                  $(NULL)
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_requestLongerTimeout.js
@@ -0,0 +1,9 @@
+function test() {
+  requestLongerTimeout(2);
+  function end() {
+    ok(true, "should not time out");
+    finish();
+  }
+  waitForExplicitFinish();
+  setTimeout(end, 40000);
+}