diff options
author | Ben Murdoch <benm@google.com> | 2014-08-29 15:12:05 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2014-08-29 18:16:21 +0100 |
commit | 014d5736f4bb5dc19e1fb5647eda69e936de499e (patch) | |
tree | 2b3babf605f9e48d98f4ef537ebfa566488786f7 /android_webview | |
parent | 70dcd3669b5c791151fe10ab9c41ee87fc8e3edd (diff) | |
download | chromium_org-014d5736f4bb5dc19e1fb5647eda69e936de499e.tar.gz |
Cherry pick "Cache pending JS bridge sync IPC replies, and send in case of RenderFrame deletion."
conflicts in:
content/common/android/gin_java_bridge_errors.cc
content/common/android/gin_java_bridge_errors.h
Bug: 16840290
Original description:
Cache pending JS bridge sync IPC replies, and send in case of
RenderFrame deletion.
When the WebView app makes a call to java over the JavaScriptBridge,
we leave the renderer hanging on a synchronous IPC. Once control
is passed into Java, it's possible that the WebView may get destroyed
(and thus the IPC channel back to the renderer closed) which means we
can't unblock the renderer waiting on the IPC response.
Instead we cache the IPC reply message and while waiting on Java to come
back to us, if we detect that the RenderFrame has been deleted, send a
reponse back before the IPC channel is closed.
BUG=408188
Committed:
https://chromium.googlesource.com/chromium/src/+/5d3e001f79c137b2ba0f5b0e9489abea616f3431
Change-Id: I7f1b28e297059eb69c5686316b47d926ea8a3d4f
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java | 74 |
1 files changed, 74 insertions, 0 deletions
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 0000000000..6a15244bb7 --- /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"}) + public void testDestroyFromJavaObject() throws Throwable { + final String HTML = "<html>Hello World</html>"; + final TestAwContentsClient client2 = new TestAwContentsClient(); + final AwTestContainerView view2 = createAwTestContainerViewOnMainSync(client2); + 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 functioning. + loadDataSync(view2.getAwContents(), client2.getOnPageFinishedHelper(), + HTML, "text/html", false); + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + } + + 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()); + } +} |