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.
5 package org.chromium.content.browser;
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;
16 import java.util.concurrent.Callable;
19 * Tests for the WebContentsObserverAndroid APIs.
21 public class WebContentsObserverAndroidTest extends ContentShellTestBase {
22 private static final String URL = UrlUtils.encodeHtmlDataUri(
23 "<html><head></head><body>didFirstVisuallyNonEmptyPaint test</body></html>");
25 private static class TestWebContentsObserverAndroid extends WebContentsObserverAndroid {
26 private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = new CallbackHelper();
28 public TestWebContentsObserverAndroid(WebContents webContents) {
32 public CallbackHelper getDidFirstVisuallyNonEmptyPaintCallbackHelper() {
33 return mDidFirstVisuallyNonEmptyPaintCallbackHelper;
37 public void didFirstVisuallyNonEmptyPaint() {
38 mDidFirstVisuallyNonEmptyPaintCallbackHelper.notifyCalled();
43 protected void setUp() throws Exception {
45 ContentShellActivity activity = launchContentShellWithUrl(null);
46 assertNotNull(activity);
47 waitForActiveShellToBeDoneLoading();
52 @Feature({"Navigation"})
53 http://crbug.com/411931
56 public void testDidFirstVisuallyNonEmptyPaint() throws Throwable {
57 TestWebContentsObserverAndroid observer = ThreadUtils.runOnUiThreadBlocking(
58 new Callable<TestWebContentsObserverAndroid>() {
60 public TestWebContentsObserverAndroid call() throws Exception {
61 return new TestWebContentsObserverAndroid(
62 getContentViewCore().getWebContents());
66 int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().getCallCount();
67 getInstrumentation().runOnMainSync(new Runnable() {
70 getContentViewCore().getWebContents().getNavigationController()
71 .loadUrl(new LoadUrlParams(URL));
74 observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallback(callCount);