summaryrefslogtreecommitdiffstats
path: root/mobile/android/tests/browser/robocop/testJavascriptBridge.js
blob: 3bfd89f88966f02a1a85ef2818386dc32858b7a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var java = new JavaBridge(this);
var javaResponded = false;

do_register_cleanup(() => {
  java.disconnect();
});
do_test_pending();

function check_js_int_arg(int1) {
  // Sync call from Java
  do_check_eq(int1, 1);
  java.asyncCall("checkJavaIntArg", 2);
}

function check_js_double_arg(double3) {
  // Sync call from Java
  do_check_eq(double3, 3.0);
  java.asyncCall("checkJavaDoubleArg", 4.0);
}

function check_js_boolean_arg(boolfalse) {
  // Sync call from Java
  do_check_eq(boolfalse, false);
  java.asyncCall("checkJavaBooleanArg", true);
}

function check_js_string_arg(stringfoo) {
  do_check_eq(stringfoo, "foo");
  java.asyncCall("checkJavaStringArg", "bar");
}

function check_js_object_arg(obj) {
  // Sync call from Java
  do_check_eq(obj.caller, "java");
  java.asyncCall("checkJavaObjectArg", {caller: "js"});
}

function check_js_sync_call() {
  // Sync call from Java
  java.syncCall("doJSSyncCall");
  // respond_to_js_sync_call should have run by now because
  // do_js_sync_call calls it from Java code
  do_check_true(javaResponded);

  java.asyncCall("checkJSSyncCallReceived");
  // End of test
  do_test_finished();
}

function respond_to_js_sync_call() {
  javaResponded = true;
}