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.SmallTest;
8 import android.view.View;
10 import org.chromium.android_webview.AwContents;
11 import org.chromium.base.test.util.Feature;
12 import org.chromium.content.browser.test.util.CallbackHelper;
13 import org.chromium.content.browser.test.util.DOMUtils;
15 import java.util.concurrent.TimeUnit;
16 import java.util.concurrent.TimeoutException;
19 * Test for AwContentClient.GetVideoLoadingProgressView.
21 * This test takes advantage of onViewAttachedToWindow, and assume our progress view
22 * is shown once it attached to window.
24 * As it needs user gesture to switch to the full screen mode video, A large button
25 * used to trigger switch occupies almost the whole WebView so the simulated click event
28 public class AwContentsClientGetVideoLoadingProgressViewTest extends AwTestBase
29 implements View.OnAttachStateChangeListener {
30 private static final String VIDEO_TEST_URL =
31 "file:///android_asset/full_screen_video_test.html";
32 // This value must be kept in sync with the string in full_screen_video_test.html
33 private static final String CUSTOM_FULLSCREEN_CONTROL_ID = "fullscreenControl";
34 private CallbackHelper mViewAttachedCallbackHelper = new CallbackHelper();
37 public void onViewAttachedToWindow(View view) {
38 mViewAttachedCallbackHelper.notifyCalled();
39 view.removeOnAttachStateChangeListener(this);
43 public void onViewDetachedFromWindow(View arg0) {
46 private void waitForViewAttached() throws InterruptedException, TimeoutException {
47 mViewAttachedCallbackHelper.waitForCallback(0, 1, WAIT_TIMEOUT_MS,
48 TimeUnit.MILLISECONDS);
51 @Feature({"AndroidWebView"})
53 public void testGetVideoLoadingProgressView() throws Throwable {
54 TestAwContentsClient contentsClient =
55 new FullScreenVideoTestAwContentsClient(
56 getActivity(), isHardwareAcceleratedTest()) {
58 protected View getVideoLoadingProgressView() {
59 View view = new View(getInstrumentation().getTargetContext());
60 view.addOnAttachStateChangeListener(
61 AwContentsClientGetVideoLoadingProgressViewTest.this);
65 final AwTestContainerView testContainerView =
66 createAwTestContainerViewOnMainSync(contentsClient);
67 final AwContents awContents = testContainerView.getAwContents();
68 awContents.getSettings().setFullscreenSupported(true);
69 enableJavaScriptOnUiThread(awContents);
70 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), VIDEO_TEST_URL);
71 Thread.sleep(5 * 1000);
72 DOMUtils.clickNode(this, awContents.getContentViewCore(), CUSTOM_FULLSCREEN_CONTROL_ID);
73 waitForViewAttached();