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 "chrome/browser/download/download_browsertest.h" | 5 #include "chrome/browser/download/download_browsertest.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 #include "chrome/grit/generated_resources.h" | 68 #include "chrome/grit/generated_resources.h" |
69 #include "chrome/test/base/in_process_browser_test.h" | 69 #include "chrome/test/base/in_process_browser_test.h" |
70 #include "chrome/test/base/ui_test_utils.h" | 70 #include "chrome/test/base/ui_test_utils.h" |
71 #include "components/history/content/browser/download_constants_utils.h" | 71 #include "components/history/content/browser/download_constants_utils.h" |
72 #include "components/history/core/browser/download_constants.h" | 72 #include "components/history/core/browser/download_constants.h" |
73 #include "components/history/core/browser/download_row.h" | 73 #include "components/history/core/browser/download_row.h" |
74 #include "components/history/core/browser/history_service.h" | 74 #include "components/history/core/browser/history_service.h" |
75 #include "components/infobars/core/confirm_infobar_delegate.h" | 75 #include "components/infobars/core/confirm_infobar_delegate.h" |
76 #include "components/infobars/core/infobar.h" | 76 #include "components/infobars/core/infobar.h" |
77 #include "components/prefs/pref_service.h" | 77 #include "components/prefs/pref_service.h" |
| 78 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
78 #include "content/public/browser/download_danger_type.h" | 79 #include "content/public/browser/download_danger_type.h" |
79 #include "content/public/browser/download_interrupt_reasons.h" | 80 #include "content/public/browser/download_interrupt_reasons.h" |
80 #include "content/public/browser/download_item.h" | 81 #include "content/public/browser/download_item.h" |
81 #include "content/public/browser/download_manager.h" | 82 #include "content/public/browser/download_manager.h" |
82 #include "content/public/browser/download_save_info.h" | 83 #include "content/public/browser/download_save_info.h" |
83 #include "content/public/browser/download_url_parameters.h" | 84 #include "content/public/browser/download_url_parameters.h" |
84 #include "content/public/browser/notification_source.h" | 85 #include "content/public/browser/notification_source.h" |
85 #include "content/public/browser/render_frame_host.h" | 86 #include "content/public/browser/render_frame_host.h" |
86 #include "content/public/browser/render_view_host.h" | 87 #include "content/public/browser/render_view_host.h" |
87 #include "content/public/browser/render_widget_host.h" | 88 #include "content/public/browser/render_widget_host.h" |
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3303 ASSERT_EQ(1u, downloads.size()); | 3304 ASSERT_EQ(1u, downloads.size()); |
3304 | 3305 |
3305 DownloadItem* download = downloads[0]; | 3306 DownloadItem* download = downloads[0]; |
3306 EXPECT_FALSE(download->IsDangerous()); | 3307 EXPECT_FALSE(download->IsDangerous()); |
3307 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 3308 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
3308 download->GetDangerType()); | 3309 download->GetDangerType()); |
3309 | 3310 |
3310 download->Cancel(true); | 3311 download->Cancel(true); |
3311 } | 3312 } |
3312 | 3313 |
3313 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | 3314 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceDiscardDownload) { |
| 3315 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 3316 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, true); |
| 3317 safe_browsing::SetExtendedReportingPref(prefs, true); |
| 3318 |
3314 // Make a dangerous file. | 3319 // Make a dangerous file. |
3315 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( | 3320 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
3316 "downloads/dangerous/dangerous.swf")); | 3321 "downloads/dangerous/dangerous.swf")); |
3317 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( | 3322 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( |
3318 new content::DownloadTestObserverInterrupted( | 3323 new content::DownloadTestObserverInterrupted( |
3319 DownloadManagerForBrowser(browser()), 1, | 3324 DownloadManagerForBrowser(browser()), 1, |
3320 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3325 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3321 ui_test_utils::NavigateToURLWithDisposition( | 3326 ui_test_utils::NavigateToURLWithDisposition( |
3322 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, | 3327 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
3323 ui_test_utils::BROWSER_TEST_NONE); | 3328 ui_test_utils::BROWSER_TEST_NONE); |
(...skipping 23 matching lines...) Expand all Loading... |
3347 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | 3352 download_protection_service->feedback_service()->MaybeStorePingsForDownload( |
3348 safe_browsing::DownloadProtectionService::UNCOMMON, | 3353 safe_browsing::DownloadProtectionService::UNCOMMON, |
3349 downloads[0], | 3354 downloads[0], |
3350 ping_request, | 3355 ping_request, |
3351 ping_response); | 3356 ping_response); |
3352 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | 3357 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
3353 *(downloads[0]))); | 3358 *(downloads[0]))); |
3354 | 3359 |
3355 // Begin feedback and check that the file is "stolen". | 3360 // Begin feedback and check that the file is "stolen". |
3356 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 3361 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
3357 downloads[0]); | 3362 downloads[0], DownloadCommands::DISCARD); |
3358 std::vector<DownloadItem*> updated_downloads; | 3363 std::vector<DownloadItem*> updated_downloads; |
3359 GetDownloads(browser(), &updated_downloads); | 3364 GetDownloads(browser(), &updated_downloads); |
3360 ASSERT_TRUE(updated_downloads.empty()); | 3365 ASSERT_TRUE(updated_downloads.empty()); |
3361 } | 3366 } |
3362 | 3367 |
3363 IN_PROC_BROWSER_TEST_F( | 3368 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceKeepDownload) { |
3364 DownloadTestWithFakeSafeBrowsing, | 3369 PrefService* prefs = browser()->profile()->GetPrefs(); |
3365 SendUncommonDownloadReportIfUserProceed) { | 3370 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, true); |
| 3371 safe_browsing::SetExtendedReportingPref(prefs, true); |
| 3372 |
| 3373 // Make a dangerous file. |
| 3374 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
| 3375 "downloads/dangerous/dangerous.swf")); |
| 3376 std::unique_ptr<content::DownloadTestObserverInterrupted> |
| 3377 interruption_observer(new content::DownloadTestObserverInterrupted( |
| 3378 DownloadManagerForBrowser(browser()), 1, |
| 3379 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
| 3380 ui_test_utils::NavigateToURLWithDisposition( |
| 3381 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
| 3382 ui_test_utils::BROWSER_TEST_NONE); |
| 3383 interruption_observer->WaitForFinished(); |
| 3384 |
| 3385 // Get the download from the DownloadManager. |
| 3386 std::vector<DownloadItem*> downloads; |
| 3387 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 3388 ASSERT_EQ(1u, downloads.size()); |
| 3389 EXPECT_TRUE(downloads[0]->IsDangerous()); |
| 3390 |
| 3391 // Save fake pings for the download. |
| 3392 safe_browsing::ClientDownloadReport fake_metadata; |
| 3393 fake_metadata.mutable_download_request()->set_url("http://test"); |
| 3394 fake_metadata.mutable_download_request()->set_length(1); |
| 3395 fake_metadata.mutable_download_request()->mutable_digests()->set_sha1("hi"); |
| 3396 fake_metadata.mutable_download_response()->set_verdict( |
| 3397 safe_browsing::ClientDownloadResponse::UNCOMMON); |
| 3398 std::string ping_request( |
| 3399 fake_metadata.download_request().SerializeAsString()); |
| 3400 std::string ping_response( |
| 3401 fake_metadata.download_response().SerializeAsString()); |
| 3402 safe_browsing::SafeBrowsingService* sb_service = |
| 3403 g_browser_process->safe_browsing_service(); |
| 3404 safe_browsing::DownloadProtectionService* download_protection_service = |
| 3405 sb_service->download_protection_service(); |
| 3406 download_protection_service->feedback_service()->MaybeStorePingsForDownload( |
| 3407 safe_browsing::DownloadProtectionService::UNCOMMON, downloads[0], |
| 3408 ping_request, ping_response); |
| 3409 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
| 3410 *(downloads[0]))); |
| 3411 |
| 3412 // Begin feedback and check that file is still there. |
| 3413 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
| 3414 downloads[0], DownloadCommands::KEEP); |
| 3415 |
| 3416 std::vector<DownloadItem*> updated_downloads; |
| 3417 GetDownloads(browser(), &updated_downloads); |
| 3418 ASSERT_EQ(std::size_t(1), updated_downloads.size()); |
| 3419 ASSERT_FALSE(updated_downloads[0]->IsDangerous()); |
| 3420 ASSERT_TRUE(PathExists(updated_downloads[0]->GetFullPath())); |
| 3421 updated_downloads[0]->Cancel(true); |
| 3422 } |
| 3423 |
| 3424 IN_PROC_BROWSER_TEST_F(DownloadTestWithFakeSafeBrowsing, |
| 3425 SendUncommonDownloadReportIfUserProceed) { |
3366 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 3426 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
3367 true); | 3427 true); |
3368 // Make a dangerous file. | 3428 // Make a dangerous file. |
3369 GURL download_url( | 3429 GURL download_url( |
3370 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); | 3430 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); |
3371 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( | 3431 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( |
3372 DangerousDownloadWaiter( | 3432 DangerousDownloadWaiter( |
3373 browser(), 1, | 3433 browser(), 1, |
3374 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3434 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3375 ui_test_utils::NavigateToURL(browser(), download_url); | 3435 ui_test_utils::NavigateToURL(browser(), download_url); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3666 browser(), 1, | 3726 browser(), 1, |
3667 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3727 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3668 ui_test_utils::NavigateToURL(browser(), extension_url); | 3728 ui_test_utils::NavigateToURL(browser(), extension_url); |
3669 | 3729 |
3670 observer->WaitForFinished(); | 3730 observer->WaitForFinished(); |
3671 | 3731 |
3672 // Download shelf should close. | 3732 // Download shelf should close. |
3673 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3733 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3674 } | 3734 } |
3675 #endif // defined(OS_CHROMEOS) | 3735 #endif // defined(OS_CHROMEOS) |
OLD | NEW |