OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.filters.LargeTest; | 7 import android.support.test.filters.LargeTest; |
8 | 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 |
9 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.BaseJUnit4ClassRunner; |
10 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
11 import org.chromium.base.test.util.RetryOnFailure; | 18 import org.chromium.base.test.util.RetryOnFailure; |
12 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
13 import org.chromium.content.browser.test.util.Criteria; | 20 import org.chromium.content.browser.test.util.Criteria; |
14 import org.chromium.content.browser.test.util.CriteriaHelper; | 21 import org.chromium.content.browser.test.util.CriteriaHelper; |
15 import org.chromium.content.browser.test.util.TouchCommon; | 22 import org.chromium.content.browser.test.util.TouchCommon; |
16 import org.chromium.content_public.browser.WebContents; | 23 import org.chromium.content_public.browser.WebContents; |
17 import org.chromium.content_public.browser.WebContentsObserver; | 24 import org.chromium.content_public.browser.WebContentsObserver; |
18 import org.chromium.content_shell_apk.ContentShellActivity; | 25 import org.chromium.content_shell_apk.ContentShellActivity; |
19 import org.chromium.content_shell_apk.ContentShellTestBase; | 26 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
20 | 27 |
21 import java.util.concurrent.Callable; | 28 import java.util.concurrent.Callable; |
22 import java.util.concurrent.ExecutionException; | 29 import java.util.concurrent.ExecutionException; |
23 | 30 |
24 /** | 31 /** |
25 * Tests for interstitial pages. | 32 * Tests for interstitial pages. |
26 */ | 33 */ |
27 public class InterstitialPageTest extends ContentShellTestBase { | 34 @RunWith(BaseJUnit4ClassRunner.class) |
| 35 public class InterstitialPageTest { |
| 36 @Rule |
| 37 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
28 | 38 |
29 private static final String URL = UrlUtils.encodeHtmlDataUri( | 39 private static final String URL = UrlUtils.encodeHtmlDataUri( |
30 "<html><head></head><body>test</body></html>"); | 40 "<html><head></head><body>test</body></html>"); |
31 | 41 |
32 private static class TestWebContentsObserver extends WebContentsObserver { | 42 private static class TestWebContentsObserver extends WebContentsObserver { |
33 private boolean mInterstitialShowing; | 43 private boolean mInterstitialShowing; |
34 | 44 |
35 public TestWebContentsObserver(WebContents webContents) { | 45 public TestWebContentsObserver(WebContents webContents) { |
36 super(webContents); | 46 super(webContents); |
37 } | 47 } |
(...skipping 11 matching lines...) Expand all Loading... |
49 public void didAttachInterstitialPage() { | 59 public void didAttachInterstitialPage() { |
50 mInterstitialShowing = true; | 60 mInterstitialShowing = true; |
51 } | 61 } |
52 | 62 |
53 @Override | 63 @Override |
54 public void didDetachInterstitialPage() { | 64 public void didDetachInterstitialPage() { |
55 mInterstitialShowing = false; | 65 mInterstitialShowing = false; |
56 } | 66 } |
57 } | 67 } |
58 | 68 |
59 @Override | 69 @Before |
60 protected void setUp() throws Exception { | 70 public void setUp() throws Exception { |
61 super.setUp(); | 71 ContentShellActivity activity = mActivityTestRule.launchContentShellWith
Url(URL); |
62 ContentShellActivity activity = launchContentShellWithUrl(URL); | 72 Assert.assertNotNull(activity); |
63 assertNotNull(activity); | 73 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
64 waitForActiveShellToBeDoneLoading(); | |
65 } | 74 } |
66 | 75 |
67 private void waitForInterstitial(final boolean shouldBeShown) { | 76 private void waitForInterstitial(final boolean shouldBeShown) { |
68 CriteriaHelper.pollUiThread( | 77 CriteriaHelper.pollUiThread( |
69 Criteria.equals(shouldBeShown, new Callable<Boolean>() { | 78 Criteria.equals(shouldBeShown, new Callable<Boolean>() { |
70 @Override | 79 @Override |
71 public Boolean call() { | 80 public Boolean call() { |
72 return getWebContents().isShowingInterstitialPage(); | 81 return mActivityTestRule.getWebContents().isShowingInter
stitialPage(); |
73 } | 82 } |
74 })); | 83 })); |
75 } | 84 } |
76 | 85 |
77 /** | 86 /** |
78 * Tests that showing and hiding an interstitial works. | 87 * Tests that showing and hiding an interstitial works. |
79 */ | 88 */ |
| 89 @Test |
80 @LargeTest | 90 @LargeTest |
81 @Feature({"Navigation"}) | 91 @Feature({"Navigation"}) |
82 @RetryOnFailure | 92 @RetryOnFailure |
83 public void testCloseInterstitial() throws ExecutionException { | 93 public void testCloseInterstitial() throws ExecutionException { |
84 final String proceedCommand = "PROCEED"; | 94 final String proceedCommand = "PROCEED"; |
85 final String htmlContent = "<html>" | 95 final String htmlContent = "<html>" |
86 + "<head>" | 96 + "<head>" |
87 + " <script>" | 97 + " <script>" |
88 + " function sendCommand(command) {" | 98 + " function sendCommand(command) {" |
89 + " window.domAutomationController.setAutomationId(1);" | 99 + " window.domAutomationController.setAutomationId(1);" |
90 + " window.domAutomationController.send(command);" | 100 + " window.domAutomationController.send(command);" |
91 + " }" | 101 + " }" |
92 + " </script>" | 102 + " </script>" |
93 + "</head>" | 103 + "</head>" |
94 + "<body style='background-color:#FF0000' " | 104 + "<body style='background-color:#FF0000' " |
95 + " onclick='sendCommand(\"" + proceedCommand + "\");'>" | 105 + " onclick='sendCommand(\"" + proceedCommand + "\");'>" |
96 + " <h1>This is a scary interstitial page</h1>" | 106 + " <h1>This is a scary interstitial page</h1>" |
97 + "</body>" | 107 + "</body>" |
98 + "</html>"; | 108 + "</html>"; |
99 final InterstitialPageDelegateAndroid delegate = | 109 final InterstitialPageDelegateAndroid delegate = |
100 new InterstitialPageDelegateAndroid(htmlContent) { | 110 new InterstitialPageDelegateAndroid(htmlContent) { |
101 @Override | 111 @Override |
102 protected void commandReceived(String command) { | 112 protected void commandReceived(String command) { |
103 assertEquals(command, proceedCommand); | 113 Assert.assertEquals(command, proceedCommand); |
104 proceed(); | 114 proceed(); |
105 } | 115 } |
106 }; | 116 }; |
107 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking( | 117 TestWebContentsObserver observer = ThreadUtils.runOnUiThreadBlocking( |
108 new Callable<TestWebContentsObserver>() { | 118 new Callable<TestWebContentsObserver>() { |
109 @Override | 119 @Override |
110 public TestWebContentsObserver call() throws Exception { | 120 public TestWebContentsObserver call() throws Exception { |
111 getWebContents().showInterstitialPage(URL, delegate.getN
ative()); | 121 mActivityTestRule.getWebContents().showInterstitialPage( |
112 return new TestWebContentsObserver(getWebContents()); | 122 URL, delegate.getNative()); |
| 123 return new TestWebContentsObserver(mActivityTestRule.get
WebContents()); |
113 } | 124 } |
114 }); | 125 }); |
115 | 126 |
116 waitForInterstitial(true); | 127 waitForInterstitial(true); |
117 assertTrue("WebContentsObserver not notified of interstitial showing", | 128 Assert.assertTrue("WebContentsObserver not notified of interstitial show
ing", |
118 observer.isInterstitialShowing()); | 129 observer.isInterstitialShowing()); |
119 TouchCommon.singleClickView(getContentViewCore().getContainerView(), 10,
10); | 130 TouchCommon.singleClickView( |
| 131 mActivityTestRule.getContentViewCore().getContainerView(), 10, 1
0); |
120 waitForInterstitial(false); | 132 waitForInterstitial(false); |
121 assertTrue("WebContentsObserver not notified of interstitial hiding", | 133 Assert.assertTrue("WebContentsObserver not notified of interstitial hidi
ng", |
122 !observer.isInterstitialShowing()); | 134 !observer.isInterstitialShowing()); |
123 } | 135 } |
124 } | 136 } |
OLD | NEW |