summaryrefslogtreecommitdiffstats
path: root/tests/WebViewTests/src/com/android/webviewtests
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-11-14 18:05:59 +0000
committerSteve Block <steveblock@google.com>2011-11-14 18:26:41 +0000
commit13ad467a91ac6d86a959b49f0168a0e6893aef2c (patch)
treebce3741a1b4872f4b115a3e702f552662a1f5f03 /tests/WebViewTests/src/com/android/webviewtests
parente3571f633a825738d785b587e91798a3d0876740 (diff)
downloadframeworks_base-13ad467a91ac6d86a959b49f0168a0e6893aef2c.zip
frameworks_base-13ad467a91ac6d86a959b49f0168a0e6893aef2c.tar.gz
frameworks_base-13ad467a91ac6d86a959b49f0168a0e6893aef2c.tar.bz2
Add tests for invalid and static methods in the WebView's Java Bridge
Change-Id: I18dacf4a4de8c787e46ea2781f5a365372a0a7da
Diffstat (limited to 'tests/WebViewTests/src/com/android/webviewtests')
-rw-r--r--tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java55
1 files changed, 41 insertions, 14 deletions
diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
index 54865e9..c9bbb77 100644
--- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
+++ b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
@@ -75,6 +75,12 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
}
}
+ private static class ObjectWithStaticMethod {
+ public static String staticMethod() {
+ return "foo";
+ }
+ }
+
TestController mTestController;
@Override
@@ -101,6 +107,17 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
mWebViewClient.waitForOnPageFinished();
}
+ // Note that this requires that we can pass a JavaScript boolean to Java.
+ private void assertRaisesException(String script) throws Throwable {
+ executeJavaScript("try {" +
+ script + ";" +
+ " testController.setBooleanValue(false);" +
+ "} catch (exception) {" +
+ " testController.setBooleanValue(true);" +
+ "}");
+ assertTrue(mTestController.waitForBooleanValue());
+ }
+
public void testTypeOfInjectedObject() throws Throwable {
assertEquals("object", executeJavaScriptAndGetStringResult("typeof testController"));
}
@@ -161,6 +178,28 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
executeJavaScriptAndGetStringResult("typeof testController.setStringValue"));
}
+ public void testTypeOfInvalidMethod() throws Throwable {
+ assertEquals("undefined", executeJavaScriptAndGetStringResult("typeof testController.foo"));
+ }
+
+ public void testCallingInvalidMethodRaisesException() throws Throwable {
+ assertRaisesException("testController.foo()");
+ }
+
+ // Note that this requires that we can pass a JavaScript string to Java.
+ public void testTypeOfStaticMethod() throws Throwable {
+ injectObjectAndReload(new ObjectWithStaticMethod(), "testObject");
+ executeJavaScript("testController.setStringValue(typeof testObject.staticMethod)");
+ assertEquals("function", mTestController.waitForStringValue());
+ }
+
+ // Note that this requires that we can pass a JavaScript string to Java.
+ public void testCallStaticMethod() throws Throwable {
+ injectObjectAndReload(new ObjectWithStaticMethod(), "testObject");
+ executeJavaScript("testController.setStringValue(testObject.staticMethod())");
+ assertEquals("foo", mTestController.waitForStringValue());
+ }
+
public void testPrivateMethodNotExposed() throws Throwable {
injectObjectAndReload(new Object() {
private void method() {}
@@ -214,20 +253,8 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
}
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)");
+ assertRaisesException("testController.setIntValue()");
+ assertRaisesException("testController.setIntValue(42, 42)");
}
public void testObjectPersistsAcrossPageLoads() throws Throwable {