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
5package org.chromium.content.browser;
6
7import org.chromium.base.ThreadUtils;
8import org.chromium.base.test.util.DisabledTest;
9import org.chromium.base.test.util.UrlUtils;
10import org.chromium.content.browser.test.util.CallbackHelper;
11import org.chromium.content_public.browser.LoadUrlParams;
12import org.chromium.content_public.browser.WebContents;
13import org.chromium.content_shell_apk.ContentShellActivity;
14import org.chromium.content_shell_apk.ContentShellTestBase;
15
16import java.util.concurrent.Callable;
17
18/**
19 * Tests for the WebContentsObserverAndroid APIs.
20 */
21public 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 TestWebContentsObserverAndroid extends WebContentsObserverAndroid {
26        private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = new CallbackHelper();
27
28        public TestWebContentsObserverAndroid(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        TestWebContentsObserverAndroid observer = ThreadUtils.runOnUiThreadBlocking(
58                new Callable<TestWebContentsObserverAndroid>() {
59                    @Override
60                    public TestWebContentsObserverAndroid call() throws Exception {
61                        return new TestWebContentsObserverAndroid(
62                                getContentViewCore().getWebContents());
63                    }
64                });
65
66        int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().getCallCount();
67        getInstrumentation().runOnMainSync(new Runnable() {
68            @Override
69            public void run() {
70                getContentViewCore().getWebContents().getNavigationController()
71                        .loadUrl(new LoadUrlParams(URL));
72            }
73        });
74        observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallback(callCount);
75    }
76}
77