Chromium Code Reviews| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java |
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab3eccf173bdcf7aa49d539ece8e6d0b50143a2d |
| --- /dev/null |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview.test; |
| + |
| +import android.test.suitebuilder.annotation.SmallTest; |
| + |
| +import org.chromium.android_webview.AwContents; |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.content.browser.JavascriptInterface; |
| + |
| +/** |
| + * Test suite for the WebView specific JavaBridge features. |
| + */ |
| +public class AwJavaBridgeTest extends AwTestBase { |
| + |
| + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); |
| + private AwTestContainerView mTestContainerView; |
| + |
| + @Override |
| + protected void setUp() throws Exception { |
| + super.setUp(); |
| + mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient); |
| + } |
| + |
| + @SmallTest |
| + @Feature({"AndroidWebView", "Android-JavaBridge"}) |
|
boliu
2014/08/27 17:55:56
I think features are supposed to match crbug label
benm (inactive)
2014/08/27 18:30:02
Oh, hm. I just used the ones we've added for all t
boliu
2014/08/27 18:34:54
Firmly in the nobody cares camp then. Consistency
|
| + public void testDestroyFromJavaObject() throws Throwable { |
| + final String HTML = "<html>Hello World</html>"; |
| + final TestAwContentsClient client2 = new TestAwContentsClient(); |
| + final AwTestContainerView view2 = createAwTestContainerViewOnMainSync(client2); |
|
boliu
2014/08/27 18:23:48
what's with 2s everywhere?
benm (inactive)
2014/08/27 18:30:02
Well, I want another one ;-)
boliu
2014/08/27 18:34:54
Ohh...the first one is from the base class. Ok, te
|
| + final AwContents awContents = mTestContainerView.getAwContents(); |
| + |
| + class Test { |
| + @JavascriptInterface |
| + public void destroy() { |
| + try { |
| + runTestOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + awContents.destroy(); |
| + } |
| + }); |
| + // Destroying one AwContents from within the JS callback should still |
| + // leave others dunctioning. |
| + loadDataSync(view2.getAwContents(), client2.getOnPageFinishedHelper(), |
| + HTML, "text/html", false); |
|
boliu
2014/08/27 18:23:48
I think you can load a new page with a different t
benm (inactive)
2014/08/27 18:30:02
I thought that was discouraged and that callback h
|
| + } catch (Throwable t) { |
| + throw new RuntimeException(t); |
|
boliu
2014/08/27 18:23:48
Wot?
benm (inactive)
2014/08/27 18:30:01
Gotta catch something, and in that case I want to
|
| + } |
| + } |
| + } |
| + |
| + enableJavaScriptOnUiThread(awContents); |
| + runTestOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + awContents.addPossiblyUnsafeJavascriptInterface(new Test(), "test", null); |
| + } |
| + }); |
| + |
| + loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), HTML, |
| + "text/html", false); |
| + |
| + // Ensure the JS interface object is there, and invoke the test method. |
| + assertEquals("\"function\"", executeJavaScriptAndWaitForResult( |
| + awContents, mContentsClient, "typeof test.destroy")); |
| + awContents.evaluateJavaScript("test.destroy()", null); |
| + |
| + client2.getOnPageFinishedHelper().waitForCallback( |
| + client2.getOnPageFinishedHelper().getCallCount()); |
| + } |
| +} |