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
5package org.chromium.android_webview.test;
6
7import android.view.View;
8
9import org.chromium.android_webview.AwContents;
10import org.chromium.android_webview.test.util.VideoTestWebServer;
11import org.chromium.base.test.util.DisabledTest;
12import org.chromium.content.browser.test.util.CallbackHelper;
13import org.chromium.content.browser.test.util.TouchCommon;
14
15import java.util.concurrent.TimeUnit;
16import java.util.concurrent.TimeoutException;
17
18/**
19 * Test for AwContentClient.GetVideoLoadingProgressView.
20 *
21 * This test takes advantage of onViewAttachedToWindow, and assume our progress view
22 * is shown once it attached to window.
23 *
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
26 * can't miss it.
27 */
28public class AwContentsClientGetVideoLoadingProgressViewTest extends AwTestBase
29        implements View.OnAttachStateChangeListener {
30    private CallbackHelper mViewAttachedCallbackHelper = new CallbackHelper();
31
32    @Override
33    public void onViewAttachedToWindow(View view) {
34        mViewAttachedCallbackHelper.notifyCalled();
35        view.removeOnAttachStateChangeListener(this);
36    }
37
38    @Override
39    public void onViewDetachedFromWindow(View arg0) {
40    }
41
42    private void waitForViewAttached() throws InterruptedException, TimeoutException {
43        mViewAttachedCallbackHelper.waitForCallback(0, 1, WAIT_TIMEOUT_MS,
44                TimeUnit.MILLISECONDS);
45    }
46
47
48    /**
49     * @Feature({"AndroidWebView"})
50     * @SmallTest
51     *
52     * http://crbug.com/238735
53     */
54    @DisabledTest
55    public void testGetVideoLoadingProgressView() throws Throwable {
56        TestAwContentsClient contentsClient =
57                new FullScreenVideoTestAwContentsClient(getActivity()) {
58                    @Override
59                    protected View getVideoLoadingProgressView() {
60                        View view = new View(getInstrumentation().getTargetContext());
61                        view.addOnAttachStateChangeListener(
62                                AwContentsClientGetVideoLoadingProgressViewTest.this);
63                        return view;
64                    }
65                };
66        final AwTestContainerView testContainerView =
67                createAwTestContainerViewOnMainSync(contentsClient);
68        final AwContents awContents = testContainerView.getAwContents();
69        enableJavaScriptOnUiThread(awContents);
70        VideoTestWebServer webServer = new VideoTestWebServer(
71                getInstrumentation().getTargetContext());
72        try {
73            loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(),
74                    webServer.getFullScreenVideoTestURL());
75            Thread.sleep(5 * 1000);
76            TouchCommon touchCommon = new TouchCommon(this);
77            touchCommon.singleClickView(testContainerView);
78            waitForViewAttached();
79        } finally {
80            if (webServer != null) webServer.getTestWebServer().shutdown();
81        }
82    }
83}
84