| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.support.test.InstrumentationRegistry; |
| 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Before; |
| 11 import org.junit.Rule; |
| 12 import org.junit.Test; |
| 13 import org.junit.runner.RunWith; |
| 14 |
| 7 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 8 import org.chromium.base.test.util.CallbackHelper; | 17 import org.chromium.base.test.util.CallbackHelper; |
| 9 import org.chromium.base.test.util.DisabledTest; | 18 import org.chromium.base.test.util.DisabledTest; |
| 10 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
| 11 import org.chromium.content_public.browser.LoadUrlParams; | 20 import org.chromium.content_public.browser.LoadUrlParams; |
| 12 import org.chromium.content_public.browser.WebContents; | 21 import org.chromium.content_public.browser.WebContents; |
| 13 import org.chromium.content_public.browser.WebContentsObserver; | 22 import org.chromium.content_public.browser.WebContentsObserver; |
| 14 import org.chromium.content_shell_apk.ContentShellActivity; | 23 import org.chromium.content_shell_apk.ContentShellActivity; |
| 15 import org.chromium.content_shell_apk.ContentShellTestBase; | 24 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 16 | 25 |
| 17 import java.util.concurrent.Callable; | 26 import java.util.concurrent.Callable; |
| 18 | 27 |
| 19 /** | 28 /** |
| 20 * Tests for the WebContentsObserver APIs. | 29 * Tests for the WebContentsObserver APIs. |
| 21 */ | 30 */ |
| 22 public class WebContentsObserverAndroidTest extends ContentShellTestBase { | 31 @RunWith(BaseJUnit4ClassRunner.class) |
| 32 public class WebContentsObserverAndroidTest { |
| 33 @Rule |
| 34 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 35 |
| 23 private static final String URL = UrlUtils.encodeHtmlDataUri( | 36 private static final String URL = UrlUtils.encodeHtmlDataUri( |
| 24 "<html><head></head><body>didFirstVisuallyNonEmptyPaint test</body><
/html>"); | 37 "<html><head></head><body>didFirstVisuallyNonEmptyPaint test</body><
/html>"); |
| 25 | 38 |
| 26 private static class TestWebContentsObserver extends WebContentsObserver { | 39 private static class TestWebContentsObserver extends WebContentsObserver { |
| 27 private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = ne
w CallbackHelper(); | 40 private CallbackHelper mDidFirstVisuallyNonEmptyPaintCallbackHelper = ne
w CallbackHelper(); |
| 28 | 41 |
| 29 public TestWebContentsObserver(WebContents webContents) { | 42 public TestWebContentsObserver(WebContents webContents) { |
| 30 super(webContents); | 43 super(webContents); |
| 31 } | 44 } |
| 32 | 45 |
| 33 public CallbackHelper getDidFirstVisuallyNonEmptyPaintCallbackHelper() { | 46 public CallbackHelper getDidFirstVisuallyNonEmptyPaintCallbackHelper() { |
| 34 return mDidFirstVisuallyNonEmptyPaintCallbackHelper; | 47 return mDidFirstVisuallyNonEmptyPaintCallbackHelper; |
| 35 } | 48 } |
| 36 | 49 |
| 37 @Override | 50 @Override |
| 38 public void didFirstVisuallyNonEmptyPaint() { | 51 public void didFirstVisuallyNonEmptyPaint() { |
| 39 mDidFirstVisuallyNonEmptyPaintCallbackHelper.notifyCalled(); | 52 mDidFirstVisuallyNonEmptyPaintCallbackHelper.notifyCalled(); |
| 40 } | 53 } |
| 41 } | 54 } |
| 42 | 55 |
| 43 @Override | 56 @Before |
| 44 protected void setUp() throws Exception { | 57 public void setUp() throws Exception { |
| 45 super.setUp(); | 58 ContentShellActivity activity = mActivityTestRule.launchContentShellWith
Url(null); |
| 46 ContentShellActivity activity = launchContentShellWithUrl(null); | 59 Assert.assertNotNull(activity); |
| 47 assertNotNull(activity); | 60 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 48 waitForActiveShellToBeDoneLoading(); | |
| 49 } | 61 } |
| 50 | 62 |
| 51 /* | 63 /* |
| 52 @SmallTest | 64 @SmallTest |
| 53 @Feature({"Navigation"}) | 65 @Feature({"Navigation"}) |
| 54 */ | 66 */ |
| 67 @Test |
| 55 @DisabledTest(message = "crbug.com/411931") | 68 @DisabledTest(message = "crbug.com/411931") |
| 56 public void testDidFirstVisuallyNonEmptyPaint() throws Throwable { | 69 public void testDidFirstVisuallyNonEmptyPaint() throws Throwable { |
| 57 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking( | 70 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking( |
| 58 new Callable<TestWebContentsObserver>() { | 71 new Callable<TestWebContentsObserver>() { |
| 59 @Override | 72 @Override |
| 60 public TestWebContentsObserver call() throws Exception { | 73 public TestWebContentsObserver call() throws Exception { |
| 61 return new TestWebContentsObserver(getContentViewCore().
getWebContents()); | 74 return new TestWebContentsObserver( |
| 75 mActivityTestRule.getContentViewCore().getWebCon
tents()); |
| 62 } | 76 } |
| 63 }); | 77 }); |
| 64 | 78 |
| 65 int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper(
).getCallCount(); | 79 int callCount = observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper(
).getCallCount(); |
| 66 getInstrumentation().runOnMainSync(new Runnable() { | 80 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { |
| 67 @Override | 81 @Override |
| 68 public void run() { | 82 public void run() { |
| 69 getContentViewCore().getWebContents().getNavigationController() | 83 mActivityTestRule.getContentViewCore() |
| 84 .getWebContents() |
| 85 .getNavigationController() |
| 70 .loadUrl(new LoadUrlParams(URL)); | 86 .loadUrl(new LoadUrlParams(URL)); |
| 71 } | 87 } |
| 72 }); | 88 }); |
| 73 observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallbac
k(callCount); | 89 observer.getDidFirstVisuallyNonEmptyPaintCallbackHelper().waitForCallbac
k(callCount); |
| 74 } | 90 } |
| 75 } | 91 } |
| OLD | NEW |