Index: android_webview/javatests/src/org/chromium/android_webview/test/VisualStateTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/VisualStateTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/VisualStateTest.java |
index 00d6849cda5b88d0267fd09663c80eac9f05bef8..8b1efaa243a0c00a234610c96c4ca487804fd816 100644 |
--- a/android_webview/javatests/src/org/chromium/android_webview/test/VisualStateTest.java |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/VisualStateTest.java |
@@ -6,6 +6,8 @@ package org.chromium.android_webview.test; |
import android.graphics.Bitmap; |
import android.graphics.Color; |
+import android.graphics.Rect; |
+import android.os.Build; |
import android.test.suitebuilder.annotation.SmallTest; |
import android.view.View; |
import android.webkit.WebChromeClient; |
@@ -16,6 +18,7 @@ import org.chromium.android_webview.test.util.CommonResources; |
import org.chromium.android_webview.test.util.GraphicsTestUtils; |
import org.chromium.android_webview.test.util.JavascriptEventObserver; |
import org.chromium.base.test.util.Feature; |
+import org.chromium.base.test.util.MinAndroidSdkLevel; |
import org.chromium.content.browser.ContentViewCore; |
import org.chromium.content.browser.test.util.CallbackHelper; |
import org.chromium.content.browser.test.util.DOMUtils; |
@@ -28,6 +31,7 @@ import java.util.concurrent.atomic.AtomicReference; |
/** |
* Visual state related tests. |
*/ |
+@MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) |
public class VisualStateTest extends AwTestBase { |
private static final String WAIT_FOR_JS_TEST_URL = |
@@ -321,6 +325,83 @@ public class VisualStateTest extends AwTestBase { |
assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
} |
+ @Feature({"AndroidWebView"}) |
+ @SmallTest |
+ public void testVisualStateCallbackWhenContainerViewDetached() |
+ throws Throwable { |
+ final CountDownLatch readyToEnterFullscreenSignal = new CountDownLatch(1); |
+ final CountDownLatch hasCustomViewSignal = new CountDownLatch(1); |
+ final CountDownLatch testFinishedSignal = new CountDownLatch(1); |
+ |
+ final AtomicReference<AwContents> awContentsRef = new AtomicReference<>(); |
hush (inactive)
2015/03/04 18:39:08
Why not "AtomicReference<AwContents>" on the right
boliu
2015/03/04 19:16:43
http://docs.oracle.com/javase/7/docs/technotes/gui
hush (inactive)
2015/03/04 19:39:54
Okay.
|
+ final AtomicReference<View> customViewRef = new AtomicReference<>(); |
+ |
+ final TestAwContentsClient awContentsClient = new TestAwContentsClient() { |
+ @Override |
+ public void onPageFinished(String url) { |
+ super.onPageFinished(url); |
+ readyToEnterFullscreenSignal.countDown(); |
+ } |
+ |
+ @Override |
+ public void onShowCustomView( |
+ final View customView, WebChromeClient.CustomViewCallback callback) { |
+ // Please note that we don't attach the custom view to the window here |
+ // (awContentsClient is an instance of TestAwContentsClient, not |
+ // FullScreenVideoTestAwContentsClient). |
+ customView.setClipBounds(new Rect(0, 0, 100, 100)); |
+ customView.measure(100, 100); |
+ customView.layout(0, 0, 100, 100); |
+ customViewRef.set(customView); |
+ hasCustomViewSignal.countDown(); |
+ } |
+ }; |
+ final AwTestContainerView testView = createAwTestContainerViewOnMainSync(awContentsClient); |
+ final AwContents awContents = testView.getAwContents(); |
+ awContentsRef.set(awContents); |
+ final ContentViewCore contentViewCore = testView.getContentViewCore(); |
+ enableJavaScriptOnUiThread(awContents); |
+ awContents.getSettings().setFullscreenSupported(true); |
+ |
+ // JS will notify this observer once it has entered fullscreen. |
+ final JavascriptEventObserver jsObserver = new JavascriptEventObserver(); |
+ runTestOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ jsObserver.register(contentViewCore, "jsObserver"); |
+ } |
+ }); |
+ |
+ loadUrlSync(awContents, awContentsClient.getOnPageFinishedHelper(), FULLSCREEN_TEST_URL); |
+ |
+ assertTrue(readyToEnterFullscreenSignal.await( |
+ AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
+ DOMUtils.clickNode(VisualStateTest.this, contentViewCore, ENTER_FULLSCREEN_CONTROL_ID); |
+ |
+ assertTrue(hasCustomViewSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
+ assertTrue(jsObserver.waitForEvent(WAIT_TIMEOUT_MS)); |
+ |
+ runTestOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ awContents.insertVisualStateCallback(20, new VisualStateCallback() { |
+ @Override |
+ public void onComplete(long id) { |
+ assertFalse(customViewRef.get().isAttachedToWindow()); |
+ // NOTE: We cannot use drawAwContents here because the web contents |
+ // are rendered into the custom view while in fullscreen. |
+ Bitmap redScreenshot = GraphicsTestUtils.drawView( |
+ customViewRef.get(), 100, 100); |
+ assertEquals(Color.RED, redScreenshot.getPixel(50, 50)); |
+ testFinishedSignal.countDown(); |
+ } |
+ }); |
+ } |
+ }); |
+ |
+ assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
+ } |
+ |
private static final LoadUrlParams createTestPageUrl(String backgroundColor) { |
return LoadUrlParams.createLoadDataParams( |
"<html><body bgcolor=" + backgroundColor + "></body></html>", "text/html", false); |