Bug 602039 - Fix waitForAndContinue test function [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 05 Oct 2010 17:42:55 -0700
changeset 66781 066bc070f35627d80835fe79b96e04b822753fa3
parent 66780 4828efe83b23f7521ad9cb5b34e8700b930368e5
child 66782 8c9b676dfae113519caa450896833db1316e7765
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs602039
Bug 602039 - Fix waitForAndContinue test function [r=mfinkle]
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_test.js
mobile/chrome/tests/head.js
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -66,16 +66,17 @@ include $(topsrcdir)/config/rules.mk
   browser_preferences_text.js \
   browser_rect.js \
   browser_select.html \
   browser_select.js \
   browser_sessionstore.js \
   browser_tabs.js \
   browser_tapping.js \
   browser_tap_content.html \
+  browser_test.js \
   browser_viewport.js \
   browser_viewport.sjs \
   browser_no_title.html \
   browser_english_title.html \
   $(NULL)
 
 libs:: $(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_test.js
@@ -0,0 +1,20 @@
+// Tests for the test functions in head.js
+
+function test() {
+  waitForExplicitFinish();
+  testWaitForAndContinue();
+}
+
+function testWaitForAndContinue() {
+  waitForAndContinue(function() {
+    ok(true, "continues on success")
+    testWaitForAndContinue2();
+  }, function() true);
+}
+
+function testWaitForAndContinue2() {
+  waitForAndContinue(function() {
+    ok(true, "continues on failure");
+    finish();
+  }, function() false);
+}
--- a/mobile/chrome/tests/head.js
+++ b/mobile/chrome/tests/head.js
@@ -21,19 +21,21 @@ function waitFor(callback, test, timeout
 // callback will test for the outcome, but not stop the entire test.
 function waitForAndContinue(callback, test, timeout) {
   if (test()) {
     callback();
     return;
   }
 
   timeout = timeout || Date.now();
-  if (Date.now() - timeout > 1000)
+  if (Date.now() - timeout > 1000) {
     callback();
-  setTimeout(waitFor, 50, callback, test, timeout);
+    return;
+  }
+  setTimeout(waitForAndContinue, 50, callback, test, timeout);
 };
 
 function makeURI(spec) {
   return Services.io.newURI(spec, null, null);
 };
 
 EventUtils.synthesizeString = function synthesizeString(aString, aWindow) {
   for (let i = 0; i < aString.length; i++) {