Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / WebContentsObserverAndroidTest.java
1 // Copyright 2014 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.content.browser;
6
7 import org.chromium.base.ThreadUtils;
8 import org.chromium.base.test.util.DisabledTest;
9 import org.chromium.base.test.util.UrlUtils;
10 import org.chromium.content.browser.test.util.CallbackHelper;
11 import org.chromium.content_public.browser.LoadUrlParams;
12 import org.chromium.content_public.browser.WebContents;
13 import org.chromium.content_shell_apk.ContentShellActivity;
14 import org.chromium.content_shell_apk.ContentShellTestBase;
15
16 import java.util.concurrent.Callable;
17
18 /**
19  * Tests for the WebContentsObserver APIs.
20  */
21 public class WebContentsObserverAndroidTest extends ContentShellTestBase {
22     private static final String URL = UrlUtils.encodeHtmlDataUri(
23             "<html><head></head><body>didFirstVisuallyNonEmptyPaint test</body></html>");
24
25     private static class TestWebContentsObserver extends WebContentsObserver {
26         private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = new CallbackHelper();
27
28         public TestWebContentsObserver(WebContents webContents) {
29             super(webContents);
30         }
31
32         public CallbackHelper getDidFirstVisuallyNonEmptyPaintCallbackHelper() {
33             return mDidFirstVisuallyNonEmptyPaintCallbackHelper;
34         }
35
36         @Override
37         public void didFirstVisuallyNonEmptyPaint() {
38             mDidFirstVisuallyNonEmptyPaintCallbackHelper.notifyCalled();
39         }
40     }
41
42     @Override
43     protected void setUp() throws Exception {
44         super.setUp();
45         ContentShellActivity activity = launchContentShellWithUrl(null);
46         assertNotNull(activity);
47         waitForActiveShellToBeDoneLoading();
48     }
49
50     /*
51     @SmallTest
52     @Feature({"Navigation"})
53     http://crbug.com/411931
54     */
55     @DisabledTest
56     public void testDidFirstVisuallyNonEmptyPaint() throws Throwable {
57         TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking(
58                 new Callable<TestWebContentsObserver>() {
59                     @Override
60                     public TestWebContentsObserver call() throws Exception {
61                         return new TestWebContentsObserver(getContentViewCore().getWebContents());
62                     }
63                 });
64
65         int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().getCallCount();
66         getInstrumentation().runOnMainSync(new Runnable() {
67             @Override
68             public void run() {
69                 getContentViewCore().getWebContents().getNavigationController()
70                         .loadUrl(new LoadUrlParams(URL));
71             }
72         });
73         observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallback(callCount);
74     }
75 }