| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 | 8 |
| 9 import junit.framework.Assert; | 9 import junit.framework.Assert; |
| 10 | 10 |
| 11 import org.chromium.android_webview.test.util.JavascriptEventObserver; | 11 import org.chromium.android_webview.test.util.JavascriptEventObserver; |
| 12 import org.chromium.android_webview.test.util.VideoTestWebServer; | 12 import org.chromium.android_webview.test.util.VideoTestWebServer; |
| 13 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.content.browser.ContentViewCore; | 14 import org.chromium.content.browser.ContentViewCore; |
| 15 import org.chromium.content.browser.test.util.DOMUtils; | 15 import org.chromium.content.browser.test.util.DOMUtils; |
| 16 import org.chromium.content.browser.test.util.TouchCommon; | 16 import org.chromium.content.browser.test.util.TouchCommon; |
| 17 import org.chromium.content_public.browser.WebContents; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * Test WebChromeClient::onShow/HideCustomView. | 20 * Test WebChromeClient::onShow/HideCustomView. |
| 20 */ | 21 */ |
| 21 public class AwContentsClientFullScreenVideoTest extends AwTestBase { | 22 public class AwContentsClientFullScreenVideoTest extends AwTestBase { |
| 22 private FullScreenVideoTestAwContentsClient mContentsClient; | 23 private FullScreenVideoTestAwContentsClient mContentsClient; |
| 23 private ContentViewCore mContentViewCore; | 24 private ContentViewCore mContentViewCore; |
| 25 private WebContents mWebContents; |
| 24 private VideoTestWebServer mWebServer; | 26 private VideoTestWebServer mWebServer; |
| 25 private AwTestContainerView mTestContainerView; | 27 private AwTestContainerView mTestContainerView; |
| 26 | 28 |
| 27 @Override | 29 @Override |
| 28 protected void setUp() throws Exception { | 30 protected void setUp() throws Exception { |
| 29 super.setUp(); | 31 super.setUp(); |
| 30 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity())
; | 32 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity())
; |
| 31 mTestContainerView = | 33 mTestContainerView = |
| 32 createAwTestContainerViewOnMainSync(mContentsClient); | 34 createAwTestContainerViewOnMainSync(mContentsClient); |
| 33 mContentViewCore = mTestContainerView.getContentViewCore(); | 35 mContentViewCore = mTestContainerView.getContentViewCore(); |
| 36 mWebContents = mTestContainerView.getAwContents().getWebContents(); |
| 34 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); | 37 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); |
| 35 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
true); | 38 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
true); |
| 36 mWebServer = new VideoTestWebServer( | 39 mWebServer = new VideoTestWebServer( |
| 37 getInstrumentation().getTargetContext()); | 40 getInstrumentation().getTargetContext()); |
| 38 } | 41 } |
| 39 | 42 |
| 40 @Override | 43 @Override |
| 41 protected void tearDown() throws Exception { | 44 protected void tearDown() throws Exception { |
| 42 super.tearDown(); | 45 super.tearDown(); |
| 43 if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); | 46 if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 @MediumTest | 49 @MediumTest |
| 47 @Feature({"AndroidWebView"}) | 50 @Feature({"AndroidWebView"}) |
| 48 public void testOnShowAndHideCustomViewWithCallback() throws Throwable { | 51 public void testOnShowAndHideCustomViewWithCallback() throws Throwable { |
| 49 doOnShowAndHideCustomViewTest(new Runnable() { | 52 doOnShowAndHideCustomViewTest(new Runnable() { |
| 50 @Override | 53 @Override |
| 51 public void run() { | 54 public void run() { |
| 52 mContentsClient.getExitCallback().onCustomViewHidden(); | 55 mContentsClient.getExitCallback().onCustomViewHidden(); |
| 53 } | 56 } |
| 54 }); | 57 }); |
| 55 } | 58 } |
| 56 | 59 |
| 57 @MediumTest | 60 @MediumTest |
| 58 @Feature({"AndroidWebView"}) | 61 @Feature({"AndroidWebView"}) |
| 59 public void testOnShowAndHideCustomViewWithJavascript() throws Throwable { | 62 public void testOnShowAndHideCustomViewWithJavascript() throws Throwable { |
| 60 doOnShowAndHideCustomViewTest(new Runnable() { | 63 doOnShowAndHideCustomViewTest(new Runnable() { |
| 61 @Override | 64 @Override |
| 62 public void run() { | 65 public void run() { |
| 63 DOMUtils.exitFullscreen(mContentViewCore); | 66 DOMUtils.exitFullscreen(mWebContents); |
| 64 } | 67 } |
| 65 }); | 68 }); |
| 66 } | 69 } |
| 67 | 70 |
| 68 @MediumTest | 71 @MediumTest |
| 69 @Feature({"AndroidWebView"}) | 72 @Feature({"AndroidWebView"}) |
| 70 public void testOnShowCustomViewAndPlayWithHtmlControl() throws Throwable { | 73 public void testOnShowCustomViewAndPlayWithHtmlControl() throws Throwable { |
| 71 doOnShowCustomViewTest(); | 74 doOnShowCustomViewTest(); |
| 72 Assert.assertFalse(DOMUtils.hasVideoEnded( | 75 Assert.assertFalse(DOMUtils.hasVideoEnded(mWebContents, VideoTestWebServ
er.VIDEO_ID)); |
| 73 mContentViewCore, VideoTestWebServer.VIDEO_ID)); | |
| 74 | 76 |
| 75 // Click the html play button that is rendered above the video right in
the middle | 77 // 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 locat
ion of the | 78 // of the custom view. Note that we're not able to get the precise locat
ion of the |
| 77 // control since it is a shadow element, so this test might break if the
location | 79 // control since it is a shadow element, so this test might break if the
location |
| 78 // ever moves. | 80 // ever moves. |
| 79 TouchCommon touchCommon = new TouchCommon( | 81 TouchCommon touchCommon = new TouchCommon( |
| 80 AwContentsClientFullScreenVideoTest.this); | 82 AwContentsClientFullScreenVideoTest.this); |
| 81 touchCommon.singleClickView(mContentsClient.getCustomView()); | 83 touchCommon.singleClickView(mContentsClient.getCustomView()); |
| 82 | 84 |
| 83 Assert.assertTrue(DOMUtils.waitForEndOfVideo( | 85 Assert.assertTrue(DOMUtils.waitForEndOfVideo(mWebContents, VideoTestWebS
erver.VIDEO_ID)); |
| 84 mContentViewCore, VideoTestWebServer.VIDEO_ID)); | |
| 85 } | 86 } |
| 86 | 87 |
| 87 @MediumTest | 88 @MediumTest |
| 88 @Feature({"AndroidWebView"}) | 89 @Feature({"AndroidWebView"}) |
| 89 public void testFullscreenNotSupported() throws Throwable { | 90 public void testFullscreenNotSupported() throws Throwable { |
| 90 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
false); | 91 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
false); |
| 91 | 92 |
| 92 final JavascriptEventObserver fullScreenErrorObserver = new JavascriptEv
entObserver(); | 93 final JavascriptEventObserver fullScreenErrorObserver = new JavascriptEv
entObserver(); |
| 93 getInstrumentation().runOnMainSync(new Runnable() { | 94 getInstrumentation().runOnMainSync(new Runnable() { |
| 94 @Override | 95 @Override |
| (...skipping 23 matching lines...) Expand all Loading... |
| 118 private void loadTestPageAndClickFullscreen() throws Exception { | 119 private void loadTestPageAndClickFullscreen() throws Exception { |
| 119 loadUrlSync(mTestContainerView.getAwContents(), | 120 loadUrlSync(mTestContainerView.getAwContents(), |
| 120 mContentsClient.getOnPageFinishedHelper(), | 121 mContentsClient.getOnPageFinishedHelper(), |
| 121 mWebServer.getFullScreenVideoTestURL()); | 122 mWebServer.getFullScreenVideoTestURL()); |
| 122 | 123 |
| 123 // Click the button in full_screen_video_test.html to enter fullscreen. | 124 // Click the button in full_screen_video_test.html to enter fullscreen. |
| 124 TouchCommon touchCommon = new TouchCommon(this); | 125 TouchCommon touchCommon = new TouchCommon(this); |
| 125 touchCommon.singleClickView(mTestContainerView); | 126 touchCommon.singleClickView(mTestContainerView); |
| 126 } | 127 } |
| 127 } | 128 } |
| OLD | NEW |