Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import static org.mozilla.gecko.tests.helpers.AssertionHelper.*; |
michael@0 | 4 | |
michael@0 | 5 | import org.mozilla.gecko.tests.helpers.*; |
michael@0 | 6 | |
michael@0 | 7 | import org.json.JSONException; |
michael@0 | 8 | import org.json.JSONObject; |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * Tests the proper operation of JavascriptBridge and JavaBridge, |
michael@0 | 12 | * which are used by tests for communication between Java and JS. |
michael@0 | 13 | */ |
michael@0 | 14 | public class testJavascriptBridge extends UITest { |
michael@0 | 15 | |
michael@0 | 16 | private static final String TEST_JS = "testJavascriptBridge.js"; |
michael@0 | 17 | |
michael@0 | 18 | private JavascriptBridge js; |
michael@0 | 19 | private boolean syncCallReceived; |
michael@0 | 20 | |
michael@0 | 21 | @Override |
michael@0 | 22 | public void setUp() throws Exception { |
michael@0 | 23 | super.setUp(); |
michael@0 | 24 | js = new JavascriptBridge(this); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | @Override |
michael@0 | 28 | public void tearDown() throws Exception { |
michael@0 | 29 | js.disconnect(); |
michael@0 | 30 | super.tearDown(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | public void testJavascriptBridge() { |
michael@0 | 34 | GeckoHelper.blockForReady(); |
michael@0 | 35 | NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_JS_HARNESS_URL + |
michael@0 | 36 | "?path=" + TEST_JS); |
michael@0 | 37 | js.syncCall("check_js_int_arg", (int) 1); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | public void checkJavaIntArg(final int int2) { |
michael@0 | 41 | // Async call from JS |
michael@0 | 42 | fAssertEquals("Integer argument matches", 2, int2); |
michael@0 | 43 | js.syncCall("check_js_double_arg", (double) 3.0); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | public void checkJavaDoubleArg(final double double4) { |
michael@0 | 47 | // Async call from JS |
michael@0 | 48 | fAssertEquals("Double argument matches", 4.0, double4); |
michael@0 | 49 | js.syncCall("check_js_boolean_arg", (boolean) false); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | public void checkJavaBooleanArg(final boolean booltrue) { |
michael@0 | 53 | // Async call from JS |
michael@0 | 54 | fAssertEquals("Boolean argument matches", true, booltrue); |
michael@0 | 55 | js.syncCall("check_js_string_arg", (String) "foo"); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | public void checkJavaStringArg(final String stringbar) throws JSONException { |
michael@0 | 59 | // Async call from JS |
michael@0 | 60 | fAssertEquals("String argument matches", "bar", stringbar); |
michael@0 | 61 | final JSONObject obj = new JSONObject(); |
michael@0 | 62 | obj.put("caller", "java"); |
michael@0 | 63 | js.syncCall("check_js_object_arg", (JSONObject) obj); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | public void checkJavaObjectArg(final JSONObject obj) throws JSONException { |
michael@0 | 67 | // Async call from JS |
michael@0 | 68 | fAssertEquals("Object argument matches", "js", obj.getString("caller")); |
michael@0 | 69 | js.syncCall("check_js_sync_call"); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | public void doJSSyncCall() { |
michael@0 | 73 | // Sync call from JS |
michael@0 | 74 | syncCallReceived = true; |
michael@0 | 75 | js.asyncCall("respond_to_js_sync_call"); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | public void checkJSSyncCallReceived() { |
michael@0 | 79 | fAssertTrue("Received sync call before end of test", syncCallReceived); |
michael@0 | 80 | // End of test |
michael@0 | 81 | } |
michael@0 | 82 | } |