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 <sstream> | 5 #include <sstream> |
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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 2449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2460 | 2460 |
2461 DownloadTestObserver* observer(DangerousDownloadWaiter( | 2461 DownloadTestObserver* observer(DangerousDownloadWaiter( |
2462 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2462 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
2463 ui_test_utils::NavigateToURL(browser(), url); | 2463 ui_test_utils::NavigateToURL(browser(), url); |
2464 observer->WaitForFinished(); | 2464 observer->WaitForFinished(); |
2465 | 2465 |
2466 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2466 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
2467 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 2467 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
2468 } | 2468 } |
2469 | 2469 |
2470 IN_PROC_BROWSER_TEST_F(DownloadTest, TestFileDataBlocker) { | 2470 IN_PROC_BROWSER_TEST_F(DownloadTest, TestDataBlocker) { |
2471 ASSERT_TRUE(InitialSetup(false)); | 2471 ASSERT_TRUE(InitialSetup(false)); |
2472 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2472 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
2473 GURL urls[] = { | 2473 GURL url("data:application/octet-stream,abcdefghijklmnop%01%02%03l"); |
2474 // file: URL | |
2475 OriginFileUrl(file), | |
2476 | 2474 |
2477 // data: URL | 2475 // Navigate & block until navigation is done. |
2478 GURL("data:application/octet-stream,abcdefghijklmnop%01%02%03l") | 2476 ui_test_utils::NavigateToURLWithDisposition( |
2479 }; | 2477 browser(), url, CURRENT_TAB, |
| 2478 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
2480 | 2479 |
2481 for (size_t i = 0; i < arraysize(urls); i++) { | 2480 // Do a round trip to the IO thread to increase chances of any download |
2482 // Navigate & block until navigation is done. | 2481 // showing up on the UI thread. |
2483 ui_test_utils::NavigateToURLWithDisposition( | 2482 // Using DownloadTestFlushObserver is overkill, but it'll do the job. |
2484 browser(), urls[i], CURRENT_TAB, | 2483 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
2485 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 2484 new DownloadTestFlushObserver( |
| 2485 DownloadManagerForBrowser(browser()))); |
| 2486 flush_observer->WaitForFlush(); |
2486 | 2487 |
2487 // Do a round trip to the IO thread to increase chances of any download | 2488 // Confirm no downloads |
2488 // showing up on the UI thread. | 2489 std::vector<DownloadItem*> downloads; |
2489 // Using DownloadTestFlushObserver is overkill, but it'll do the job. | 2490 GetDownloads(browser(), &downloads); |
2490 scoped_refptr<DownloadTestFlushObserver> flush_observer( | 2491 EXPECT_EQ(0u, downloads.size()); |
2491 new DownloadTestFlushObserver( | |
2492 DownloadManagerForBrowser(browser()))); | |
2493 flush_observer->WaitForFlush(); | |
2494 | 2492 |
2495 // Confirm no downloads | 2493 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); |
2496 std::vector<DownloadItem*> downloads; | |
2497 GetDownloads(browser(), &downloads); | |
2498 EXPECT_EQ(0u, downloads.size()); | |
2499 | 2494 |
2500 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); | 2495 // Try the same thing with a direct download. Also check that the |
| 2496 // callback gives the right error. |
| 2497 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 2498 ASSERT_TRUE(web_contents); |
| 2499 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( |
| 2500 new DownloadTestItemCreationObserver); |
| 2501 // Only for cleanup if a download is actually created. |
| 2502 DownloadTestObserverTerminal backup_observer( |
| 2503 DownloadManagerForBrowser(browser()), |
| 2504 1, |
| 2505 false, |
| 2506 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
2501 | 2507 |
2502 // Try the same thing with a direct download. Also check that the | 2508 DownloadManagerForBrowser(browser())->DownloadUrl( |
2503 // callback gives the right error. | 2509 url, GURL(), "", false, -1, content::DownloadSaveInfo(), |
2504 WebContents* web_contents = browser()->GetSelectedWebContents(); | 2510 web_contents, creation_observer->callback()); |
2505 ASSERT_TRUE(web_contents); | |
2506 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | |
2507 new DownloadTestItemCreationObserver); | |
2508 // Only for cleanup if a download is actually created. | |
2509 DownloadTestObserverTerminal backup_observer( | |
2510 DownloadManagerForBrowser(browser()), | |
2511 1, | |
2512 false, | |
2513 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | |
2514 | 2511 |
2515 DownloadManagerForBrowser(browser())->DownloadUrl( | 2512 creation_observer->WaitForDownloadItemCreation(); |
2516 urls[i], GURL(), "", false, -1, content::DownloadSaveInfo(), | |
2517 web_contents, creation_observer->callback()); | |
2518 | 2513 |
2519 creation_observer->WaitForDownloadItemCreation(); | 2514 EXPECT_FALSE(creation_observer->succeeded()); |
| 2515 EXPECT_EQ(net::ERR_DISALLOWED_URL_SCHEME, creation_observer->error()); |
| 2516 EXPECT_EQ(content::DownloadId::Invalid(), creation_observer->download_id()); |
| 2517 downloads.clear(); |
| 2518 GetDownloads(browser(), &downloads); |
| 2519 EXPECT_EQ(0u, downloads.size()); |
2520 | 2520 |
2521 EXPECT_FALSE(creation_observer->succeeded()); | 2521 if (creation_observer->succeeded()) { |
2522 EXPECT_EQ(net::ERR_DISALLOWED_URL_SCHEME, creation_observer->error()); | 2522 // Wait until the download is done. We don't care how it's finished. |
2523 EXPECT_EQ(content::DownloadId::Invalid(), creation_observer->download_id()); | 2523 backup_observer.WaitForFinished(); |
2524 downloads.clear(); | |
2525 GetDownloads(browser(), &downloads); | |
2526 EXPECT_EQ(0u, downloads.size()); | |
2527 | |
2528 if (creation_observer->succeeded()) { | |
2529 // Wait until the download is done. We don't care how it's finished. | |
2530 backup_observer.WaitForFinished(); | |
2531 } | |
2532 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); | |
2533 } | 2524 } |
| 2525 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); |
2534 } | 2526 } |
OLD | NEW |