mobile/android/base/tests/testJavascriptBridge.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial