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.android_webview.test.util.VideoTestWebServer;
12 import org.chromium.base.test.util.DisabledTest;
13 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.test.util.CallbackHelper;
15 import org.chromium.content.browser.test.util.TouchCommon;
17 import java.util.concurrent.TimeUnit;
18 import java.util.concurrent.TimeoutException;
21 * Test for AwContentClient.GetVideoLoadingProgressView.
23 * This test takes advantage of onViewAttachedToWindow, and assume our progress view
24 * is shown once it attached to window.
26 * As it needs user gesture to switch to the full screen mode video, A large button
27 * used to trigger switch occupies almost the whole WebView so the simulated click event
30 public class AwContentsClientGetVideoLoadingProgressViewTest extends AwTestBase
31 implements View.OnAttachStateChangeListener {
32 private CallbackHelper mViewAttachedCallbackHelper = new CallbackHelper();
35 public void onViewAttachedToWindow(View view) {
36 mViewAttachedCallbackHelper.notifyCalled();
37 view.removeOnAttachStateChangeListener(this);
41 public void onViewDetachedFromWindow(View arg0) {
44 private void waitForViewAttached() throws InterruptedException, TimeoutException {
45 mViewAttachedCallbackHelper.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
50 * @Feature({"AndroidWebView"})
53 * http://crbug.com/238735
56 public void testGetVideoLoadingProgressView() throws Throwable {
57 TestAwContentsClient contentsClient =
58 new FullScreenVideoTestAwContentsClient(getActivity()) {
60 protected View getVideoLoadingProgressView() {
61 View view = new View(getInstrumentation().getTargetContext());
62 view.addOnAttachStateChangeListener(
63 AwContentsClientGetVideoLoadingProgressViewTest.this);
67 final AwTestContainerView testContainerView =
68 createAwTestContainerViewOnMainSync(contentsClient);
69 final AwContents awContents = testContainerView.getAwContents();
70 enableJavaScriptOnUiThread(awContents);
71 VideoTestWebServer webServer = new VideoTestWebServer(
72 getInstrumentation().getTargetContext());
74 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
75 webServer.getFullScreenVideoTestURL());
76 Thread.sleep(5 * 1000);
77 TouchCommon touchCommon = new TouchCommon(this);
78 touchCommon.singleClickView(testContainerView);
79 waitForViewAttached();
81 if (webServer != null) webServer.getTestWebServer().shutdown();