1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.test.suitebuilder.annotation.SmallTest;
9 import org.chromium.android_webview.AwContents;
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.content.browser.JavascriptInterface;
14 * Test suite for the WebView specific JavaBridge features.
16 public class AwJavaBridgeTest extends AwTestBase {
18 private TestAwContentsClient mContentsClient = new TestAwContentsClient();
19 private AwTestContainerView mTestContainerView;
22 protected void setUp() throws Exception {
24 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient);
28 @Feature({"AndroidWebView", "Android-JavaBridge"})
29 public void testDestroyFromJavaObject() throws Throwable {
30 final String html = "<html>Hello World</html>";
31 final TestAwContentsClient client2 = new TestAwContentsClient();
32 final AwTestContainerView view2 = createAwTestContainerViewOnMainSync(client2);
33 final AwContents awContents = mTestContainerView.getAwContents();
37 public void destroy() {
39 runTestOnUiThread(new Runnable() {
45 // Destroying one AwContents from within the JS callback should still
46 // leave others functioning.
47 loadDataSync(view2.getAwContents(), client2.getOnPageFinishedHelper(),
48 html, "text/html", false);
49 } catch (Throwable t) {
50 throw new RuntimeException(t);
55 enableJavaScriptOnUiThread(awContents);
56 runTestOnUiThread(new Runnable() {
59 awContents.addPossiblyUnsafeJavascriptInterface(new Test(), "test", null);
63 loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), html,
66 // Ensure the JS interface object is there, and invoke the test method.
67 assertEquals("\"function\"", executeJavaScriptAndWaitForResult(
68 awContents, mContentsClient, "typeof test.destroy"));
69 awContents.evaluateJavaScript("test.destroy()", null);
71 client2.getOnPageFinishedHelper().waitForCallback(
72 client2.getOnPageFinishedHelper().getCallCount());