Chromium Code Reviews| 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 |
| 3368 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceKeepDownload) { | |
| 3369 PrefService* prefs = browser()->profile()->GetPrefs(); | |
| 3370 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, true); | |
| 3371 safe_browsing::SetExtendedReportingPref(prefs, true); | |
| 3372 EnableFileChooser(true); | |
| 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( | |
| 3378 new content::DownloadTestObserverInterrupted( | |
| 3379 DownloadManagerForBrowser(browser()), 1, | |
| 3380 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | |
| 3381 std::unique_ptr<content::DownloadTestObserver> completion_observer( | |
| 3382 new content::DownloadTestObserverTerminal( | |
| 3383 DownloadManagerForBrowser(browser()), 1, | |
| 3384 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | |
| 3385 ui_test_utils::NavigateToURLWithDisposition( | |
| 3386 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, | |
| 3387 ui_test_utils::BROWSER_TEST_NONE); | |
| 3388 interruption_observer->WaitForFinished(); | |
| 3389 | |
| 3390 // Get the download from the DownloadManager. | |
| 3391 std::vector<DownloadItem*> downloads; | |
| 3392 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
| 3393 ASSERT_EQ(1u, downloads.size()); | |
| 3394 EXPECT_TRUE(downloads[0]->IsDangerous()); | |
| 3395 | |
| 3396 // Save fake pings for the download. | |
| 3397 safe_browsing::ClientDownloadReport fake_metadata; | |
| 3398 fake_metadata.mutable_download_request()->set_url("http://test"); | |
| 3399 fake_metadata.mutable_download_request()->set_length(1); | |
| 3400 fake_metadata.mutable_download_request()->mutable_digests()->set_sha1("hi"); | |
| 3401 fake_metadata.mutable_download_response()->set_verdict( | |
| 3402 safe_browsing::ClientDownloadResponse::UNCOMMON); | |
| 3403 std::string ping_request( | |
| 3404 fake_metadata.download_request().SerializeAsString()); | |
| 3405 std::string ping_response( | |
| 3406 fake_metadata.download_response().SerializeAsString()); | |
| 3407 safe_browsing::SafeBrowsingService* sb_service = | |
| 3408 g_browser_process->safe_browsing_service(); | |
| 3409 safe_browsing::DownloadProtectionService* download_protection_service = | |
| 3410 sb_service->download_protection_service(); | |
| 3411 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | |
| 3412 safe_browsing::DownloadProtectionService::UNCOMMON, downloads[0], | |
| 3413 ping_request, ping_response); | |
| 3414 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | |
| 3415 *(downloads[0]))); | |
| 3416 | |
| 3417 // Begin feedback and check that file is still there. | |
| 3418 download_protection_service->feedback_service()->BeginFeedbackForDownload( | |
| 3419 downloads[0], DownloadCommands::KEEP); | |
| 3420 // Wait for download to complete. | |
| 3421 completion_observer->WaitForFinished(); | |
| 3422 | |
| 3423 std::vector<DownloadItem*> updated_downloads; | |
| 3424 GetDownloads(browser(), &updated_downloads); | |
| 3425 ASSERT_FALSE(updated_downloads.empty()); | |
|
asanka
2016/11/07 16:01:55
Should assert that there's exactly one download. O
Jialiu Lin
2016/11/14 20:57:39
Done.
| |
| 3426 ASSERT_FALSE(updated_downloads[0]->IsDangerous()); | |
| 3427 ASSERT_TRUE(PathExists(updated_downloads[0]->GetFullPath())); | |
| 3428 } | |
|
asanka
2016/11/07 16:01:54
I'm okay with the tests as is. But ideally we'd te
Jialiu Lin
2016/11/14 20:57:39
acknowledged.
I agree. We need more tests to verif
| |
| 3429 | |
| 3363 IN_PROC_BROWSER_TEST_F( | 3430 IN_PROC_BROWSER_TEST_F( |
| 3364 DownloadTestWithFakeSafeBrowsing, | 3431 DownloadTestWithFakeSafeBrowsing, |
| 3365 SendUncommonDownloadReportIfUserProceed) { | 3432 SendUncommonDownloadReportIfUserProceed) { |
| 3366 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 3433 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
| 3367 true); | 3434 true); |
| 3368 // Make a dangerous file. | 3435 // Make a dangerous file. |
| 3369 GURL download_url( | 3436 GURL download_url( |
| 3370 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); | 3437 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); |
| 3371 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( | 3438 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( |
| 3372 DangerousDownloadWaiter( | 3439 DangerousDownloadWaiter( |
| 3373 browser(), 1, | 3440 browser(), 1, |
| 3374 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3441 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
| 3375 ui_test_utils::NavigateToURL(browser(), download_url); | 3442 ui_test_utils::NavigateToURL(browser(), download_url); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3666 browser(), 1, | 3733 browser(), 1, |
| 3667 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3734 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3668 ui_test_utils::NavigateToURL(browser(), extension_url); | 3735 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3669 | 3736 |
| 3670 observer->WaitForFinished(); | 3737 observer->WaitForFinished(); |
| 3671 | 3738 |
| 3672 // Download shelf should close. | 3739 // Download shelf should close. |
| 3673 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3740 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3674 } | 3741 } |
| 3675 #endif // defined(OS_CHROMEOS) | 3742 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |