Bug 494397 - SimpleTest.js |window.onerror| calls |SimpleTest.finish()| while test is still running; (Av1) Tabs cleanup, Improve+Add error messages, Use executeSoon(); r=rcampbell
authorSerge Gautherie <sgautherie.bz@free.fr>
Fri, 19 Jun 2009 20:10:20 +0200
changeset 29395 26bfd1ee3185280800f50900875745b3963aed6a
parent 29394 6641b775a1ef19bacd1b25e6dca862f2394aa53a
child 29396 d4fa463061387320fcd9105b9914dd7758e6ba98
push id7598
push usersgautherie.bz@free.fr
push dateFri, 19 Jun 2009 18:20:10 +0000
treeherdermozilla-central@d4fa46306138 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs494397
milestone1.9.2a1pre
Bug 494397 - SimpleTest.js |window.onerror| calls |SimpleTest.finish()| while test is still running; (Av1) Tabs cleanup, Improve+Add error messages, Use executeSoon(); r=rcampbell
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -13,17 +13,17 @@
 if (typeof(SimpleTest) == "undefined") {
     var SimpleTest = {};
 }
 
 var parentRunner = null;
 if (typeof(parent) != "undefined" && parent.TestRunner) {
     parentRunner = parent.TestRunner;
 } else if (parent && parent.wrappedJSObject &&
-	   parent.wrappedJSObject.TestRunner) {
+           parent.wrappedJSObject.TestRunner) {
     parentRunner = parent.wrappedJSObject.TestRunner;
 }
 
 // Check to see if the TestRunner is present and has logging
 if (parentRunner) {
     SimpleTest._logEnabled = parentRunner.logEnabled;
 }
 
@@ -175,19 +175,19 @@ SimpleTest.showReport = function() {
     var togglePassed = A({'href': '#'}, "Toggle passed checks");
     var toggleFailed = A({'href': '#'}, "Toggle failed checks");
     var toggleTodo = A({'href': '#'}, "Toggle todo checks");
     togglePassed.onclick = partial(SimpleTest.toggleByClass, 'test_ok');
     toggleFailed.onclick = partial(SimpleTest.toggleByClass, 'test_not_ok');
     toggleTodo.onclick = partial(SimpleTest.toggleByClass, 'test_todo');
     var body = document.body;  // Handles HTML documents
     if (!body) {
-	// Do the XML thing
-	body = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
-					       "body")[0]
+        // Do the XML thing.
+        body = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
+                                               "body")[0];
     }
     var firstChild = body.childNodes[0];
     var addNode;
     if (firstChild) {
         addNode = function (el) {
             body.insertBefore(el, firstChild);
         };
     } else {
@@ -402,17 +402,17 @@ SimpleTest._formatStack = function (stac
     ];
 
     var out = "Structures begin differing at:" + SimpleTest.LF;
     for (var i = 0; i < vals.length; i++) {
         var val = vals[i];
         if (val == null) {
             val = 'undefined';
         } else {
-             val == SimpleTest.DNE ? "Does not exist" : "'" + val + "'";
+            val == SimpleTest.DNE ? "Does not exist" : "'" + val + "'";
         }
     }
 
     out += vars[0] + ' = ' + vals[0] + SimpleTest.LF;
     out += vars[1] + ' = ' + vals[1] + SimpleTest.LF;
 
     return '    ' + out;
 };
@@ -459,22 +459,29 @@ SimpleTest.isa = function (object, clas)
 // Global symbols:
 var ok = SimpleTest.ok;
 var is = SimpleTest.is;
 var isnot = SimpleTest.isnot;
 var todo = SimpleTest.todo;
 var todo_is = SimpleTest.todo_is;
 var todo_isnot = SimpleTest.todo_isnot;
 var isDeeply = SimpleTest.isDeeply;
-var oldOnError = window.onerror;
+
+const oldOnError = window.onerror;
 window.onerror = function (ev) {
-    is(0, 1, "Error thrown during test: " + ev);
-    if (oldOnError) {
-	try {
-	  oldOnError(ev);
-	} catch (e) {
-	}
+  // Log the error.
+  ok(false, "[SimpleTest/SimpleTest.js, window.onerror] An error occurred: [ " + ev + " ]");
+
+  // Call previous handler.
+  if (oldOnError) {
+    try {
+      oldOnError(ev);
+    } catch (e) {
+      // Log the exception.
+      ok(false, "[SimpleTest/SimpleTest.js, window.onerror] Exception thrown by oldOnError(): [ " + e + " ]");
     }
-    if (SimpleTest._stopOnLoad == false) {
-      // Need to finish() manually here
-      SimpleTest.finish();
-    }
+  }
+
+  if (!SimpleTest._stopOnLoad) {
+    // Need to finish() manually here, yet let the test actually end first.
+    SimpleTest.executeSoon(SimpleTest.finish);
+  }
 }