Bug 1259651 - Add the ability to register callback functions to be notified when a mochitest times out to SimpleTest. r=ted.
authorJW Wang <jwwang@mozilla.com>
Fri, 01 Apr 2016 07:42:43 +0800
changeset 291115 b78ed68af2fb7051771b49260d7f5394a7c30c63
parent 291114 c3fb02405b68aca36fdc60e556e13e49fe5482b0
child 291116 7f8bd64aaadd033af0bd933cbb0f2dca4c2b9245
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1259651
milestone48.0a1
Bug 1259651 - Add the ability to register callback functions to be notified when a mochitest times out to SimpleTest. r=ted. MozReview-Commit-ID: 2p7qqFMxHpW
testing/mochitest/tests/SimpleTest/SimpleTest.js
testing/mochitest/tests/SimpleTest/TestRunner.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -212,16 +212,17 @@ if (typeof(computedStyle) == 'undefined'
 
         return style.getPropertyValue(selectorCase);
     };
 }
 
 SimpleTest._tests = [];
 SimpleTest._stopOnLoad = true;
 SimpleTest._cleanupFunctions = [];
+SimpleTest._timeoutFunctions = [];
 SimpleTest.expected = 'pass';
 SimpleTest.num_failed = 0;
 SimpleTest._inChaosMode = false;
 
 SimpleTest.setExpected = function () {
   if (parent.TestRunner) {
     SimpleTest.expected = parent.TestRunner.expected;
   }
@@ -983,25 +984,36 @@ SimpleTest.executeSoon = function(aFunc)
     setTimeout(aFunc, 0);
     return null;		// Avoid warning.
 };
 
 SimpleTest.registerCleanupFunction = function(aFunc) {
     SimpleTest._cleanupFunctions.push(aFunc);
 };
 
+SimpleTest.registerTimeoutFunction = function(aFunc) {
+    SimpleTest._timeoutFunctions.push(aFunc);
+};
+
 SimpleTest.testInChaosMode = function() {
     if (SimpleTest._inChaosMode) {
       // It's already enabled for this test, don't enter twice
       return;
     }
     SpecialPowers.DOMWindowUtils.enterChaosMode();
     SimpleTest._inChaosMode = true;
 };
 
+SimpleTest.timeout = function() {
+    for (let func of SimpleTest._timeoutFunctions) {
+        func();
+    }
+    SimpleTest._timeoutFunctions = [];
+}
+
 /**
  * Finishes the tests. This is automatically called, except when
  * SimpleTest.waitForExplicitFinish() has been invoked.
 **/
 SimpleTest.finish = function() {
     if (SimpleTest._alreadyFinished) {
         var err = "[SimpleTest.finish()] this test already called finish!";
         if (parentRunner) {
@@ -1016,16 +1028,18 @@ SimpleTest.finish = function() {
         var test = {'result': false, 'name': 'fail-if condition in manifest', 'diag': msg};
         var successInfo = {status:"FAIL", expected:"FAIL", message:"TEST-KNOWN-FAIL"};
         var failureInfo = {status:"PASS", expected:"FAIL", message:"TEST-UNEXPECTED-PASS"};
 
         SimpleTest._logResult(test, successInfo, failureInfo);
         SimpleTest._tests.push(test);
     }
 
+    SimpleTest._timeoutFunctions = [];
+
     SimpleTest.testsLength = SimpleTest._tests.length;
 
     SimpleTest._alreadyFinished = true;
 
     if (SimpleTest._inChaosMode) {
         SpecialPowers.DOMWindowUtils.leaveChaosMode();
         SimpleTest._inChaosMode = false;
     }
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -114,16 +114,17 @@ TestRunner._checkForHangs = function() {
       win.SimpleTest.ok(false, msg);
     } else if ("W3CTest" in win) {
       win.W3CTest.logFailure(msg);
     }
   }
 
   function killTest(win) {
     if ("SimpleTest" in win) {
+      win.SimpleTest.timeout();
       win.SimpleTest.finish();
     } else if ("W3CTest" in win) {
       win.W3CTest.timeout();
     }
   }
 
   if (TestRunner._currentTest < TestRunner._urls.length) {
     var runtime = new Date().valueOf() - TestRunner._currentTestStartTime;