Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 2838293002: Ensure all content_browsertests call the host resolver in SetUpOnMainThread and not after. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <utility> 10 #include <utility>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 class NetLogWithSource; 83 class NetLogWithSource;
84 } 84 }
85 85
86 namespace content { 86 namespace content {
87 87
88 namespace { 88 namespace {
89 89
90 // Default request count for parallel download tests. 90 // Default request count for parallel download tests.
91 constexpr int kTestRequestCount = 3; 91 constexpr int kTestRequestCount = 3;
92 92
93 const std::string kOriginOne = "one.example";
94 const std::string kOriginTwo = "two.example";
95
93 class MockDownloadItemObserver : public DownloadItem::Observer { 96 class MockDownloadItemObserver : public DownloadItem::Observer {
94 public: 97 public:
95 MockDownloadItemObserver() {} 98 MockDownloadItemObserver() {}
96 virtual ~MockDownloadItemObserver() {} 99 virtual ~MockDownloadItemObserver() {}
97 100
98 MOCK_METHOD1(OnDownloadUpdated, void(DownloadItem*)); 101 MOCK_METHOD1(OnDownloadUpdated, void(DownloadItem*));
99 MOCK_METHOD1(OnDownloadOpened, void(DownloadItem*)); 102 MOCK_METHOD1(OnDownloadOpened, void(DownloadItem*));
100 MOCK_METHOD1(OnDownloadRemoved, void(DownloadItem*)); 103 MOCK_METHOD1(OnDownloadRemoved, void(DownloadItem*));
101 MOCK_METHOD1(OnDownloadDestroyed, void(DownloadItem*)); 104 MOCK_METHOD1(OnDownloadDestroyed, void(DownloadItem*));
102 }; 105 };
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 591
589 BrowserThread::PostTask( 592 BrowserThread::PostTask(
590 BrowserThread::IO, FROM_HERE, 593 BrowserThread::IO, FROM_HERE,
591 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler)); 594 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler));
592 base::FilePath mock_base(GetTestFilePath("download", "")); 595 base::FilePath mock_base(GetTestFilePath("download", ""));
593 BrowserThread::PostTask( 596 BrowserThread::PostTask(
594 BrowserThread::IO, FROM_HERE, 597 BrowserThread::IO, FROM_HERE,
595 base::Bind( 598 base::Bind(
596 &net::URLRequestMockHTTPJob::AddUrlHandlers, mock_base, 599 &net::URLRequestMockHTTPJob::AddUrlHandlers, mock_base,
597 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); 600 make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
601 ASSERT_TRUE(embedded_test_server()->Start());
602 const std::string real_host =
603 embedded_test_server()->host_port_pair().host();
604 host_resolver()->AddRule(kOriginOne, real_host);
605 host_resolver()->AddRule(kOriginTwo, real_host);
598 } 606 }
599 607
600 void SetUpCommandLine(base::CommandLine* command_line) override { 608 void SetUpCommandLine(base::CommandLine* command_line) override {
601 IsolateAllSitesForTesting(command_line); 609 IsolateAllSitesForTesting(command_line);
602 } 610 }
603 611
604 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() { 612 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() {
605 return test_delegate_.get(); 613 return test_delegate_.get();
606 } 614 }
607 615
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2295 } 2303 }
2296 2304
2297 // Test that the referrer header is set correctly for a download that's resumed 2305 // Test that the referrer header is set correctly for a download that's resumed
2298 // partially. 2306 // partially.
2299 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) { 2307 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) {
2300 TestDownloadRequestHandler request_handler; 2308 TestDownloadRequestHandler request_handler;
2301 TestDownloadRequestHandler::Parameters parameters = 2309 TestDownloadRequestHandler::Parameters parameters =
2302 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); 2310 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
2303 request_handler.StartServing(parameters); 2311 request_handler.StartServing(parameters);
2304 2312
2305 ASSERT_TRUE(embedded_test_server()->Start());
2306 GURL document_url = embedded_test_server()->GetURL( 2313 GURL document_url = embedded_test_server()->GetURL(
2307 std::string("/download/download-link.html?dl=") 2314 std::string("/download/download-link.html?dl=")
2308 .append(request_handler.url().spec())); 2315 .append(request_handler.url().spec()));
2309 2316
2310 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2317 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2311 WaitForInterrupt(download); 2318 WaitForInterrupt(download);
2312 2319
2313 download->Resume(); 2320 download->Resume();
2314 WaitForCompletion(download); 2321 WaitForCompletion(download);
2315 2322
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 2472
2466 EXPECT_EQ(FILE_PATH_LITERAL("suggested-filename"), 2473 EXPECT_EQ(FILE_PATH_LITERAL("suggested-filename"),
2467 downloads[0]->GetTargetFilePath().BaseName().value()); 2474 downloads[0]->GetTargetFilePath().BaseName().value());
2468 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); 2475 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete());
2469 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); 2476 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete());
2470 } 2477 }
2471 2478
2472 // A request for a non-existent resource should still result in a DownloadItem 2479 // A request for a non-existent resource should still result in a DownloadItem
2473 // that's created in an interrupted state. 2480 // that's created in an interrupted state.
2474 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeServerError) { 2481 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeServerError) {
2475 ASSERT_TRUE(embedded_test_server()->Start());
2476
2477 GURL download_url = 2482 GURL download_url =
2478 embedded_test_server()->GetURL("/download/does-not-exist"); 2483 embedded_test_server()->GetURL("/download/does-not-exist");
2479 GURL document_url = embedded_test_server()->GetURL( 2484 GURL document_url = embedded_test_server()->GetURL(
2480 std::string("/download/download-attribute.html?target=") + 2485 std::string("/download/download-attribute.html?target=") +
2481 download_url.spec()); 2486 download_url.spec());
2482 2487
2483 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2488 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2484 WaitForInterrupt(download); 2489 WaitForInterrupt(download);
2485 2490
2486 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, 2491 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2487 download->GetLastReason()); 2492 download->GetLastReason());
2488 } 2493 }
2489 2494
2490 namespace { 2495 namespace {
2491 2496
2492 void ErrorReturningRequestHandler( 2497 void ErrorReturningRequestHandler(
2493 const net::HttpRequestHeaders& headers, 2498 const net::HttpRequestHeaders& headers,
2494 const TestDownloadRequestHandler::OnStartResponseCallback& callback) { 2499 const TestDownloadRequestHandler::OnStartResponseCallback& callback) {
2495 callback.Run(std::string(), net::ERR_INTERNET_DISCONNECTED); 2500 callback.Run(std::string(), net::ERR_INTERNET_DISCONNECTED);
2496 } 2501 }
2497 2502
2498 } // namespace 2503 } // namespace
2499 2504
2500 // A request that fails before it gets a response from the server should also 2505 // A request that fails before it gets a response from the server should also
2501 // result in a DownloadItem that's created in an interrupted state. 2506 // result in a DownloadItem that's created in an interrupted state.
2502 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeNetworkError) { 2507 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeNetworkError) {
2503 ASSERT_TRUE(embedded_test_server()->Start());
2504 TestDownloadRequestHandler request_handler; 2508 TestDownloadRequestHandler request_handler;
2505 TestDownloadRequestHandler::Parameters parameters; 2509 TestDownloadRequestHandler::Parameters parameters;
2506 2510
2507 parameters.on_start_handler = base::Bind(&ErrorReturningRequestHandler); 2511 parameters.on_start_handler = base::Bind(&ErrorReturningRequestHandler);
2508 request_handler.StartServing(parameters); 2512 request_handler.StartServing(parameters);
2509 2513
2510 GURL document_url = embedded_test_server()->GetURL( 2514 GURL document_url = embedded_test_server()->GetURL(
2511 std::string("/download/download-attribute.html?target=") + 2515 std::string("/download/download-attribute.html?target=") +
2512 request_handler.url().spec()); 2516 request_handler.url().spec());
2513 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2517 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2514 WaitForInterrupt(download); 2518 WaitForInterrupt(download);
2515 2519
2516 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, 2520 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED,
2517 download->GetLastReason()); 2521 download->GetLastReason());
2518 } 2522 }
2519 2523
2520 // A request that fails due to it being rejected by policy should result in a 2524 // A request that fails due to it being rejected by policy should result in a
2521 // DownloadItem that's marked as interrupted. 2525 // DownloadItem that's marked as interrupted.
2522 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeInvalidURL) { 2526 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeInvalidURL) {
2523 ASSERT_TRUE(embedded_test_server()->Start());
2524
2525 GURL document_url = embedded_test_server()->GetURL( 2527 GURL document_url = embedded_test_server()->GetURL(
2526 "/download/download-attribute.html?target=about:version"); 2528 "/download/download-attribute.html?target=about:version");
2527 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2529 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2528 WaitForInterrupt(download); 2530 WaitForInterrupt(download);
2529 2531
2530 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, 2532 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST,
2531 download->GetLastReason()); 2533 download->GetLastReason());
2532 EXPECT_FALSE(download->CanResume()); 2534 EXPECT_FALSE(download->CanResume());
2533 } 2535 }
2534 2536
2535 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeBlobURL) { 2537 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeBlobURL) {
2536 ASSERT_TRUE(embedded_test_server()->Start());
2537
2538 GURL document_url = 2538 GURL document_url =
2539 embedded_test_server()->GetURL("/download/download-attribute-blob.html"); 2539 embedded_test_server()->GetURL("/download/download-attribute-blob.html");
2540 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2540 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2541 WaitForCompletion(download); 2541 WaitForCompletion(download);
2542 2542
2543 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename.txt"), 2543 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename.txt"),
2544 download->GetTargetFilePath().BaseName().value().c_str()); 2544 download->GetTargetFilePath().BaseName().value().c_str());
2545 } 2545 }
2546 2546
2547 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameSiteCookie) { 2547 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameSiteCookie) {
2548 base::ThreadRestrictions::ScopedAllowIO allow_io_during_test; 2548 base::ThreadRestrictions::ScopedAllowIO allow_io_during_test;
2549 2549
2550 const std::string kOriginOne = "one.example";
2551 const std::string kOriginTwo = "two.example";
2552
2553 ASSERT_TRUE(embedded_test_server()->Start());
2554
2555 const std::string real_host = embedded_test_server()->host_port_pair().host();
2556 host_resolver()->AddRule(kOriginOne, real_host);
2557 host_resolver()->AddRule(kOriginTwo, real_host);
2558
2559 GURL echo_cookie_url = 2550 GURL echo_cookie_url =
2560 embedded_test_server()->GetURL(kOriginOne, "/echoheader?cookie"); 2551 embedded_test_server()->GetURL(kOriginOne, "/echoheader?cookie");
2561 2552
2562 // download-attribute-same-site-cookie sets two cookies. One "A=B" is set with 2553 // download-attribute-same-site-cookie sets two cookies. One "A=B" is set with
2563 // SameSite=Strict. The other one "B=C" doesn't have this flag. In general 2554 // SameSite=Strict. The other one "B=C" doesn't have this flag. In general
2564 // a[download] should behave the same as a top level navigation. 2555 // a[download] should behave the same as a top level navigation.
2565 // 2556 //
2566 // The page then simulates a click on an <a download> link whose target is the 2557 // The page then simulates a click on an <a download> link whose target is the
2567 // /echoheader handler on the same origin. 2558 // /echoheader handler on the same origin.
2568 DownloadItem* download = StartDownloadAndReturnItem( 2559 DownloadItem* download = StartDownloadAndReturnItem(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 IN_PROC_BROWSER_TEST_F(DownloadContentTest, SniffedMimeType) { 2628 IN_PROC_BROWSER_TEST_F(DownloadContentTest, SniffedMimeType) {
2638 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("gzip-content.gz"); 2629 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("gzip-content.gz");
2639 DownloadItem* item = StartDownloadAndReturnItem(shell(), url); 2630 DownloadItem* item = StartDownloadAndReturnItem(shell(), url);
2640 WaitForCompletion(item); 2631 WaitForCompletion(item);
2641 2632
2642 EXPECT_STREQ("application/x-gzip", item->GetMimeType().c_str()); 2633 EXPECT_STREQ("application/x-gzip", item->GetMimeType().c_str());
2643 EXPECT_TRUE(item->GetOriginalMimeType().empty()); 2634 EXPECT_TRUE(item->GetOriginalMimeType().empty());
2644 } 2635 }
2645 2636
2646 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DuplicateContentDisposition) { 2637 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DuplicateContentDisposition) {
2647 ASSERT_TRUE(embedded_test_server()->Start());
2648
2649 // double-content-disposition.txt is served with two Content-Disposition 2638 // double-content-disposition.txt is served with two Content-Disposition
2650 // headers, both of which are identical. 2639 // headers, both of which are identical.
2651 NavigateToURLAndWaitForDownload( 2640 NavigateToURLAndWaitForDownload(
2652 shell(), 2641 shell(),
2653 embedded_test_server()->GetURL( 2642 embedded_test_server()->GetURL(
2654 "/download/double-content-disposition.txt"), 2643 "/download/double-content-disposition.txt"),
2655 DownloadItem::COMPLETE); 2644 DownloadItem::COMPLETE);
2656 2645
2657 std::vector<DownloadItem*> downloads; 2646 std::vector<DownloadItem*> downloads;
2658 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2647 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2659 ASSERT_EQ(1u, downloads.size()); 2648 ASSERT_EQ(1u, downloads.size());
2660 2649
2661 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2650 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2662 downloads[0]->GetTargetFilePath().BaseName().value()); 2651 downloads[0]->GetTargetFilePath().BaseName().value());
2663 } 2652 }
2664 2653
2665 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameOriginIFrame) { 2654 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameOriginIFrame) {
2666 ASSERT_TRUE(embedded_test_server()->Start());
2667
2668 GURL frame_url = embedded_test_server()->GetURL( 2655 GURL frame_url = embedded_test_server()->GetURL(
2669 "/download/download-attribute.html?target=/download/download-test.lib"); 2656 "/download/download-attribute.html?target=/download/download-test.lib");
2670 GURL document_url = embedded_test_server()->GetURL( 2657 GURL document_url = embedded_test_server()->GetURL(
2671 "/download/iframe-host.html?target=" + frame_url.spec()); 2658 "/download/iframe-host.html?target=" + frame_url.spec());
2672 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); 2659 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
2673 WaitForCompletion(download); 2660 WaitForCompletion(download);
2674 2661
2675 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename"), 2662 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename"),
2676 download->GetTargetFilePath().BaseName().value().c_str()); 2663 download->GetTargetFilePath().BaseName().value().c_str());
2677 } 2664 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 2709
2723 TestDownloadRequestHandler::CompletedRequests completed_requests; 2710 TestDownloadRequestHandler::CompletedRequests completed_requests;
2724 request_handler.GetCompletedRequestInfo(&completed_requests); 2711 request_handler.GetCompletedRequestInfo(&completed_requests);
2725 EXPECT_EQ(kTestRequestCount, static_cast<int>(completed_requests.size())); 2712 EXPECT_EQ(kTestRequestCount, static_cast<int>(completed_requests.size()));
2726 2713
2727 ReadAndVerifyFileContents(parameters.pattern_generator_seed, parameters.size, 2714 ReadAndVerifyFileContents(parameters.pattern_generator_seed, parameters.size,
2728 download->GetTargetFilePath()); 2715 download->GetTargetFilePath());
2729 } 2716 }
2730 2717
2731 } // namespace content 2718 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698