Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java |
index c865f4b043f1aed8287e65586ebacb4b3ace5c0e..07ae6c61e310421fdfad93989aea048bf03da09c 100644 |
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsGarbageCollectionTest.java |
@@ -4,13 +4,14 @@ |
package org.chromium.android_webview.test; |
+import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
+ |
import android.content.Context; |
import android.content.ContextWrapper; |
+import android.os.ResultReceiver; |
import android.test.suitebuilder.annotation.LargeTest; |
import android.test.suitebuilder.annotation.SmallTest; |
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
- |
import org.chromium.android_webview.AwContents; |
import org.chromium.base.annotations.SuppressFBWarnings; |
import org.chromium.base.test.util.Feature; |
@@ -60,7 +61,7 @@ public class AwContentsGarbageCollectionTest extends AwTestBase { |
} |
private static class GcTestDependencyFactory extends TestDependencyFactory { |
- private StrongRefTestContext mContext; |
+ private final StrongRefTestContext mContext; |
public GcTestDependencyFactory(StrongRefTestContext context) { |
mContext = context; |
@@ -106,6 +107,42 @@ public class AwContentsGarbageCollectionTest extends AwTestBase { |
@DisableHardwareAccelerationForTest |
@SmallTest |
@Feature({"AndroidWebView"}) |
+ public void testHoldKeyboardResultReceiver() throws Throwable { |
+ gcAndCheckAllAwContentsDestroyed(); |
+ |
+ TestAwContentsClient client = new TestAwContentsClient(); |
+ AwTestContainerView containerViews[] = new AwTestContainerView[MAX_IDLE_INSTANCES + 1]; |
+ ResultReceiver resultReceivers[] = new ResultReceiver[MAX_IDLE_INSTANCES + 1]; |
+ for (int i = 0; i < containerViews.length; i++) { |
+ final AwTestContainerView containerView = createAwTestContainerViewOnMainSync(client); |
+ containerViews[i] = containerView; |
+ loadUrlAsync(containerView.getAwContents(), "about:blank"); |
+ // When we call showSoftInput(), we pass a ResultReceiver object as a parameter. |
+ // Android framework will hold the object reference until the matching |
+ // ResultReceiver in InputMethodService (IME app) gets garbage-collected. |
+ // WebView object wouldn't get gc'ed once OSK shows up because of this. |
+ // It is difficult to show keyboard and wait until input method window shows up. |
+ // Instead, we simply emulate Android's behavior by keeping strong references. |
+ // See crbug.com/595613 for details. |
+ resultReceivers[i] = runTestOnUiThreadAndGetResult(new Callable<ResultReceiver>() { |
+ @Override |
+ public ResultReceiver call() throws Exception { |
+ return containerView.getContentViewCore().getNewShowKeyboardReceiver(); |
+ } |
+ }); |
+ } |
+ |
+ for (int i = 0; i < containerViews.length; i++) { |
+ containerViews[i] = null; |
+ } |
+ containerViews = null; |
+ removeAllViews(); |
+ gcAndCheckAllAwContentsDestroyed(); |
+ } |
+ |
+ @DisableHardwareAccelerationForTest |
+ @SmallTest |
+ @Feature({"AndroidWebView"}) |
public void testReferenceFromClient() throws Throwable { |
gcAndCheckAllAwContentsDestroyed(); |