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