| 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 import android.view.KeyEvent; | 8 import android.view.KeyEvent; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 | 10 |
| 11 import junit.framework.Assert; | 11 import junit.framework.Assert; |
| 12 | 12 |
| 13 import org.chromium.android_webview.test.util.JavascriptEventObserver; |
| 13 import org.chromium.android_webview.test.util.VideoTestWebServer; | 14 import org.chromium.android_webview.test.util.VideoTestWebServer; |
| 14 import org.chromium.base.CommandLine; | 15 import org.chromium.base.CommandLine; |
| 15 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 16 import org.chromium.content.browser.ContentViewCore; | 17 import org.chromium.content.browser.ContentViewCore; |
| 17 import org.chromium.content.browser.test.util.DOMUtils; | 18 import org.chromium.content.browser.test.util.DOMUtils; |
| 18 import org.chromium.content.browser.test.util.TouchCommon; | 19 import org.chromium.content.browser.test.util.TouchCommon; |
| 19 import org.chromium.content.common.ContentSwitches; | 20 import org.chromium.content.common.ContentSwitches; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Test WebChromeClient::onShow/HideCustomView. | 23 * Test WebChromeClient::onShow/HideCustomView. |
| 23 */ | 24 */ |
| 24 public class AwContentsClientFullScreenVideoTest extends AwTestBase { | 25 public class AwContentsClientFullScreenVideoTest extends AwTestBase { |
| 25 private FullScreenVideoTestAwContentsClient mContentsClient; | 26 private FullScreenVideoTestAwContentsClient mContentsClient; |
| 26 private ContentViewCore mContentViewCore; | 27 private ContentViewCore mContentViewCore; |
| 27 private VideoTestWebServer mWebServer; | 28 private VideoTestWebServer mWebServer; |
| 28 private AwTestContainerView mTestContainerView; | 29 private AwTestContainerView mTestContainerView; |
| 29 | 30 |
| 30 @Override | 31 @Override |
| 31 protected void setUp() throws Exception { | 32 protected void setUp() throws Exception { |
| 32 super.setUp(); | 33 super.setUp(); |
| 33 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity())
; | 34 mContentsClient = new FullScreenVideoTestAwContentsClient(getActivity())
; |
| 34 mTestContainerView = | 35 mTestContainerView = |
| 35 createAwTestContainerViewOnMainSync(mContentsClient); | 36 createAwTestContainerViewOnMainSync(mContentsClient); |
| 36 mContentViewCore = mTestContainerView.getContentViewCore(); | 37 mContentViewCore = mTestContainerView.getContentViewCore(); |
| 37 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); | 38 enableJavaScriptOnUiThread(mTestContainerView.getAwContents()); |
| 39 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
true); |
| 38 mWebServer = new VideoTestWebServer( | 40 mWebServer = new VideoTestWebServer( |
| 39 getInstrumentation().getTargetContext()); | 41 getInstrumentation().getTargetContext()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 @Override | 44 @Override |
| 43 protected void tearDown() throws Exception { | 45 protected void tearDown() throws Exception { |
| 44 super.tearDown(); | 46 super.tearDown(); |
| 45 if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); | 47 if (mWebServer != null) mWebServer.getTestWebServer().shutdown(); |
| 46 } | 48 } |
| 47 | 49 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // control since it is a shadow element, so this test might break if the
location | 104 // control since it is a shadow element, so this test might break if the
location |
| 103 // ever moves. | 105 // ever moves. |
| 104 TouchCommon touchCommon = new TouchCommon( | 106 TouchCommon touchCommon = new TouchCommon( |
| 105 AwContentsClientFullScreenVideoTest.this); | 107 AwContentsClientFullScreenVideoTest.this); |
| 106 touchCommon.singleClickView(mContentsClient.getCustomView()); | 108 touchCommon.singleClickView(mContentsClient.getCustomView()); |
| 107 | 109 |
| 108 Assert.assertTrue(DOMUtils.waitForEndOfVideo( | 110 Assert.assertTrue(DOMUtils.waitForEndOfVideo( |
| 109 mContentViewCore, VideoTestWebServer.VIDEO_ID)); | 111 mContentViewCore, VideoTestWebServer.VIDEO_ID)); |
| 110 } | 112 } |
| 111 | 113 |
| 114 @MediumTest |
| 115 @Feature({"AndroidWebView"}) |
| 116 public void testFullscreenNotSupported() throws Throwable { |
| 117 mTestContainerView.getAwContents().getSettings().setFullscreenSupported(
false); |
| 118 |
| 119 final JavascriptEventObserver fullScreenErrorObserver = new JavascriptEv
entObserver(); |
| 120 getInstrumentation().runOnMainSync(new Runnable() { |
| 121 @Override |
| 122 public void run() { |
| 123 fullScreenErrorObserver.register(mContentViewCore, "javaFullScre
enErrorObserver"); |
| 124 } |
| 125 }); |
| 126 |
| 127 loadTestPageAndClickFullscreen(); |
| 128 |
| 129 Assert.assertTrue(fullScreenErrorObserver.waitForEvent(500)); |
| 130 Assert.assertFalse(mContentsClient.wasCustomViewShownCalled()); |
| 131 } |
| 132 |
| 112 private static boolean areHtmlControlsEnabled() { | 133 private static boolean areHtmlControlsEnabled() { |
| 113 return !CommandLine.getInstance().hasSwitch( | 134 return !CommandLine.getInstance().hasSwitch( |
| 114 ContentSwitches.DISABLE_OVERLAY_FULLSCREEN_VIDEO_SUBTITLE); | 135 ContentSwitches.DISABLE_OVERLAY_FULLSCREEN_VIDEO_SUBTITLE); |
| 115 } | 136 } |
| 116 | 137 |
| 117 private void doOnShowAndHideCustomViewTest(final Runnable existFullscreen) | 138 private void doOnShowAndHideCustomViewTest(final Runnable existFullscreen) |
| 118 throws Throwable { | 139 throws Throwable { |
| 119 doOnShowCustomViewTest(); | 140 doOnShowCustomViewTest(); |
| 120 getInstrumentation().runOnMainSync(existFullscreen); | 141 getInstrumentation().runOnMainSync(existFullscreen); |
| 121 mContentsClient.waitForCustomViewHidden(); | 142 mContentsClient.waitForCustomViewHidden(); |
| 122 } | 143 } |
| 123 | 144 |
| 124 private void doOnShowCustomViewTest() throws Exception { | 145 private void doOnShowCustomViewTest() throws Exception { |
| 146 loadTestPageAndClickFullscreen(); |
| 147 mContentsClient.waitForCustomViewShown(); |
| 148 } |
| 149 |
| 150 private void loadTestPageAndClickFullscreen() throws Exception { |
| 125 loadUrlSync(mTestContainerView.getAwContents(), | 151 loadUrlSync(mTestContainerView.getAwContents(), |
| 126 mContentsClient.getOnPageFinishedHelper(), | 152 mContentsClient.getOnPageFinishedHelper(), |
| 127 mWebServer.getFullScreenVideoTestURL()); | 153 mWebServer.getFullScreenVideoTestURL()); |
| 128 | 154 |
| 129 // Click the button in full_screen_video_test.html to enter fullscreen. | 155 // Click the button in full_screen_video_test.html to enter fullscreen. |
| 130 TouchCommon touchCommon = new TouchCommon(this); | 156 TouchCommon touchCommon = new TouchCommon(this); |
| 131 touchCommon.singleClickView(mTestContainerView); | 157 touchCommon.singleClickView(mTestContainerView); |
| 132 mContentsClient.waitForCustomViewShown(); | |
| 133 } | 158 } |
| 134 } | 159 } |
| OLD | NEW |