Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / android_webview / javatests / src / org / chromium / android_webview / test / AwContentsClientGetVideoLoadingProgressViewTest.java
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.base.test.util.Feature;
12 import org.chromium.content.browser.test.util.CallbackHelper;
13 import org.chromium.content.browser.test.util.DOMUtils;
14
15 import java.util.concurrent.TimeUnit;
16 import 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  */
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();
35
36     @Override
37     public void onViewAttachedToWindow(View view) {
38         mViewAttachedCallbackHelper.notifyCalled();
39         view.removeOnAttachStateChangeListener(this);
40     }
41
42     @Override
43     public void onViewDetachedFromWindow(View arg0) {
44     }
45
46     private void waitForViewAttached() throws InterruptedException, TimeoutException {
47         mViewAttachedCallbackHelper.waitForCallback(0, 1, WAIT_TIMEOUT_MS,
48                 TimeUnit.MILLISECONDS);
49     }
50
51     @Feature({"AndroidWebView"})
52     @SmallTest
53     public void testGetVideoLoadingProgressView() throws Throwable {
54         TestAwContentsClient contentsClient =
55                 new FullScreenVideoTestAwContentsClient(
56                         getActivity(), isHardwareAcceleratedTest()) {
57                     @Override
58                     protected View getVideoLoadingProgressView() {
59                         View view = new View(getInstrumentation().getTargetContext());
60                         view.addOnAttachStateChangeListener(
61                                 AwContentsClientGetVideoLoadingProgressViewTest.this);
62                         return view;
63                     }
64                 };
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();
74     }
75 }