OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/public/renderer/resource_fetcher.h" | 5 #include "content/public/renderer/resource_fetcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 fetcher->Start(frame, WebURLRequest::TargetIsMainFrame, | 258 fetcher->Start(frame, WebURLRequest::TargetIsMainFrame, |
259 delegate->NewCallback()); | 259 delegate->NewCallback()); |
260 | 260 |
261 delegate->WaitForResponse(); | 261 delegate->WaitForResponse(); |
262 ASSERT_TRUE(delegate->completed()); | 262 ASSERT_TRUE(delegate->completed()); |
263 EXPECT_EQ(delegate->response().httpStatusCode(), 200); | 263 EXPECT_EQ(delegate->response().httpStatusCode(), 200); |
264 EXPECT_EQ(kHeader, delegate->data()); | 264 EXPECT_EQ(kHeader, delegate->data()); |
265 } | 265 } |
266 }; | 266 }; |
267 | 267 |
268 #if defined(OS_ANDROID) | |
269 // Disable (http://crbug.com/248796). | |
270 #define MAYBE_ResourceFetcher404 DISABLED_ResourceFetcher404 | |
271 #define MAYBE_ResourceFetcherDeletedInCallback \ | |
272 DISABLED_ResourceFetcherDeletedInCallback | |
273 #define MAYBE_ResourceFetcherTimeout DISABLED_ResourceFetcherTimeout | |
274 #define MAYBE_ResourceFetcherDownload DISABLED_ResourceFetcherDownload | |
275 // Disable (http://crbug.com/341142). | |
mmenke
2014/02/06 03:17:27
nit: I duped this against the other bug, so you c
| |
276 #define MAYBE_ResourceFetcherPost DISABLED_ResourceFetcherPost | |
277 #define MAYBE_ResourceFetcherSetHeader DISABLED_ResourceFetcherSetHeader | |
278 #else | |
279 #define MAYBE_ResourceFetcher404 ResourceFetcher404 | |
280 #define MAYBE_ResourceFetcherDeletedInCallback ResourceFetcherDeletedInCallback | |
281 #define MAYBE_ResourceFetcherTimeout ResourceFetcherTimeout | |
282 #define MAYBE_ResourceFetcherDownload ResourceFetcherDownload | |
283 #define MAYBE_ResourceFetcherPost ResourceFetcherPost | |
284 #define MAYBE_ResourceFetcherSetHeader ResourceFetcherSetHeader | |
285 #endif | |
286 | |
268 // Test a fetch from the test server. | 287 // Test a fetch from the test server. |
269 // If this flakes, use http://crbug.com/51622. | 288 // If this flakes, use http://crbug.com/51622. |
270 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { | 289 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, MAYBE_ResourceFetcherDownload) { |
271 // Need to spin up the renderer. | 290 // Need to spin up the renderer. |
272 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 291 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
273 | 292 |
274 ASSERT_TRUE(test_server()->Start()); | 293 ASSERT_TRUE(test_server()->Start()); |
275 GURL url(test_server()->GetURL("files/simple_page.html")); | 294 GURL url(test_server()->GetURL("files/simple_page.html")); |
276 | 295 |
277 PostTaskToInProcessRendererAndWait( | 296 PostTaskToInProcessRendererAndWait( |
278 base::Bind(&ResourceFetcherTests::ResourceFetcherDownloadOnRenderer, | 297 base::Bind(&ResourceFetcherTests::ResourceFetcherDownloadOnRenderer, |
279 base::Unretained(this), url)); | 298 base::Unretained(this), url)); |
280 } | 299 } |
281 | 300 |
282 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcher404) { | 301 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, MAYBE_ResourceFetcher404) { |
283 // Need to spin up the renderer. | 302 // Need to spin up the renderer. |
284 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 303 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
285 | 304 |
286 // Test 404 response. | 305 // Test 404 response. |
287 ASSERT_TRUE(test_server()->Start()); | 306 ASSERT_TRUE(test_server()->Start()); |
288 GURL url = test_server()->GetURL("files/thisfiledoesntexist.html"); | 307 GURL url = test_server()->GetURL("files/thisfiledoesntexist.html"); |
289 | 308 |
290 PostTaskToInProcessRendererAndWait( | 309 PostTaskToInProcessRendererAndWait( |
291 base::Bind(&ResourceFetcherTests::ResourceFetcher404OnRenderer, | 310 base::Bind(&ResourceFetcherTests::ResourceFetcher404OnRenderer, |
292 base::Unretained(this), url)); | 311 base::Unretained(this), url)); |
293 } | 312 } |
294 | 313 |
295 // If this flakes, use http://crbug.com/51622. | 314 // If this flakes, use http://crbug.com/51622. |
296 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { | 315 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { |
297 // Need to spin up the renderer. | 316 // Need to spin up the renderer. |
298 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 317 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
299 | 318 |
300 PostTaskToInProcessRendererAndWait( | 319 PostTaskToInProcessRendererAndWait( |
301 base::Bind(&ResourceFetcherTests::ResourceFetcherDidFailOnRenderer, | 320 base::Bind(&ResourceFetcherTests::ResourceFetcherDidFailOnRenderer, |
302 base::Unretained(this))); | 321 base::Unretained(this))); |
303 } | 322 } |
304 | 323 |
305 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { | 324 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, MAYBE_ResourceFetcherTimeout) { |
306 // Need to spin up the renderer. | 325 // Need to spin up the renderer. |
307 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 326 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
308 | 327 |
309 // Grab a page that takes at least 1 sec to respond, but set the fetcher to | 328 // Grab a page that takes at least 1 sec to respond, but set the fetcher to |
310 // timeout in 0 sec. | 329 // timeout in 0 sec. |
311 ASSERT_TRUE(test_server()->Start()); | 330 ASSERT_TRUE(test_server()->Start()); |
312 GURL url(test_server()->GetURL("slow?1")); | 331 GURL url(test_server()->GetURL("slow?1")); |
313 | 332 |
314 PostTaskToInProcessRendererAndWait( | 333 PostTaskToInProcessRendererAndWait( |
315 base::Bind(&ResourceFetcherTests::ResourceFetcherTimeoutOnRenderer, | 334 base::Bind(&ResourceFetcherTests::ResourceFetcherTimeoutOnRenderer, |
316 base::Unretained(this), url)); | 335 base::Unretained(this), url)); |
317 } | 336 } |
318 | 337 |
319 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherDeletedInCallback) { | 338 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, |
339 MAYBE_ResourceFetcherDeletedInCallback) { | |
320 // Need to spin up the renderer. | 340 // Need to spin up the renderer. |
321 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 341 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
322 | 342 |
323 // Grab a page that takes at least 1 sec to respond, but set the fetcher to | 343 // Grab a page that takes at least 1 sec to respond, but set the fetcher to |
324 // timeout in 0 sec. | 344 // timeout in 0 sec. |
325 ASSERT_TRUE(test_server()->Start()); | 345 ASSERT_TRUE(test_server()->Start()); |
326 GURL url(test_server()->GetURL("slow?1")); | 346 GURL url(test_server()->GetURL("slow?1")); |
327 | 347 |
328 PostTaskToInProcessRendererAndWait( | 348 PostTaskToInProcessRendererAndWait( |
329 base::Bind( | 349 base::Bind( |
330 &ResourceFetcherTests::ResourceFetcherDeletedInCallbackOnRenderer, | 350 &ResourceFetcherTests::ResourceFetcherDeletedInCallbackOnRenderer, |
331 base::Unretained(this), url)); | 351 base::Unretained(this), url)); |
332 } | 352 } |
333 | 353 |
354 | |
355 | |
334 // Test that ResourceFetchers can handle POSTs. | 356 // Test that ResourceFetchers can handle POSTs. |
335 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherPost) { | 357 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, MAYBE_ResourceFetcherPost) { |
336 // Need to spin up the renderer. | 358 // Need to spin up the renderer. |
337 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 359 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
338 | 360 |
339 // Grab a page that echos the POST body. | 361 // Grab a page that echos the POST body. |
340 ASSERT_TRUE(test_server()->Start()); | 362 ASSERT_TRUE(test_server()->Start()); |
341 GURL url(test_server()->GetURL("echo")); | 363 GURL url(test_server()->GetURL("echo")); |
342 | 364 |
343 PostTaskToInProcessRendererAndWait( | 365 PostTaskToInProcessRendererAndWait( |
344 base::Bind( | 366 base::Bind( |
345 &ResourceFetcherTests::ResourceFetcherPost, | 367 &ResourceFetcherTests::ResourceFetcherPost, |
346 base::Unretained(this), url)); | 368 base::Unretained(this), url)); |
347 } | 369 } |
348 | 370 |
349 // Test that ResourceFetchers can set headers. | 371 // Test that ResourceFetchers can set headers. |
350 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, ResourceFetcherSetHeader) { | 372 IN_PROC_BROWSER_TEST_F(ResourceFetcherTests, MAYBE_ResourceFetcherSetHeader) { |
351 // Need to spin up the renderer. | 373 // Need to spin up the renderer. |
352 NavigateToURL(shell(), GURL(kAboutBlankURL)); | 374 NavigateToURL(shell(), GURL(kAboutBlankURL)); |
353 | 375 |
354 // Grab a page that echos the POST body. | 376 // Grab a page that echos the POST body. |
355 ASSERT_TRUE(test_server()->Start()); | 377 ASSERT_TRUE(test_server()->Start()); |
356 GURL url(test_server()->GetURL("echoheader?header")); | 378 GURL url(test_server()->GetURL("echoheader?header")); |
357 | 379 |
358 PostTaskToInProcessRendererAndWait( | 380 PostTaskToInProcessRendererAndWait( |
359 base::Bind( | 381 base::Bind( |
360 &ResourceFetcherTests::ResourceFetcherSetHeader, | 382 &ResourceFetcherTests::ResourceFetcherSetHeader, |
361 base::Unretained(this), url)); | 383 base::Unretained(this), url)); |
362 } | 384 } |
363 | 385 |
364 } // namespace content | 386 } // namespace content |
OLD | NEW |