diff --git a/mobile/android/base/tests/JavascriptTest.java b/mobile/android/base/tests/JavascriptTest.java index d692a71ff43..77a98388414 100644 --- a/mobile/android/base/tests/JavascriptTest.java +++ b/mobile/android/base/tests/JavascriptTest.java @@ -37,7 +37,8 @@ public class JavascriptTest extends BaseTest { mAsserter.dumpLog("Loading JavaScript test from " + url); loadUrl(url); - final JavascriptMessageParser testMessageParser = new JavascriptMessageParser(mAsserter); + final JavascriptMessageParser testMessageParser = + new JavascriptMessageParser(mAsserter, false); try { while (!testMessageParser.isTestFinished()) { if (Log.isLoggable(LOGTAG, Log.VERBOSE)) { diff --git a/mobile/android/base/tests/helpers/JavascriptBridge.java b/mobile/android/base/tests/helpers/JavascriptBridge.java index 6a6d9302014..aa6299e1e4a 100644 --- a/mobile/android/base/tests/helpers/JavascriptBridge.java +++ b/mobile/android/base/tests/helpers/JavascriptBridge.java @@ -110,8 +110,10 @@ public final class JavascriptBridge { public JavascriptBridge(final Object target) { mTarget = target; mMethods = target.getClass().getMethods(); - mLogParser = new JavascriptMessageParser(sAsserter); mExpecter = sActions.expectGeckoEvent(EVENT_TYPE); + // The JS here is unrelated to a test harness, so we + // have our message parser end on assertion failure. + mLogParser = new JavascriptMessageParser(sAsserter, true); } /** diff --git a/mobile/android/base/tests/helpers/JavascriptMessageParser.java b/mobile/android/base/tests/helpers/JavascriptMessageParser.java index af48d4189d3..6237f1adcf1 100644 --- a/mobile/android/base/tests/helpers/JavascriptMessageParser.java +++ b/mobile/android/base/tests/helpers/JavascriptMessageParser.java @@ -34,9 +34,22 @@ public final class JavascriptMessageParser { private String lastTestName = ""; // Have we seen a message saying the test is finished? private boolean testFinishedMessageSeen = false; + private final boolean endOnAssertionFailure; - public JavascriptMessageParser(final Assert asserter) { + /** + * Constructs a message parser for test result messages sent from JavaScript. When seeing an + * assertion failure, the message parser can use the given {@link org.mozilla.gecko.Assert} + * instance to immediately end the test (typically if the underlying JS framework is not able + * to end the test itself) or to swallow the Errors - this functionality is determined by the + * endOnAssertionFailure parameter. + * + * @param asserter The Assert instance to which test results should be passed. + * @param endOnAssertionFailure + * true if the test should end if we see a JS assertion failure, false otherwise. + */ + public JavascriptMessageParser(final Assert asserter, final boolean endOnAssertionFailure) { this.asserter = asserter; + this.endOnAssertionFailure = endOnAssertionFailure; } public boolean isTestFinished() { @@ -61,8 +74,15 @@ public final class JavascriptMessageParser { try { asserter.ok(false, name, message); } catch (AssertionFailedError e) { - // Swallow this exception. We want to see all the - // Javascript failures, not die on the very first one! + // Above, we call the assert, allowing it to log. + // Now we can end the test, if applicable. + if (this.endOnAssertionFailure) { + throw e; + } + // Otherwise, swallow the Error. The JS framework we're + // logging messages from is likely capable of ending tests + // when it needs to, and we want to see all of its failures, + // not just the first one! } } else if ("KNOWN-FAIL".equals(type)) { asserter.todo(false, name, message);