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 android.test.suitebuilder.annotation.SmallTest;
9 import org.chromium.base.ThreadUtils;
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.UrlUtils;
12 import org.chromium.content.browser.test.util.CallbackHelper;
13 import org.chromium.content_public.browser.WebContents;
14 import org.chromium.content_shell_apk.ContentShellActivity;
15 import org.chromium.content_shell_apk.ContentShellTestBase;
17 import java.util.concurrent.Callable;
20 * Tests for the WebContentsObserverAndroid APIs.
22 public class WebContentsObserverAndroidTest extends ContentShellTestBase {
23 private static final String URL = UrlUtils.encodeHtmlDataUri(
24 "<html><head></head><body>didFirstVisuallyNonEmptyPaint test</body></html>");
26 private static class TestWebContentsObserverAndroid extends WebContentsObserverAndroid {
27 private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = new CallbackHelper();
29 public TestWebContentsObserverAndroid(WebContents webContents) {
33 public CallbackHelper getDidFirstVisuallyNonEmptyPaintCallbackHelper() {
34 return mDidFirstVisuallyNonEmptyPaintCallbackHelper;
38 public void didFirstVisuallyNonEmptyPaint() {
39 mDidFirstVisuallyNonEmptyPaintCallbackHelper.notifyCalled();
44 protected void setUp() throws Exception {
46 ContentShellActivity activity = launchContentShellWithUrl(null);
47 assertNotNull(activity);
48 waitForActiveShellToBeDoneLoading();
52 @Feature({"Navigation"})
53 public void testDidFirstVisuallyNonEmptyPaint() throws Throwable {
54 TestWebContentsObserverAndroid observer = ThreadUtils.runOnUiThreadBlocking(
55 new Callable<TestWebContentsObserverAndroid>() {
57 public TestWebContentsObserverAndroid call() throws Exception {
58 return new TestWebContentsObserverAndroid(
59 getContentViewCore().getWebContents());
63 int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().getCallCount();
64 getInstrumentation().runOnMainSync(new Runnable() {
67 getContentViewCore().loadUrl(new LoadUrlParams(URL));
70 observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallback(callCount);