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 WebContentsObserver 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 TestWebContentsObserver extends WebContentsObserver {
26 private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = new CallbackHelper();
28 public TestWebContentsObserver(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 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking(
58 new Callable<TestWebContentsObserver>() {
60 public TestWebContentsObserver call() throws Exception {
61 return new TestWebContentsObserver(getContentViewCore().getWebContents());
65 int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().getCallCount();
66 getInstrumentation().runOnMainSync(new Runnable() {
69 getContentViewCore().getWebContents().getNavigationController()
70 .loadUrl(new LoadUrlParams(URL));
73 observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallback(callCount);