Bug 602039 - Fix waitForAndContinue test function [r=mfinkle]
--- 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++) {