Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 package org.chromium.android_webview.test; | |
| 6 | |
| 7 import android.test.suitebuilder.annotation.MediumTest; | |
| 8 | |
| 9 import org.chromium.android_webview.test.util.JavascriptEventObserver; | |
| 10 import org.chromium.android_webview.test.util.VideoTestWebServer; | |
| 11 import org.chromium.base.test.util.Feature; | |
| 12 import org.chromium.content.browser.ContentViewCore; | |
| 13 import org.chromium.content.browser.test.util.DOMUtils; | |
| 14 import org.chromium.content.browser.test.util.TouchCommon; | |
| 15 | |
| 16 /** | |
| 17 * Test the fullscreen API (WebChromeClient::onShow/HideCustomView). | |
| 18 * | |
| 19 * <p>Fullscreen support follows a different code path depending on whether | |
| 20 * the element is a video or not, so we test we both. For non-video elements | |
| 21 * we pick a div containing a video and custom html controls since this is a | |
| 22 * very common use case. | |
| 23 */ | |
| 24 public class AwContentsClientFullScreenTest extends AwTestBase { | |
| 25 private FullScreenVideoTestAwContentsClient mContentsClient; | |
| 26 private ContentViewCore mContentViewCore; | |
| 27 private VideoTestWebServer mWebServer; | |
| 28 private AwTestContainerView mTestContainerView; | |
| 29 | |
| 30 @Override | |
| 31 protected void setUp() throws Exception { | |
| 32 super.setUp(); | |
| 33 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity()) ; | |
| 34 mTestContainerView = | |
| 35 createAwTestContainerViewOnMainSync(mContentsClient); | |
| 36 mContentViewCore = mTestContainerView.getContentViewCore(); | |
| 37 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); | |
| 38 mTestContainerView.getAwContents().getSettings().setFullscreenSupported( true); | |
| 39 mWebServer = new VideoTestWebServer( | |
| 40 getInstrumentation().getTargetContext()); | |
| 41 } | |
| 42 | |
| 43 @Override | |
| 44 protected void tearDown() throws Exception { | |
| 45 super.tearDown(); | |
| 46 if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); | |
| 47 } | |
| 48 | |
| 49 @MediumTest | |
| 50 @Feature({"AndroidWebView"}) | |
| 51 public void testOnShowAndHideCustomViewWithCallback_video() throws Throwable { | |
| 52 doTestOnShowAndHideCustomViewWithCallback(getFullScreenVideoTestUrl()); | |
| 53 } | |
| 54 | |
| 55 @MediumTest | |
| 56 @Feature({"AndroidWebView"}) | |
| 57 public void testOnShowAndHideCustomViewWithCallback_videoInsideDiv() throws Throwable { | |
| 58 doTestOnShowAndHideCustomViewWithCallback(getFullScreenVideoInsideDivTes tUrl()); | |
| 59 } | |
| 60 | |
| 61 public void doTestOnShowAndHideCustomViewWithCallback(String videoTestUrl) t hrows Throwable { | |
| 62 doOnShowAndHideCustomViewTest(videoTestUrl, new Runnable() { | |
| 63 @Override | |
| 64 public void run() { | |
| 65 mContentsClient.getExitCallback().onCustomViewHidden(); | |
| 66 } | |
| 67 }); | |
| 68 } | |
| 69 | |
| 70 @MediumTest | |
| 71 @Feature({"AndroidWebView"}) | |
| 72 public void testOnShowAndHideCustomViewWithJavascript_video() throws Throwab le { | |
| 73 doTestOnShowAndHideCustomViewWithJavascript(getFullScreenVideoTestUrl()) ; | |
| 74 } | |
| 75 | |
| 76 @MediumTest | |
| 77 @Feature({"AndroidWebView"}) | |
| 78 public void testOnShowAndHideCustomViewWithJavascript_videoInsideDiv() | |
| 79 throws Throwable { | |
| 80 doTestOnShowAndHideCustomViewWithJavascript(getFullScreenVideoInsideDivT estUrl()); | |
| 81 } | |
| 82 | |
| 83 public void doTestOnShowAndHideCustomViewWithJavascript(String videoTestUrl) throws Throwable { | |
| 84 doOnShowAndHideCustomViewTest(videoTestUrl, new Runnable() { | |
| 85 @Override | |
| 86 public void run() { | |
| 87 DOMUtils.exitFullscreen(mContentViewCore); | |
| 88 } | |
| 89 }); | |
| 90 } | |
| 91 | |
| 92 @MediumTest | |
| 93 @Feature({"AndroidWebView"}) | |
| 94 public void testOnShowCustomViewAndPlayWithHtmlControl_video() throws Throwa ble { | |
| 95 doTestOnShowCustomViewAndPlayWithHtmlControl(getFullScreenVideoTestUrl() ); | |
| 96 } | |
| 97 | |
| 98 @MediumTest | |
| 99 @Feature({"AndroidWebView"}) | |
| 100 public void testOnShowCustomViewAndPlayWithHtmlControl_videoInsideDiv() thro ws Throwable { | |
| 101 doTestOnShowCustomViewAndPlayWithHtmlControl(getFullScreenVideoInsideDiv TestUrl()); | |
| 102 } | |
| 103 | |
| 104 public void doTestOnShowCustomViewAndPlayWithHtmlControl(String videoTestUrl ) throws Throwable { | |
| 105 final JavascriptEventObserver onPlayObserver = registerObserver("javaOnP layObserver"); | |
| 106 | |
| 107 doOnShowCustomViewTest(videoTestUrl); | |
| 108 | |
| 109 // Click the html play button that is rendered above the video right in the middle | |
| 110 // of the custom view. Note that we're not able to get the precise locat ion of the | |
| 111 // control since it is a shadow element, so this test might break if the location | |
| 112 // ever moves. | |
| 113 TouchCommon touchCommon = new TouchCommon( | |
| 114 AwContentsClientFullScreenTest.this); | |
| 115 touchCommon.singleClickView(mContentsClient.getCustomView()); | |
| 116 | |
| 117 assertTrue(onPlayObserver.waitForEvent(2000)); | |
|
mkosiba (inactive)
2014/10/09 15:18:54
any reason not to use AwTestBase.WAIT_TIMEOUT_MS?
Ignacio Solla
2014/10/10 15:34:19
Changed to WAIT_TIMEOUT_MS.
| |
| 118 } | |
| 119 | |
| 120 @MediumTest | |
| 121 @Feature({"AndroidWebView"}) | |
| 122 public void testFullscreenNotSupported_video() throws Throwable { | |
| 123 doTestFullscreenNotSupported(getFullScreenVideoTestUrl()); | |
| 124 } | |
| 125 | |
| 126 @MediumTest | |
| 127 @Feature({"AndroidWebView"}) | |
| 128 public void testFullscreenNotSupported_videoInsideDiv() throws Throwable { | |
| 129 doTestFullscreenNotSupported(getFullScreenVideoInsideDivTestUrl()); | |
| 130 } | |
| 131 | |
| 132 public void doTestFullscreenNotSupported(String videoTestUrl) throws Throwab le { | |
| 133 mTestContainerView.getAwContents().getSettings().setFullscreenSupported( false); | |
| 134 | |
| 135 final JavascriptEventObserver fullScreenErrorObserver = registerObserver ( | |
| 136 "javaFullScreenErrorObserver"); | |
| 137 | |
| 138 loadTestPageAndClickFullscreen(videoTestUrl); | |
| 139 | |
| 140 assertTrue(fullScreenErrorObserver.waitForEvent(500)); | |
|
mkosiba (inactive)
2014/10/09 15:18:54
same here.
Ignacio Solla
2014/10/10 15:34:19
Done.
| |
| 141 assertFalse(mContentsClient.wasCustomViewShownCalled()); | |
| 142 } | |
| 143 | |
| 144 private JavascriptEventObserver registerObserver(final String observerName) { | |
| 145 final JavascriptEventObserver observer = new JavascriptEventObserver(); | |
| 146 getInstrumentation().runOnMainSync(new Runnable() { | |
| 147 @Override | |
| 148 public void run() { | |
| 149 observer.register(mContentViewCore, observerName); | |
| 150 } | |
| 151 }); | |
| 152 return observer; | |
| 153 } | |
| 154 | |
| 155 private void doOnShowAndHideCustomViewTest(String videoTestUrl, final Runnab le existFullscreen) | |
| 156 throws Throwable { | |
| 157 doOnShowCustomViewTest(videoTestUrl); | |
| 158 getInstrumentation().runOnMainSync(existFullscreen); | |
| 159 mContentsClient.waitForCustomViewHidden(); | |
| 160 } | |
| 161 | |
| 162 private void doOnShowCustomViewTest(String videoTestUrl) throws Exception { | |
| 163 final JavascriptEventObserver onEnterFullscreenObserver = | |
| 164 registerObserver("javaOnEnterFullscreen"); | |
| 165 loadTestPageAndClickFullscreen(videoTestUrl); | |
| 166 mContentsClient.waitForCustomViewShown(); | |
| 167 assertTrue(onEnterFullscreenObserver.waitForEvent(2000)); | |
|
mkosiba (inactive)
2014/10/09 15:18:54
and here
Ignacio Solla
2014/10/10 15:34:19
Done.
| |
| 168 } | |
| 169 | |
| 170 private void loadTestPageAndClickFullscreen(String videoTestUrl) throws Exce ption { | |
| 171 loadUrlSync(mTestContainerView.getAwContents(), | |
| 172 mContentsClient.getOnPageFinishedHelper(), videoTestUrl); | |
| 173 | |
| 174 // Click the button in full_screen_video_test.html to enter fullscreen. | |
| 175 TouchCommon touchCommon = new TouchCommon(this); | |
| 176 touchCommon.singleClickView(mTestContainerView); | |
| 177 } | |
| 178 | |
| 179 private String getFullScreenVideoTestUrl() { | |
| 180 return mWebServer.getFullScreenVideoTestURL(); | |
| 181 } | |
| 182 | |
| 183 private String getFullScreenVideoInsideDivTestUrl() { | |
| 184 return mWebServer.getFullScreenVideoInsideDivTestURL(); | |
| 185 } | |
| 186 } | |
| OLD | NEW |