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