Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f914432 authored by Steve Block's avatar Steve Block Committed by Android (Google) Code Review
Browse files

Merge "Add another test for WebView's Java Bridge"

parents 81b10fd7 8e33fe94
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
        private int mIntValue;
        private long mLongValue;
        private String mStringValue;
        private boolean mBooleanValue;

        public synchronized void setIntValue(int x) {
            mIntValue = x;
@@ -51,6 +52,10 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
            mStringValue = x;
            notifyResultIsReady();
        }
        public synchronized void setBooleanValue(boolean x) {
            mBooleanValue = x;
            notifyResultIsReady();
        }

        public synchronized int waitForIntValue() {
            waitForResult();
@@ -64,6 +69,10 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
            waitForResult();
            return mStringValue;
        }
        public synchronized boolean waitForBooleanValue() {
            waitForResult();
            return mBooleanValue;
        }
    }

    TestController mTestController;
@@ -204,6 +213,23 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
        assertEquals("2 args", mTestController.waitForStringValue());
    }

    public void testCallMethodWithWrongNumberOfArgumentsRaisesException() throws Throwable {
        class Test {
            public void run(String script) throws Throwable {
                executeJavaScript("try {" +
                                  script + ";" +
                                  "  testController.setBooleanValue(false);" +
                                  "} catch (exception) {" +
                                  "  testController.setBooleanValue(true);" +
                                  "}");
                assertTrue(mTestController.waitForBooleanValue());
            }
        }
        Test test = new Test();
        test.run("testController.setIntValue()");
        test.run("testController.setIntValue(42, 42)");
    }

    public void testObjectPersistsAcrossPageLoads() throws Throwable {
        assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController"));
        runTestOnUiThread(new Runnable() {