| 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 // 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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 BrowserThread::IO, FROM_HERE, | 568 BrowserThread::IO, FROM_HERE, |
| 569 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler)); | 569 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler)); |
| 570 base::FilePath mock_base(GetTestFilePath("download", "")); | 570 base::FilePath mock_base(GetTestFilePath("download", "")); |
| 571 BrowserThread::PostTask( | 571 BrowserThread::PostTask( |
| 572 BrowserThread::IO, FROM_HERE, | 572 BrowserThread::IO, FROM_HERE, |
| 573 base::Bind( | 573 base::Bind( |
| 574 &net::URLRequestMockHTTPJob::AddUrlHandlers, mock_base, | 574 &net::URLRequestMockHTTPJob::AddUrlHandlers, mock_base, |
| 575 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); | 575 make_scoped_refptr(content::BrowserThread::GetBlockingPool()))); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void SetUpCommandLine(base::CommandLine* commnad_line) override { |
| 579 IsolateAllSitesForTesting(commnad_line); |
| 580 } |
| 581 |
| 578 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() { | 582 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() { |
| 579 return test_delegate_.get(); | 583 return test_delegate_.get(); |
| 580 } | 584 } |
| 581 | 585 |
| 582 const base::FilePath& GetDownloadDirectory() const { | 586 const base::FilePath& GetDownloadDirectory() const { |
| 583 return downloads_directory_.path(); | 587 return downloads_directory_.path(); |
| 584 } | 588 } |
| 585 | 589 |
| 586 // Create a DownloadTestObserverTerminal that will wait for the | 590 // Create a DownloadTestObserverTerminal that will wait for the |
| 587 // specified number of downloads to finish. | 591 // specified number of downloads to finish. |
| (...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 DownloadItem::COMPLETE); | 2476 DownloadItem::COMPLETE); |
| 2473 | 2477 |
| 2474 std::vector<DownloadItem*> downloads; | 2478 std::vector<DownloadItem*> downloads; |
| 2475 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2479 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2476 ASSERT_EQ(1u, downloads.size()); | 2480 ASSERT_EQ(1u, downloads.size()); |
| 2477 | 2481 |
| 2478 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2482 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2479 downloads[0]->GetTargetFilePath().BaseName().value()); | 2483 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2480 } | 2484 } |
| 2481 | 2485 |
| 2486 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameOriginIFrame) { |
| 2487 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2488 |
| 2489 GURL frame_url = embedded_test_server()->GetURL( |
| 2490 "/download/download-attribute.html?target=/download/download-test.lib"); |
| 2491 GURL document_url = embedded_test_server()->GetURL( |
| 2492 "/download/iframe-host.html?target=" + frame_url.spec()); |
| 2493 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
| 2494 WaitForCompletion(download); |
| 2495 |
| 2496 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename"), |
| 2497 download->GetTargetFilePath().BaseName().value().c_str()); |
| 2498 } |
| 2499 |
| 2500 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 2501 DownloadAttributeCrossOriginIFrame) { |
| 2502 net::EmbeddedTestServer origin_one; |
| 2503 net::EmbeddedTestServer origin_two; |
| 2504 ASSERT_TRUE(origin_one.Start()); |
| 2505 ASSERT_TRUE(origin_two.Start()); |
| 2506 |
| 2507 origin_one.ServeFilesFromDirectory(GetTestFilePath("download", "")); |
| 2508 origin_two.ServeFilesFromDirectory(GetTestFilePath("download", "")); |
| 2509 |
| 2510 GURL frame_url = |
| 2511 origin_one.GetURL("/download-attribute.html?target=" + |
| 2512 origin_two.GetURL("/download-test.lib").spec()); |
| 2513 GURL::Replacements replacements; |
| 2514 replacements.SetHostStr("localhost"); |
| 2515 frame_url = frame_url.ReplaceComponents(replacements); |
| 2516 GURL document_url = |
| 2517 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); |
| 2518 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
| 2519 WaitForCompletion(download); |
| 2520 |
| 2521 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), |
| 2522 download->GetTargetFilePath().BaseName().value().c_str()); |
| 2523 } |
| 2524 |
| 2482 } // namespace content | 2525 } // namespace content |
| OLD | NEW |