Chromium Code Reviews| 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 2ae84a6b203469799177395a7870e94bfd8ab7ef..d5fdbedf4602622b69b470e0e08d9096e8a349b3 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 |
| @@ -9,13 +9,12 @@ import android.graphics.Color; |
| import android.graphics.Rect; |
| import android.test.suitebuilder.annotation.SmallTest; |
| import android.util.Base64; |
| -import android.view.View; |
| -import android.webkit.WebChromeClient; |
| import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| import org.chromium.android_webview.AwContents; |
| import org.chromium.android_webview.AwContents.VisualStateCallback; |
| +import org.chromium.android_webview.AwContentsClient; |
| import org.chromium.android_webview.AwWebResourceResponse; |
| import org.chromium.android_webview.test.util.CommonResources; |
| import org.chromium.android_webview.test.util.GraphicsTestUtils; |
| @@ -42,6 +41,8 @@ import java.util.concurrent.atomic.AtomicReference; |
| public class VisualStateTest extends AwTestBase { |
| private static final String WAIT_FOR_JS_TEST_URL = |
| "file:///android_asset/visual_state_waits_for_js_test.html"; |
| + private static final String WAIT_FOR_JS_DETACHED_TEST_URL = |
| + "file:///android_asset/visual_state_waits_for_js_detached_test.html"; |
| private static final String ON_PAGE_COMMIT_VISIBLE_TEST_URL = |
| "file:///android_asset/visual_state_on_page_commit_visible_test.html"; |
| private static final String FULLSCREEN_TEST_URL = |
| @@ -403,77 +404,64 @@ public class VisualStateTest extends AwTestBase { |
| assertTrue(testFinishedSignal.await(AwTestBase.WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); |
| } |
| + private AwTestContainerView createDetachedTestContainerViewOnMainSync( |
| + final AwContentsClient awContentsClient) { |
| + final AtomicReference<AwTestContainerView> testContainerView = |
|
boliu
2015/11/05 17:48:03
new way to do thi is ThreadUtils.runOnUiThreadBloc
Tobias Sargeant
2015/11/05 22:30:16
Done.
|
| + new AtomicReference<AwTestContainerView>(); |
| + getInstrumentation().runOnMainSync(new Runnable() { |
| + @Override |
| + public void run() { |
| + AwTestContainerView detachedView = createDetachedAwTestContainerView( |
| + awContentsClient); |
| + detachedView.setClipBounds(new Rect(0, 0, 100, 100)); |
| + detachedView.measure(100, 100); |
| + detachedView.layout(0, 0, 100, 100); |
| + testContainerView.set(detachedView); |
| + } |
| + }); |
| + return testContainerView.get(); |
| + } |
| + |
| @Feature({"AndroidWebView"}) |
| @SmallTest |
| - public void testVisualStateCallbackWhenContainerViewDetached() |
| - throws Throwable { |
| - final CountDownLatch readyToEnterFullscreenSignal = new CountDownLatch(1); |
| - final CountDownLatch hasCustomViewSignal = new CountDownLatch(1); |
| + public void testVisualStateCallbackWhenContainerViewDetached() throws Throwable { |
| final CountDownLatch testFinishedSignal = new CountDownLatch(1); |
| - final AtomicReference<AwContents> awContentsRef = new AtomicReference<>(); |
| - 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 TestAwContentsClient awContentsClient = new TestAwContentsClient(); |
| + final AwTestContainerView testView = |
| + createDetachedTestContainerViewOnMainSync(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"); |
| + // JS will notify this observer once it has changed the background color of the page. |
| + final Object jsObserver = new Object() { |
| + public void notifyJava() { |
| + ThreadUtils.postOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + awContents.insertVisualStateCallback(20, |
| + new VisualStateCallback() { |
| + @Override |
| + public void onComplete(long id) { |
| + Bitmap redScreenshot = GraphicsTestUtils.drawAwContents( |
| + awContents, 100, 100); |
| + assertEquals(Color.RED, redScreenshot.getPixel(50, 50)); |
| + testFinishedSignal.countDown(); |
| + } |
| + }); |
| + } |
| + }); |
| } |
| - }); |
| - |
| - 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(); |
| - } |
| - }); |
| + contentViewCore.addPossiblyUnsafeJavascriptInterface( |
| + jsObserver, "jsObserver", null); |
|
boliu
2015/11/05 17:48:03
call this somethign else to avoid confusing with t
Tobias Sargeant
2015/11/05 22:30:16
Done.
|
| + awContents.loadUrl(WAIT_FOR_JS_DETACHED_TEST_URL); |
| } |
| }); |