diff options
author | igsolla <igsolla@chromium.org> | 2014-11-05 09:02:08 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-05 17:02:26 +0000 |
commit | 06d14e5623a8e879f7e6d56c84650c0f524e2c5b (patch) | |
tree | 4711885dfa736a55278de9949cddf799eff1fc25 /android_webview/javatests/src | |
parent | cdec29fe5047465f3b5288ed158b703dfac7fbc1 (diff) | |
download | chromium_src-06d14e5623a8e879f7e6d56c84650c0f524e2c5b.zip chromium_src-06d14e5623a8e879f7e6d56c84650c0f524e2c5b.tar.gz chromium_src-06d14e5623a8e879f7e6d56c84650c0f524e2c5b.tar.bz2 |
[aw] Software mode tests for fullscreen API.
To avoid possible deadlocks, we need to propagate
the layer type from the old container view to the
FullscreenView when entering fullscreen.
Plus a number of other improvements:
- Fix a possible crash (improbable outside tests) when
exitFullscreen is called between enterFullscreen and
enterFullscreenVideo
- Test that for fullscreen video a ContentVideoView
is created
- Remove some flakiness by waiting for the fulscreen
property in Javascript to be set
BUG=424213,429642
Review URL: https://codereview.chromium.org/667143002
Cr-Commit-Position: refs/heads/master@{#302816}
Diffstat (limited to 'android_webview/javatests/src')
4 files changed, 133 insertions, 21 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java index d87a66a..5881f20 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java @@ -10,12 +10,15 @@ import android.view.ViewGroup; import org.chromium.android_webview.test.util.JavascriptEventObserver; import org.chromium.base.test.util.Feature; +import org.chromium.content.browser.ContentVideoView; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.TouchCommon; +import org.chromium.content_public.browser.WebContents; +import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; /** @@ -47,7 +50,8 @@ public class AwContentsClientFullScreenTest extends AwTestBase { @Override protected void setUp() throws Exception { super.setUp(); - mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity()); + mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity(), + isHardwareAcceleratedTest()); mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient); mContentViewCore = mTestContainerView.getContentViewCore(); @@ -57,6 +61,32 @@ public class AwContentsClientFullScreenTest extends AwTestBase { @MediumTest @Feature({"AndroidWebView"}) + @DisableHardwareAccelerationForTest + public void testFullscreenVideoInSoftwareModeDoesNotDeadlock() throws Throwable { + // Although fullscreen video is not supported without hardware acceleration + // we should not deadlock if apps try to use it. + loadTestPageAndClickFullscreen(VIDEO_TEST_URL); + mContentsClient.waitForCustomViewShown(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + mContentsClient.getExitCallback().onCustomViewHidden(); + } + }); + mContentsClient.waitForCustomViewHidden(); + } + + @MediumTest + @Feature({"AndroidWebView"}) + @DisableHardwareAccelerationForTest + public void testFullscreenForNonVideoElementIsSupportedInSoftwareMode() throws Throwable { + // Fullscreen for non-video elements is supported and works as expected. Note that + // this test is the same as testOnShowAndHideCustomViewWithCallback_videoInsideDiv below. + doTestOnShowAndHideCustomViewWithCallback(VIDEO_INSIDE_DIV_TEST_URL); + } + + @MediumTest + @Feature({"AndroidWebView"}) public void testOnShowAndHideCustomViewWithCallback_video() throws Throwable { doTestOnShowAndHideCustomViewWithCallback(VIDEO_TEST_URL); } @@ -112,10 +142,10 @@ public class AwContentsClientFullScreenTest extends AwTestBase { public void doTestOnShowCustomViewAndPlayWithHtmlControl(String videoTestUrl) throws Throwable { doOnShowCustomViewTest(videoTestUrl); - assertTrue(DOMUtils.isVideoPaused(mContentViewCore.getWebContents(), VIDEO_ID)); + assertTrue(DOMUtils.isVideoPaused(getWebContentsOnUiThread(), VIDEO_ID)); tapPlayButton(); - assertTrue(DOMUtils.waitForVideoPlay(mContentViewCore.getWebContents(), VIDEO_ID)); + assertTrue(DOMUtils.waitForVideoPlay(getWebContentsOnUiThread(), VIDEO_ID)); } @MediumTest @@ -169,7 +199,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { assertKeepScreenOnActive(customView, true); // Stop the video and verify that the power save blocker is gone. - DOMUtils.pauseVideo(mContentViewCore.getWebContents(), VIDEO_ID); + DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); assertKeepScreenOnActive(customView, false); } @@ -177,7 +207,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { @Feature({"AndroidWebView"}) public void testPowerSaveBlockerIsEnabledDuringEmbeddedPlayback() throws Throwable { - assertFalse(DOMUtils.isFullscreen(mContentViewCore.getWebContents())); + assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); // No power save blocker is active before playback starts. @@ -188,7 +218,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { assertKeepScreenOnActive(mTestContainerView, true); // Stop the video and verify that the power save blocker is gone. - DOMUtils.pauseVideo(mContentViewCore.getWebContents(), VIDEO_ID); + DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); assertKeepScreenOnActive(mTestContainerView, false); } @@ -196,7 +226,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { @Feature({"AndroidWebView"}) public void testPowerSaveBlockerIsTransferredToFullscreen() throws Throwable { - assertFalse(DOMUtils.isFullscreen(mContentViewCore.getWebContents())); + assertFalse(DOMUtils.isFullscreen(getWebContentsOnUiThread())); loadTestPage(VIDEO_INSIDE_DIV_TEST_URL); // Play and verify that there is an active power save blocker. @@ -211,11 +241,11 @@ public class AwContentsClientFullScreenTest extends AwTestBase { assertKeepScreenOnActive(customView, true); // Pause the video and the power save blocker is gone. - DOMUtils.pauseVideo(mContentViewCore.getWebContents(), VIDEO_ID); + DOMUtils.pauseVideo(getWebContentsOnUiThread(), VIDEO_ID); assertKeepScreenOnActive(customView, false); // Exit fullscreen and the power save blocker is still gone. - DOMUtils.exitFullscreen(mContentViewCore.getWebContents()); + DOMUtils.exitFullscreen(getWebContentsOnUiThread()); mContentsClient.waitForCustomViewHidden(); assertKeepScreenOnActive(mTestContainerView, false); } @@ -235,7 +265,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { // Exit fullscreen and verify that the power save blocker is // still there. - DOMUtils.exitFullscreen(mContentViewCore.getWebContents()); + DOMUtils.exitFullscreen(getWebContentsOnUiThread()); mContentsClient.waitForCustomViewHidden(); assertKeepScreenOnActive(mTestContainerView, true); } @@ -246,7 +276,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { // VIDEO_INSIDE_DIV_TEST_URL uses a custom play control with known id. DOMUtils.clickNode(this, mContentViewCore, CUSTOM_PLAY_CONTROL_ID); } else if (VIDEO_TEST_URL.equals(testUrl) - && DOMUtils.isFullscreen(mContentViewCore.getWebContents())) { + && DOMUtils.isFullscreen(getWebContentsOnUiThread())) { // VIDEO_TEST_URL uses the standard html5 video controls. The standard // html5 controls are shadow html elements without any ids. In fullscreen we can still // tap the play button because this is rendered in the center of the custom view. @@ -270,7 +300,7 @@ public class AwContentsClientFullScreenTest extends AwTestBase { public boolean isSatisfied() { try { return getKeepScreenOn(view) == expected - && DOMUtils.isVideoPaused(mContentViewCore.getWebContents(), VIDEO_ID) + && DOMUtils.isVideoPaused(getWebContentsOnUiThread(), VIDEO_ID) != expected; } catch (InterruptedException | TimeoutException e) { fail(e.getMessage()); @@ -294,9 +324,60 @@ public class AwContentsClientFullScreenTest extends AwTestBase { return view.getKeepScreenOn(); } - private JavascriptEventObserver registerObserver(final String observerName) { + private void assertIsFullscreen() throws InterruptedException { + // We need to poll because the Javascript state is updated asynchronously + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + try { + return DOMUtils.isFullscreen(getWebContentsOnUiThread()); + } catch (InterruptedException | TimeoutException e) { + fail(e.getMessage()); + return false; + } + } + })); + } + + private void assertContainsContentVideoView() + throws InterruptedException { + // We need to poll because the ContentVideoView is added to the customView asynchronously + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + try { + return runTestOnUiThreadAndGetResult(new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return containsVideoView(mContentsClient.getCustomView()); + } + }); + } catch (Exception e) { + fail(e.getMessage()); + return false; + } + } + })); + } + + private boolean containsVideoView(View view) { + if (view instanceof ContentVideoView) { + return true; + } + if (view instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + if (containsVideoView(viewGroup.getChildAt(i))) { + return true; + } + } + } + return false; + } + + private JavascriptEventObserver registerObserver(final String observerName) throws Throwable { final JavascriptEventObserver observer = new JavascriptEventObserver(); - getInstrumentation().runOnMainSync(new Runnable() { + runTestOnUiThread(new Runnable() { @Override public void run() { observer.register(mContentViewCore, observerName); @@ -308,14 +389,19 @@ public class AwContentsClientFullScreenTest extends AwTestBase { private void doOnShowAndHideCustomViewTest(String videoTestUrl, final Runnable existFullscreen) throws Throwable { doOnShowCustomViewTest(videoTestUrl); - getInstrumentation().runOnMainSync(existFullscreen); + runTestOnUiThread(existFullscreen); mContentsClient.waitForCustomViewHidden(); } private void doOnShowCustomViewTest(String videoTestUrl) throws Exception { loadTestPageAndClickFullscreen(videoTestUrl); mContentsClient.waitForCustomViewShown(); - assertTrue(DOMUtils.isFullscreen(mContentViewCore.getWebContents())); + assertIsFullscreen(); + if (videoTestUrl.equals(VIDEO_TEST_URL)) { + // We only create a ContentVideoView (ie. a hardware accelerated surface) when going + // fullscreen on a video element. + assertContainsContentVideoView(); + } } private void loadTestPageAndClickFullscreen(String videoTestUrl) throws Exception { @@ -327,4 +413,18 @@ public class AwContentsClientFullScreenTest extends AwTestBase { loadUrlSync(mTestContainerView.getAwContents(), mContentsClient.getOnPageFinishedHelper(), videoTestUrl); } + + private WebContents getWebContentsOnUiThread() { + try { + return runTestOnUiThreadAndGetResult(new Callable<WebContents>() { + @Override + public WebContents call() throws Exception { + return mContentViewCore.getWebContents(); + } + }); + } catch (Exception e) { + fail(e.getMessage()); + return null; + } + } } diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java index a053102..6275682 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientGetVideoLoadingProgressViewTest.java @@ -52,7 +52,8 @@ public class AwContentsClientGetVideoLoadingProgressViewTest extends AwTestBase @SmallTest public void testGetVideoLoadingProgressView() throws Throwable { TestAwContentsClient contentsClient = - new FullScreenVideoTestAwContentsClient(getActivity()) { + new FullScreenVideoTestAwContentsClient( + getActivity(), isHardwareAcceleratedTest()) { @Override protected View getVideoLoadingProgressView() { View view = new View(getInstrumentation().getTargetContext()); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java index c328392..2e2c500 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java @@ -332,8 +332,7 @@ public class AwTestBase final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) { final TestDependencyFactory testDependencyFactory = createTestDependencyFactory(); - boolean allowHardwareAcceleration = !testMethodHasAnnotation( - DisableHardwareAccelerationForTest.class); + boolean allowHardwareAcceleration = isHardwareAcceleratedTest(); final AwTestContainerView testContainerView = testDependencyFactory.createAwTestContainerView(getActivity(), allowHardwareAcceleration); @@ -348,6 +347,10 @@ public class AwTestBase return testContainerView; } + protected boolean isHardwareAcceleratedTest() { + return !testMethodHasAnnotation(DisableHardwareAccelerationForTest.class); + } + public AwTestContainerView createAwTestContainerViewOnMainSync( final AwContentsClient client) throws Exception { return createAwTestContainerViewOnMainSync(client, false); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java index c1a82b8..2143c46 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/FullScreenVideoTestAwContentsClient.java @@ -27,17 +27,25 @@ public class FullScreenVideoTestAwContentsClient extends TestAwContentsClient { private CallbackHelper mOnShowCustomViewCallbackHelper = new CallbackHelper(); private CallbackHelper mOnHideCustomViewCallbackHelper = new CallbackHelper(); - private Activity mActivity; + private final Activity mActivity; + private final boolean mAllowHardwareAcceleration; private View mCustomView; private WebChromeClient.CustomViewCallback mExitCallback; - public FullScreenVideoTestAwContentsClient(Activity activity) { + public FullScreenVideoTestAwContentsClient(Activity activity, + boolean allowHardwareAcceleration) { mActivity = activity; + mAllowHardwareAcceleration = allowHardwareAcceleration; } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { mCustomView = view; + if (!mAllowHardwareAcceleration) { + // The hardware emulation in the testing infrastructure is not perfect, and this is + // required to work-around some of the limitations. + mCustomView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } mExitCallback = callback; mActivity.getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, |