Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import org.mozilla.gecko.tests.helpers.JavascriptBridge; |
michael@0 | 4 | import org.mozilla.gecko.tests.helpers.JavascriptMessageParser; |
michael@0 | 5 | |
michael@0 | 6 | import android.util.Log; |
michael@0 | 7 | import java.util.regex.Matcher; |
michael@0 | 8 | import java.util.regex.Pattern; |
michael@0 | 9 | |
michael@0 | 10 | import org.json.JSONObject; |
michael@0 | 11 | import org.mozilla.gecko.Actions; |
michael@0 | 12 | import org.mozilla.gecko.Assert; |
michael@0 | 13 | |
michael@0 | 14 | public class JavascriptTest extends BaseTest { |
michael@0 | 15 | private static final String LOGTAG = "JavascriptTest"; |
michael@0 | 16 | private static final String EVENT_TYPE = JavascriptBridge.EVENT_TYPE; |
michael@0 | 17 | |
michael@0 | 18 | private final String javascriptUrl; |
michael@0 | 19 | |
michael@0 | 20 | public JavascriptTest(String javascriptUrl) { |
michael@0 | 21 | super(); |
michael@0 | 22 | this.javascriptUrl = javascriptUrl; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | public void testJavascript() throws Exception { |
michael@0 | 26 | blockForGeckoReady(); |
michael@0 | 27 | |
michael@0 | 28 | // We want to be waiting for Robocop messages before the page is loaded |
michael@0 | 29 | // because the test harness runs each test in the suite (and possibly |
michael@0 | 30 | // completes testing) before the page load event is fired. |
michael@0 | 31 | final Actions.EventExpecter expecter = |
michael@0 | 32 | mActions.expectGeckoEvent(EVENT_TYPE); |
michael@0 | 33 | mAsserter.dumpLog("Registered listener for " + EVENT_TYPE); |
michael@0 | 34 | |
michael@0 | 35 | final String url = getAbsoluteUrl(StringHelper.ROBOCOP_JS_HARNESS_URL + |
michael@0 | 36 | "?path=" + javascriptUrl); |
michael@0 | 37 | mAsserter.dumpLog("Loading JavaScript test from " + url); |
michael@0 | 38 | loadUrl(url); |
michael@0 | 39 | |
michael@0 | 40 | final JavascriptMessageParser testMessageParser = |
michael@0 | 41 | new JavascriptMessageParser(mAsserter, false); |
michael@0 | 42 | try { |
michael@0 | 43 | while (!testMessageParser.isTestFinished()) { |
michael@0 | 44 | if (Log.isLoggable(LOGTAG, Log.VERBOSE)) { |
michael@0 | 45 | Log.v(LOGTAG, "Waiting for " + EVENT_TYPE); |
michael@0 | 46 | } |
michael@0 | 47 | String data = expecter.blockForEventData(); |
michael@0 | 48 | if (Log.isLoggable(LOGTAG, Log.VERBOSE)) { |
michael@0 | 49 | Log.v(LOGTAG, "Got event with data '" + data + "'"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | JSONObject o = new JSONObject(data); |
michael@0 | 53 | String innerType = o.getString("innerType"); |
michael@0 | 54 | if (!"progress".equals(innerType)) { |
michael@0 | 55 | throw new Exception("Unexpected event innerType " + innerType); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | String message = o.getString("message"); |
michael@0 | 59 | if (message == null) { |
michael@0 | 60 | throw new Exception("Progress message must not be null"); |
michael@0 | 61 | } |
michael@0 | 62 | testMessageParser.logMessage(message); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | if (Log.isLoggable(LOGTAG, Log.DEBUG)) { |
michael@0 | 66 | Log.d(LOGTAG, "Got test finished message"); |
michael@0 | 67 | } |
michael@0 | 68 | } finally { |
michael@0 | 69 | expecter.unregisterListener(); |
michael@0 | 70 | mAsserter.dumpLog("Unregistered listener for " + EVENT_TYPE); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | } |