diff options
author | Steve Block <steveblock@google.com> | 2012-04-24 13:01:57 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2012-04-26 13:59:51 +0100 |
commit | e9e260fbc0892885790eeccb4d803f7d81f261aa (patch) | |
tree | b1cf840b4956cdfd07e1fa0db6ed64fd7d053ca2 /tests | |
parent | 8a1da405235ca2a34eb01d57363a842a27ae9580 (diff) | |
download | frameworks_base-e9e260fbc0892885790eeccb4d803f7d81f261aa.zip frameworks_base-e9e260fbc0892885790eeccb4d803f7d81f261aa.tar.gz frameworks_base-e9e260fbc0892885790eeccb4d803f7d81f261aa.tar.bz2 |
Add tests for uncaught exceptions from methods called through the Java Bridge
This is a cherry-pick from master. See
https://android-git.corp.google.com/g/184260
If a method called on a Java object through the Java Bridge throws an uncaught
exception, we throw a JavaScript exception.
See WebKit change https://android-git.corp.google.com/g/184252
Bug: 6386557
Change-Id: Ie2a97a26372fb11782b35db09bc2046fb7eb1f86
Diffstat (limited to 'tests')
-rw-r--r-- | tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java index 07d7c34..1ecccf6 100644 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java +++ b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java @@ -186,6 +186,13 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { assertRaisesException("testController.foo()"); } + public void testUncaughtJavaExceptionRaisesJavaException() throws Throwable { + injectObjectAndReload(new Object() { + public void method() { throw new RuntimeException("foo"); } + }, "testObject"); + assertRaisesException("testObject.method()"); + } + // Note that this requires that we can pass a JavaScript string to Java. public void testTypeOfStaticMethod() throws Throwable { injectObjectAndReload(new ObjectWithStaticMethod(), "testObject"); @@ -394,7 +401,6 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { assertEquals("", mTestController.waitForStringValue()); } - // java.lang.reflect only allows access to public methods and fields. See b/6386557. public void testReflectPublicMethod() throws Throwable { injectObjectAndReload(new Object() { public String method() { return "foo"; } @@ -404,7 +410,6 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { ".toString()")); } - // java.lang.reflect only allows access to public methods and fields. See b/6386557. public void testReflectPublicField() throws Throwable { injectObjectAndReload(new Object() { public String field = "foo"; @@ -412,4 +417,26 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { assertEquals("foo", executeJavaScriptAndGetStringResult( "testObject.getClass().getField('field').get(testObject).toString()")); } + + public void testReflectPrivateMethodRaisesException() throws Throwable { + injectObjectAndReload(new Object() { + private void method() {}; + }, "testObject"); + assertRaisesException("testObject.getClass().getMethod('method', null)"); + // getDeclaredMethod() is able to access a private method, but invoke() + // throws a Java exception. + assertRaisesException( + "testObject.getClass().getDeclaredMethod('method', null).invoke(testObject, null)"); + } + + public void testReflectPrivateFieldRaisesException() throws Throwable { + injectObjectAndReload(new Object() { + private int field; + }, "testObject"); + assertRaisesException("testObject.getClass().getField('field')"); + // getDeclaredField() is able to access a private field, but getInt() + // throws a Java exception. + assertRaisesException( + "testObject.getClass().getDeclaredField('field').getInt(testObject)"); + } } |