1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.test.suitebuilder.annotation.MediumTest;
9 import junit.framework.Assert;
11 import org.chromium.android_webview.test.util.JavascriptEventObserver;
12 import org.chromium.android_webview.test.util.VideoTestWebServer;
13 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.ContentViewCore;
15 import org.chromium.content.browser.test.util.DOMUtils;
16 import org.chromium.content.browser.test.util.TouchCommon;
19 * Test WebChromeClient::onShow/HideCustomView.
21 public class AwContentsClientFullScreenVideoTest extends AwTestBase {
22 private FullScreenVideoTestAwContentsClient mContentsClient;
23 private ContentViewCore mContentViewCore;
24 private VideoTestWebServer mWebServer;
25 private AwTestContainerView mTestContainerView;
28 protected void setUp() throws Exception {
30 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity());
32 createAwTestContainerViewOnMainSync(mContentsClient);
33 mContentViewCore = mTestContainerView.getContentViewCore();
34 enableJavaScriptOnUiThread(mTestContainerView.getAwContents());
35 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(true);
36 mWebServer = new VideoTestWebServer(
37 getInstrumentation().getTargetContext());
41 protected void tearDown() throws Exception {
43 if (mWebServer != null) mWebServer.getTestWebServer().shutdown();
47 @Feature({"AndroidWebView"})
48 public void testOnShowAndHideCustomViewWithCallback() throws Throwable {
49 doOnShowAndHideCustomViewTest(new Runnable() {
52 mContentsClient.getExitCallback().onCustomViewHidden();
58 @Feature({"AndroidWebView"})
59 public void testOnShowAndHideCustomViewWithJavascript() throws Throwable {
60 doOnShowAndHideCustomViewTest(new Runnable() {
63 DOMUtils.exitFullscreen(mContentViewCore);
69 @Feature({"AndroidWebView"})
70 public void testOnShowCustomViewAndPlayWithHtmlControl() throws Throwable {
71 doOnShowCustomViewTest();
72 Assert.assertFalse(DOMUtils.hasVideoEnded(
73 mContentViewCore, VideoTestWebServer.VIDEO_ID));
75 // Click the html play button that is rendered above the video right in the middle
76 // of the custom view. Note that we're not able to get the precise location of the
77 // control since it is a shadow element, so this test might break if the location
79 TouchCommon touchCommon = new TouchCommon(
80 AwContentsClientFullScreenVideoTest.this);
81 touchCommon.singleClickView(mContentsClient.getCustomView());
83 Assert.assertTrue(DOMUtils.waitForEndOfVideo(
84 mContentViewCore, VideoTestWebServer.VIDEO_ID));
88 @Feature({"AndroidWebView"})
89 public void testFullscreenNotSupported() throws Throwable {
90 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(false);
92 final JavascriptEventObserver fullScreenErrorObserver = new JavascriptEventObserver();
93 getInstrumentation().runOnMainSync(new Runnable() {
96 fullScreenErrorObserver.register(mContentViewCore, "javaFullScreenErrorObserver");
100 loadTestPageAndClickFullscreen();
102 Assert.assertTrue(fullScreenErrorObserver.waitForEvent(500));
103 Assert.assertFalse(mContentsClient.wasCustomViewShownCalled());
106 private void doOnShowAndHideCustomViewTest(final Runnable existFullscreen)
108 doOnShowCustomViewTest();
109 getInstrumentation().runOnMainSync(existFullscreen);
110 mContentsClient.waitForCustomViewHidden();
113 private void doOnShowCustomViewTest() throws Exception {
114 loadTestPageAndClickFullscreen();
115 mContentsClient.waitForCustomViewShown();
118 private void loadTestPageAndClickFullscreen() throws Exception {
119 loadUrlSync(mTestContainerView.getAwContents(),
120 mContentsClient.getOnPageFinishedHelper(),
121 mWebServer.getFullScreenVideoTestURL());
123 // Click the button in full_screen_video_test.html to enter fullscreen.
124 TouchCommon touchCommon = new TouchCommon(this);
125 touchCommon.singleClickView(mTestContainerView);