зеркало из https://github.com/mozilla/gecko-dev.git
Bug 996313 - Add boolean for ending test on assertion failure in JavascriptMessageParser. r=nalexander
This commit is contained in:
Родитель
313392a942
Коммит
de7cef208f
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
* <code>endOnAssertionFailure</code> 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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче