summaryrefslogtreecommitdiffstats
path: root/tests/WebViewTests
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-11-09 15:31:49 +0000
committerSteve Block <steveblock@google.com>2011-11-09 16:22:13 +0000
commit8e33fe944f9e407e1ba0c40736747c707c40acc7 (patch)
treea3b34e4e898cee280d33821c9c824645fa57400f /tests/WebViewTests
parentba1f05d4a816dd60a6be2a09858d8c9ecf3d552d (diff)
downloadframeworks_base-8e33fe944f9e407e1ba0c40736747c707c40acc7.zip
frameworks_base-8e33fe944f9e407e1ba0c40736747c707c40acc7.tar.gz
frameworks_base-8e33fe944f9e407e1ba0c40736747c707c40acc7.tar.bz2
Add another test for WebView's Java Bridge
Tests that an exception is raised if the wrong number of arguments are passed to a method of an injected object. Bug: 5140673 Change-Id: Ic9f9d09969e0fccbe82584e1a9ca7580f6010c87
Diffstat (limited to 'tests/WebViewTests')
-rw-r--r--tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
index 143221d..54865e9 100644
--- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
+++ b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeBasicsTest.java
@@ -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() {