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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.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 benm's comment 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
Index: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
index 768f4c63931f53c337275ab01f634a48fb99009c..ddc655b8430b3fb0e609ad97f536731c685f2898 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
@@ -4,10 +4,15 @@
package org.chromium.content.browser;
+import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
+
import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.Assert;
+
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
+import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_shell_apk.ContentShellActivity;
import java.lang.annotation.Annotation;
@@ -16,6 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.ref.WeakReference;
+import java.util.concurrent.CountDownLatch;
/**
* Part of the test suite for the Java Bridge. Tests a number of features including ...
@@ -533,6 +539,47 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
+ public void testBlockingUiThreadDoesNotBlockCallsFromJs() throws Throwable {
+ class TestObject {
+ private CountDownLatch mLatch;
+ public TestObject() {
+ mLatch = new CountDownLatch(1);
+ }
+ public boolean waitOnTheLatch() throws Exception {
+ return mLatch.await(scaleTimeout(10000),
+ java.util.concurrent.TimeUnit.MILLISECONDS);
+ }
+ public void unlockTheLatch() throws Exception {
+ mTestController.setStringValue("unlocked");
+ mLatch.countDown();
+ }
+ }
+ final TestObject testObject = new TestObject();
+ injectObjectAndReload(testObject, "testObject");
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // loadUrl is asynchronous, the JS code will start running on the renderer
+ // thread. As soon as we exit loadUrl, the browser UI thread will be stuck waiting
+ // on the latch. If blocking the browser thread blocks Java Bridge, then the call
+ // to "unlockTheLatch()" will be executed after the waiting timeout, thus the
+ // string value will not yet be updated by the injected object.
+ mTestController.setStringValue("locked");
+ getWebContents().getNavigationController().loadUrl(new LoadUrlParams(
+ "javascript:(function() { testObject.unlockTheLatch() })()"));
+ try {
+ assertTrue(testObject.waitOnTheLatch());
+ } catch (Exception e) {
+ android.util.Log.e("JavaBridgeBasicsTest", "Wait exception", e);
+ Assert.fail("Wait exception");
+ }
+ assertEquals("unlocked", mTestController.getStringValue());
+ }
+ });
+ }
+
+ @SmallTest
+ @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testPublicInheritedMethod() throws Throwable {
class Base {
public void method(int x) {

Powered by Google App Engine
This is Rietveld 408576698