Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java

Issue 772123002: [Android] Java Bridge: handle requests from Java Script on the background thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more Sami's comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 253a361aa39997c0b3fca27c190ee3a06d2ae953..e39252f911f04aa9d3e03dc0f8c268804ae06ad0 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwJavaBridgeTest.java
@@ -43,9 +43,9 @@ public class AwJavaBridgeTest extends AwTestBase {
}
});
// Destroying one AwContents from within the JS callback should still
- // leave others functioning.
- loadDataSync(view2.getAwContents(), client2.getOnPageFinishedHelper(),
- html, "text/html", false);
+ // leave others functioning. Note that we must do this asynchronously,
+ // as Blink thread is currently blocked waiting for this method to finish.
+ loadDataAsync(view2.getAwContents(), html, "text/html", false);
} catch (Throwable t) {
throw new RuntimeException(t);
}
@@ -66,9 +66,99 @@ public class AwJavaBridgeTest extends AwTestBase {
// Ensure the JS interface object is there, and invoke the test method.
assertEquals("\"function\"", executeJavaScriptAndWaitForResult(
awContents, mContentsClient, "typeof test.destroy"));
+ int currentCallCount = client2.getOnPageFinishedHelper().getCallCount();
awContents.evaluateJavaScript("test.destroy()", null);
- client2.getOnPageFinishedHelper().waitForCallback(
- client2.getOnPageFinishedHelper().getCallCount());
+ client2.getOnPageFinishedHelper().waitForCallback(currentCallCount);
+ }
+
+ @SmallTest
+ @Feature({"AndroidWebView", "Android-JavaBridge"})
+ public void testTwoWebViewsCreatedSimultaneously() throws Throwable {
+ final AwContents awContents1 = mTestContainerView.getAwContents();
+ final TestAwContentsClient client2 = new TestAwContentsClient();
+ final AwTestContainerView view2 = createAwTestContainerViewOnMainSync(client2);
+ final AwContents awContents2 = view2.getAwContents();
+
+ enableJavaScriptOnUiThread(awContents1);
+ enableJavaScriptOnUiThread(awContents2);
+
+ class Test {
+ Test(int value) {
+ mValue = value;
+ }
+ @JavascriptInterface
+ public int getValue() {
+ return mValue;
+ }
+ private int mValue;
+ }
+
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ awContents1.addPossiblyUnsafeJavascriptInterface(new Test(1), "test", null);
+ awContents2.addPossiblyUnsafeJavascriptInterface(new Test(2), "test", null);
+ }
+ });
+ final String html = "<html>Hello World</html>";
+ loadDataSync(awContents1, mContentsClient.getOnPageFinishedHelper(), html,
+ "text/html", false);
+ loadDataSync(awContents2, client2.getOnPageFinishedHelper(), html,
+ "text/html", false);
+
+ assertEquals("1",
+ executeJavaScriptAndWaitForResult(awContents1, mContentsClient, "test.getValue()"));
+ assertEquals("2",
+ executeJavaScriptAndWaitForResult(awContents2, client2, "test.getValue()"));
+ }
+
+ @SmallTest
+ @Feature({"AndroidWebView", "Android-JavaBridge"})
+ public void testTwoWebViewsSecondCreatedAfterLoadingInFirst() throws Throwable {
+ final AwContents awContents1 = mTestContainerView.getAwContents();
+ enableJavaScriptOnUiThread(awContents1);
+
+ class Test {
+ Test(int value) {
+ mValue = value;
+ }
+ @JavascriptInterface
+ public int getValue() {
+ return mValue;
+ }
+ private int mValue;
+ }
+
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ awContents1.addPossiblyUnsafeJavascriptInterface(new Test(1), "test", null);
+ }
+ });
+ final String html = "<html>Hello World</html>";
+ loadDataSync(awContents1, mContentsClient.getOnPageFinishedHelper(), html,
+ "text/html", false);
+ assertEquals("1",
+ executeJavaScriptAndWaitForResult(awContents1, mContentsClient, "test.getValue()"));
+
+ final TestAwContentsClient client2 = new TestAwContentsClient();
+ final AwTestContainerView view2 = createAwTestContainerViewOnMainSync(client2);
+ final AwContents awContents2 = view2.getAwContents();
+ enableJavaScriptOnUiThread(awContents2);
+
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ awContents2.addPossiblyUnsafeJavascriptInterface(new Test(2), "test", null);
+ }
+ });
+ loadDataSync(awContents2, client2.getOnPageFinishedHelper(), html,
+ "text/html", false);
+
+ assertEquals("1",
+ executeJavaScriptAndWaitForResult(awContents1, mContentsClient, "test.getValue()"));
+ assertEquals("2",
+ executeJavaScriptAndWaitForResult(awContents2, client2, "test.getValue()"));
}
}
« no previous file with comments | « no previous file | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698