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.app.Activity;
8 import android.view.Gravity;
9 import android.view.KeyEvent;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.view.WindowManager;
13 import android.webkit.WebChromeClient;
14 import android.widget.FrameLayout;
16 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
18 import org.chromium.content.browser.test.util.CallbackHelper;
20 import java.util.concurrent.TimeUnit;
21 import java.util.concurrent.TimeoutException;
24 * This class is a AwContentsClient for full screen video test.
26 public class FullScreenVideoTestAwContentsClient extends TestAwContentsClient {
27 public static final long WAITING_SECONDS = scaleTimeout(20);
28 private CallbackHelper mOnShowCustomViewCallbackHelper = new CallbackHelper();
29 private CallbackHelper mOnHideCustomViewCallbackHelper = new CallbackHelper();
30 private CallbackHelper mOnUnhandledKeyUpEventCallbackHelper = new CallbackHelper();
32 private final Activity mActivity;
33 private final boolean mAllowHardwareAcceleration;
34 private View mCustomView;
35 private WebChromeClient.CustomViewCallback mExitCallback;
37 public FullScreenVideoTestAwContentsClient(Activity activity,
38 boolean allowHardwareAcceleration) {
40 mAllowHardwareAcceleration = allowHardwareAcceleration;
44 public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
46 if (!mAllowHardwareAcceleration) {
47 // The hardware emulation in the testing infrastructure is not perfect, and this is
48 // required to work-around some of the limitations.
49 mCustomView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
51 mExitCallback = callback;
52 mActivity.getWindow().setFlags(
53 WindowManager.LayoutParams.FLAG_FULLSCREEN,
54 WindowManager.LayoutParams.FLAG_FULLSCREEN);
56 mActivity.getWindow().addContentView(view,
57 new FrameLayout.LayoutParams(
58 ViewGroup.LayoutParams.MATCH_PARENT,
59 ViewGroup.LayoutParams.MATCH_PARENT,
61 mOnShowCustomViewCallbackHelper.notifyCalled();
65 public void onHideCustomView() {
66 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
67 mOnHideCustomViewCallbackHelper.notifyCalled();
70 public WebChromeClient.CustomViewCallback getExitCallback() {
75 public void onUnhandledKeyEvent(KeyEvent event) {
76 if (event.getAction() == KeyEvent.ACTION_UP) {
77 mOnUnhandledKeyUpEventCallbackHelper.notifyCalled();
81 public boolean wasOnUnhandledKeyUpEventCalled() {
82 return mOnUnhandledKeyUpEventCallbackHelper.getCallCount() > 0;
85 public View getCustomView() {
89 public boolean wasCustomViewShownCalled() {
90 return mOnShowCustomViewCallbackHelper.getCallCount() > 0;
93 public void waitForCustomViewShown() throws TimeoutException, InterruptedException {
94 mOnShowCustomViewCallbackHelper.waitForCallback(0, 1, WAITING_SECONDS, TimeUnit.SECONDS);
97 public void waitForCustomViewHidden() throws InterruptedException, TimeoutException {
98 mOnHideCustomViewCallbackHelper.waitForCallback(0, 1, WAITING_SECONDS, TimeUnit.SECONDS);