Bug 988553 - General Javascript test harness cleanup; r=nalexander

This commit is contained in:
Jim Chen 2014-03-31 14:03:35 -04:00
parent 06880d3a39
commit 8f0142e411
4 changed files with 22 additions and 17 deletions

View File

@ -5,15 +5,14 @@ import org.mozilla.gecko.tests.helpers.JavascriptMessageParser;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class JavascriptTest extends BaseTest {
public static final String LOGTAG = "JavascriptTest";
private static final String LOGTAG = "JavascriptTest";
private static final String EVENT_TYPE = "Robocop:JS";
public final String javascriptUrl;
private final String javascriptUrl;
public JavascriptTest(String javascriptUrl) {
super();
@ -31,37 +30,36 @@ public class JavascriptTest extends BaseTest {
// We want to be waiting for Robocop messages before the page is loaded
// because the test harness runs each test in the suite (and possibly
// completes testing) before the page load event is fired.
final Actions.EventExpecter expecter = mActions.expectGeckoEvent("Robocop:Status");
mAsserter.dumpLog("Registered listener for Robocop:Status");
final Actions.EventExpecter expecter =
mActions.expectGeckoEvent(EVENT_TYPE);
mAsserter.dumpLog("Registered listener for " + EVENT_TYPE);
final String url = getAbsoluteUrl("/robocop/robocop_javascript.html?path=" + javascriptUrl);
final String url = getAbsoluteUrl(StringHelper.ROBOCOP_JS_HARNESS_URL +
"?path=" + javascriptUrl);
mAsserter.dumpLog("Loading JavaScript test from " + url);
loadUrl(url);
final JavascriptMessageParser testMessageParser = new JavascriptMessageParser(mAsserter);
try {
while (!testMessageParser.isTestFinished()) {
if (Log.isLoggable(LOGTAG, Log.VERBOSE)) {
Log.v(LOGTAG, "Waiting for Robocop:Status");
Log.v(LOGTAG, "Waiting for " + EVENT_TYPE);
}
String data = expecter.blockForEventData();
if (Log.isLoggable(LOGTAG, Log.VERBOSE)) {
Log.v(LOGTAG, "Got Robocop:Status with data '" + data + "'");
Log.v(LOGTAG, "Got event with data '" + data + "'");
}
JSONObject o = new JSONObject(data);
String innerType = o.getString("innerType");
if (!"progress".equals(innerType)) {
throw new Exception("Unexpected Robocop:Status innerType " + innerType);
throw new Exception("Unexpected event innerType " + innerType);
}
String message = o.getString("message");
if (message == null) {
throw new Exception("Robocop:Status progress message must not be null");
throw new Exception("Progress message must not be null");
}
testMessageParser.logMessage(message);
}
@ -70,7 +68,7 @@ public class JavascriptTest extends BaseTest {
}
} finally {
expecter.unregisterListener();
mAsserter.dumpLog("Unregistered listener for Robocop:Status");
mAsserter.dumpLog("Unregistered listener for " + EVENT_TYPE);
}
}
}

View File

@ -77,6 +77,7 @@ public class StringHelper {
public static final String ROBOCOP_TEXT_PAGE_URL = "/robocop/robocop_text_page.html";
public static final String ROBOCOP_ADOBE_FLASH_URL = "/robocop/robocop_adobe_flash.html";
public static final String ROBOCOP_INPUT_URL = "/robocop/robocop_input.html";
public static final String ROBOCOP_JS_HARNESS_URL = "/robocop/robocop_javascript.html";
// Robocop page titles
public static final String ROBOCOP_BIG_LINK_TITLE = "Big Link";

View File

@ -17,6 +17,12 @@ import java.util.regex.Pattern;
*/
public final class JavascriptMessageParser {
/**
* The Javascript test harness sends test events to Java.
* Each such test event is wrapped in a Robocop:JS event.
*/
public static final String EVENT_TYPE = "Robocop:JS";
// Messages matching this pattern are handled specially. Messages not
// matching this pattern are still printed.
private static final Pattern testMessagePattern =

View File

@ -36,7 +36,7 @@ function _evalURI(uri, sandbox) {
* absolute.
*
* The Javascript test harness sends all output to Java via
* Robocop:Status messages.
* Robocop:JS messages.
*/
function testOneFile(uri) {
let HEAD_JS = "robocop_head.js";
@ -59,7 +59,7 @@ function testOneFile(uri) {
// Output from head.js is fed, line by line, to this function. We
// send any such output back to the Java Robocop harness.
testScope.dump = function (str) {
let message = { type: "Robocop:Status",
let message = { type: "Robocop:JS",
innerType: "progress",
message: str,
};