diff options
author | Steve Block <steveblock@google.com> | 2011-11-09 15:31:49 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-11-09 16:22:13 +0000 |
commit | 8e33fe944f9e407e1ba0c40736747c707c40acc7 (patch) | |
tree | a3b34e4e898cee280d33821c9c824645fa57400f /tests/WebViewTests | |
parent | ba1f05d4a816dd60a6be2a09858d8c9ecf3d552d (diff) | |
download | frameworks_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.java | 26 |
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() { |