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.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
11 import org.chromium.base.test.util.UrlUtils; | 11 import org.chromium.base.test.util.UrlUtils; |
12 import org.chromium.content.browser.ContentViewCore.NavigationTransitionDelegate
; | |
13 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 12 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| 13 import org.chromium.content_public.browser.NavigationTransitionDelegate; |
14 import org.chromium.content_shell_apk.ContentShellActivity; | 14 import org.chromium.content_shell_apk.ContentShellActivity; |
15 import org.chromium.content_shell_apk.ContentShellTestBase; | 15 import org.chromium.content_shell_apk.ContentShellTestBase; |
16 import org.chromium.net.test.util.TestWebServer; | 16 import org.chromium.net.test.util.TestWebServer; |
17 | 17 |
18 import java.util.ArrayList; | 18 import java.util.ArrayList; |
19 import java.util.List; | 19 import java.util.List; |
20 import java.util.concurrent.TimeUnit; | 20 import java.util.concurrent.TimeUnit; |
21 | 21 |
22 /** | 22 /** |
23 * Test suite for navigation transition listeners. | 23 * Test suite for navigation transition listeners. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 * the transition is handled. | 103 * the transition is handled. |
104 */ | 104 */ |
105 @SmallTest | 105 @SmallTest |
106 public void testDidDeferAfterResponseStartedCalled() throws Throwable { | 106 public void testDidDeferAfterResponseStartedCalled() throws Throwable { |
107 ContentShellActivity activity = launchContentShellWithUrl(URL_1); | 107 ContentShellActivity activity = launchContentShellWithUrl(URL_1); |
108 waitForActiveShellToBeDoneLoading(); | 108 waitForActiveShellToBeDoneLoading(); |
109 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); | 109 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); |
110 TestCallbackHelperContainer testCallbackHelperContainer = | 110 TestCallbackHelperContainer testCallbackHelperContainer = |
111 new TestCallbackHelperContainer(contentViewCore); | 111 new TestCallbackHelperContainer(contentViewCore); |
112 | 112 |
113 contentViewCore.setHasPendingNavigationTransitionForTesting(); | 113 contentViewCore.getWebContents().setHasPendingNavigationTransitionForTes
ting(); |
114 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( | 114 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( |
115 contentViewCore, | 115 contentViewCore, |
116 true); | 116 true); |
117 contentViewCore.setNavigationTransitionDelegate(delegate); | 117 contentViewCore.getWebContents().setNavigationTransitionDelegate(delegat
e); |
118 | 118 |
119 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); | 119 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); |
120 | 120 |
121 assertTrue("didDeferAfterResponseStarted called.", delegate.getDidCallDe
fer()); | 121 assertTrue("didDeferAfterResponseStarted called.", delegate.getDidCallDe
fer()); |
122 } | 122 } |
123 | 123 |
124 /** | 124 /** |
125 * Tests that the listener does not receive DidDeferAfterResponseStarted if
we specify that | 125 * Tests that the listener does not receive DidDeferAfterResponseStarted if
we specify that |
126 * the transition is handled. | 126 * the transition is handled. |
127 */ | 127 */ |
128 @SmallTest | 128 @SmallTest |
129 public void testDidDeferAfterResponseStartedNotCalled() throws Throwable { | 129 public void testDidDeferAfterResponseStartedNotCalled() throws Throwable { |
130 ContentShellActivity activity = launchContentShellWithUrl(URL_1); | 130 ContentShellActivity activity = launchContentShellWithUrl(URL_1); |
131 waitForActiveShellToBeDoneLoading(); | 131 waitForActiveShellToBeDoneLoading(); |
132 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); | 132 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); |
133 TestCallbackHelperContainer testCallbackHelperContainer = | 133 TestCallbackHelperContainer testCallbackHelperContainer = |
134 new TestCallbackHelperContainer(contentViewCore); | 134 new TestCallbackHelperContainer(contentViewCore); |
135 | 135 |
136 contentViewCore.setHasPendingNavigationTransitionForTesting(); | 136 contentViewCore.getWebContents().setHasPendingNavigationTransitionForTes
ting(); |
137 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( | 137 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( |
138 contentViewCore, | 138 contentViewCore, |
139 false); | 139 false); |
140 contentViewCore.setNavigationTransitionDelegate(delegate); | 140 contentViewCore.getWebContents().setNavigationTransitionDelegate(delegat
e); |
141 | 141 |
142 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); | 142 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); |
143 | 143 |
144 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD
efer()); | 144 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD
efer()); |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Tests that the resource handler doesn't query the listener if no transiti
on is pending. | 148 * Tests that the resource handler doesn't query the listener if no transiti
on is pending. |
149 */ | 149 */ |
150 @SmallTest | 150 @SmallTest |
151 public void testWillHandleDeferAfterResponseStartedNotCalled() throws Throwa
ble { | 151 public void testWillHandleDeferAfterResponseStartedNotCalled() throws Throwa
ble { |
152 ContentShellActivity activity = launchContentShellWithUrl(URL_1); | 152 ContentShellActivity activity = launchContentShellWithUrl(URL_1); |
153 waitForActiveShellToBeDoneLoading(); | 153 waitForActiveShellToBeDoneLoading(); |
154 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); | 154 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); |
155 TestCallbackHelperContainer testCallbackHelperContainer = | 155 TestCallbackHelperContainer testCallbackHelperContainer = |
156 new TestCallbackHelperContainer(contentViewCore); | 156 new TestCallbackHelperContainer(contentViewCore); |
157 | 157 |
158 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( | 158 TestNavigationTransitionDelegate delegate = new TestNavigationTransition
Delegate( |
159 contentViewCore, | 159 contentViewCore, |
160 false); | 160 false); |
161 contentViewCore.setNavigationTransitionDelegate(delegate); | 161 contentViewCore.getWebContents().setNavigationTransitionDelegate(delegat
e); |
162 | 162 |
163 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); | 163 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams(
URL_1)); |
164 | 164 |
165 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD
efer()); | 165 assertFalse("didDeferAfterResponseStarted called.", delegate.getDidCallD
efer()); |
166 assertFalse("willHandleDeferAfterResponseStarted called.", | 166 assertFalse("willHandleDeferAfterResponseStarted called.", |
167 delegate.getDidCallWillHandlerDefer()); | 167 delegate.getDidCallWillHandlerDefer()); |
168 } | 168 } |
169 | 169 |
170 /** | 170 /** |
171 * Tests that the listener receives addStylesheetToTransition if we specify | 171 * Tests that the listener receives addStylesheetToTransition if we specify |
172 * that there are entering transition stylesheet. | 172 * that there are entering transition stylesheet. |
173 */ | 173 */ |
174 @SmallTest | 174 @SmallTest |
175 public void testAddStylesheetToTransitionCalled() throws Throwable { | 175 public void testAddStylesheetToTransitionCalled() throws Throwable { |
176 TestWebServer webServer = null; | 176 TestWebServer webServer = null; |
177 try { | 177 try { |
178 webServer = new TestWebServer(false); | 178 webServer = new TestWebServer(false); |
179 | 179 |
180 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); | 180 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); |
181 ContentShellActivity activity = launchContentShellWithUrl(url2); | 181 ContentShellActivity activity = launchContentShellWithUrl(url2); |
182 waitForActiveShellToBeDoneLoading(); | 182 waitForActiveShellToBeDoneLoading(); |
183 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); | 183 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); |
184 TestCallbackHelperContainer testCallbackHelperContainer = | 184 TestCallbackHelperContainer testCallbackHelperContainer = |
185 new TestCallbackHelperContainer(contentViewCore); | 185 new TestCallbackHelperContainer(contentViewCore); |
186 contentViewCore.setHasPendingNavigationTransitionForTesting(); | 186 contentViewCore.getWebContents().setHasPendingNavigationTransitionForT
esting(); |
187 TestNavigationTransitionDelegate delegate = | 187 TestNavigationTransitionDelegate delegate = |
188 new TestNavigationTransitionDelegate(contentViewCore, true); | 188 new TestNavigationTransitionDelegate(contentViewCore, true); |
189 contentViewCore.setNavigationTransitionDelegate(delegate); | 189 contentViewCore.getWebContents().setNavigationTransitionDelegate(deleg
ate); |
190 | 190 |
191 int currentCallCount = testCallbackHelperContainer | 191 int currentCallCount = testCallbackHelperContainer |
192 .getOnPageFinishedHelper().getCallCount(); | 192 .getOnPageFinishedHelper().getCallCount(); |
193 String[] headers = { | 193 String[] headers = { |
194 "link", | 194 "link", |
195 "<transition0.css>;rel=transition-entering-stylesheet;scope=*", | 195 "<transition0.css>;rel=transition-entering-stylesheet;scope=*", |
196 "link", | 196 "link", |
197 "<transition1.css>;rel=transition-entering-stylesheet;scope=*", | 197 "<transition1.css>;rel=transition-entering-stylesheet;scope=*", |
198 "link", | 198 "link", |
199 "<transition2.css>;rel=transition-entering-stylesheet;scope=*" | 199 "<transition2.css>;rel=transition-entering-stylesheet;scope=*" |
(...skipping 28 matching lines...) Expand all Loading... |
228 TestWebServer webServer = null; | 228 TestWebServer webServer = null; |
229 try { | 229 try { |
230 webServer = new TestWebServer(false); | 230 webServer = new TestWebServer(false); |
231 | 231 |
232 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); | 232 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); |
233 ContentShellActivity activity = launchContentShellWithUrl(url2); | 233 ContentShellActivity activity = launchContentShellWithUrl(url2); |
234 waitForActiveShellToBeDoneLoading(); | 234 waitForActiveShellToBeDoneLoading(); |
235 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); | 235 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); |
236 TestCallbackHelperContainer testCallbackHelperContainer = | 236 TestCallbackHelperContainer testCallbackHelperContainer = |
237 new TestCallbackHelperContainer(contentViewCore); | 237 new TestCallbackHelperContainer(contentViewCore); |
238 contentViewCore.setHasPendingNavigationTransitionForTesting(); | 238 contentViewCore.getWebContents().setHasPendingNavigationTransitionForT
esting(); |
239 TestNavigationTransitionDelegate delegate = | 239 TestNavigationTransitionDelegate delegate = |
240 new TestNavigationTransitionDelegate(contentViewCore, true); | 240 new TestNavigationTransitionDelegate(contentViewCore, true); |
241 contentViewCore.setNavigationTransitionDelegate(delegate); | 241 contentViewCore.getWebContents().setNavigationTransitionDelegate(deleg
ate); |
242 | 242 |
243 int currentCallCount = testCallbackHelperContainer | 243 int currentCallCount = testCallbackHelperContainer |
244 .getOnPageFinishedHelper().getCallCount(); | 244 .getOnPageFinishedHelper().getCallCount(); |
245 final String url3 = webServer.setResponse(URL_3, URL_3_DATA, null); | 245 final String url3 = webServer.setResponse(URL_3, URL_3_DATA, null); |
246 LoadUrlParams url3_params = new LoadUrlParams(url3); | 246 LoadUrlParams url3_params = new LoadUrlParams(url3); |
247 loadUrl(contentViewCore, testCallbackHelperContainer, url3_params); | 247 loadUrl(contentViewCore, testCallbackHelperContainer, url3_params); |
248 testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallback( | 248 testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallback( |
249 currentCallCount, | 249 currentCallCount, |
250 1, | 250 1, |
251 10000, | 251 10000, |
(...skipping 18 matching lines...) Expand all Loading... |
270 TestWebServer webServer = null; | 270 TestWebServer webServer = null; |
271 try { | 271 try { |
272 webServer = new TestWebServer(false); | 272 webServer = new TestWebServer(false); |
273 | 273 |
274 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); | 274 final String url2 = webServer.setResponse(URL_2, URL_2_DATA, null); |
275 ContentShellActivity activity = launchContentShellWithUrl(url2); | 275 ContentShellActivity activity = launchContentShellWithUrl(url2); |
276 waitForActiveShellToBeDoneLoading(); | 276 waitForActiveShellToBeDoneLoading(); |
277 ContentViewCore contentViewCore = activity.getActiveContentViewCore(
); | 277 ContentViewCore contentViewCore = activity.getActiveContentViewCore(
); |
278 TestCallbackHelperContainer testCallbackHelperContainer = | 278 TestCallbackHelperContainer testCallbackHelperContainer = |
279 new TestCallbackHelperContainer(contentViewCore); | 279 new TestCallbackHelperContainer(contentViewCore); |
280 contentViewCore.setHasPendingNavigationTransitionForTesting(); | 280 contentViewCore.getWebContents().setHasPendingNavigationTransitionFo
rTesting(); |
281 TestNavigationTransitionDelegate delegate = | 281 TestNavigationTransitionDelegate delegate = |
282 new TestNavigationTransitionDelegate(contentViewCore, true); | 282 new TestNavigationTransitionDelegate(contentViewCore, true); |
283 contentViewCore.setNavigationTransitionDelegate(delegate); | 283 contentViewCore.getWebContents().setNavigationTransitionDelegate(del
egate); |
284 | 284 |
285 String transitionEnteringColor = "#00FF00"; | 285 String transitionEnteringColor = "#00FF00"; |
286 | 286 |
287 int currentCallCount = testCallbackHelperContainer | 287 int currentCallCount = testCallbackHelperContainer |
288 .getOnPageFinishedHelper().getCallCount(); | 288 .getOnPageFinishedHelper().getCallCount(); |
289 String[] headers = { | 289 String[] headers = { |
290 "X-Transition-Entering-Color", | 290 "X-Transition-Entering-Color", |
291 transitionEnteringColor, | 291 transitionEnteringColor, |
292 }; | 292 }; |
293 final String url3 = webServer.setResponse(URL_3, | 293 final String url3 = webServer.setResponse(URL_3, |
294 URL_3_DATA, | 294 URL_3_DATA, |
295 createHeadersList(headers)); | 295 createHeadersList(headers)); |
296 LoadUrlParams url3Params = new LoadUrlParams(url3); | 296 LoadUrlParams url3Params = new LoadUrlParams(url3); |
297 loadUrl(contentViewCore, testCallbackHelperContainer, url3Params); | 297 loadUrl(contentViewCore, testCallbackHelperContainer, url3Params); |
298 testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallbac
k( | 298 testCallbackHelperContainer.getOnPageFinishedHelper().waitForCallbac
k( |
299 currentCallCount, | 299 currentCallCount, |
300 1, | 300 1, |
301 10000, | 301 10000, |
302 TimeUnit.MILLISECONDS); | 302 TimeUnit.MILLISECONDS); |
303 | 303 |
304 assertTrue("X-Transition-Entering-Color parsed correctly.", | 304 assertTrue("X-Transition-Entering-Color parsed correctly.", |
305 TextUtils.equals( | 305 TextUtils.equals( |
306 delegate.getTransitionEnteringColor(), | 306 delegate.getTransitionEnteringColor(), |
307 transitionEnteringColor)); | 307 transitionEnteringColor)); |
308 } finally { | 308 } finally { |
309 if (webServer != null) webServer.shutdown(); | 309 if (webServer != null) webServer.shutdown(); |
310 } | 310 } |
311 } | 311 } |
312 } | 312 } |
OLD | NEW |