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 3293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3304 ASSERT_EQ(1u, downloads.size()); | 3304 ASSERT_EQ(1u, downloads.size()); |
3305 | 3305 |
3306 DownloadItem* download = downloads[0]; | 3306 DownloadItem* download = downloads[0]; |
3307 EXPECT_FALSE(download->IsDangerous()); | 3307 EXPECT_FALSE(download->IsDangerous()); |
3308 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 3308 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
3309 download->GetDangerType()); | 3309 download->GetDangerType()); |
3310 | 3310 |
3311 download->Cancel(true); | 3311 download->Cancel(true); |
3312 } | 3312 } |
3313 | 3313 |
3314 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | 3314 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceDiscardDownload) { |
3315 // Make a dangerous file. | 3315 // Make a dangerous file. |
3316 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( | 3316 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
3317 "downloads/dangerous/dangerous.swf")); | 3317 "downloads/dangerous/dangerous.swf")); |
3318 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( | 3318 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( |
3319 new content::DownloadTestObserverInterrupted( | 3319 new content::DownloadTestObserverInterrupted( |
3320 DownloadManagerForBrowser(browser()), 1, | 3320 DownloadManagerForBrowser(browser()), 1, |
3321 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3321 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3322 ui_test_utils::NavigateToURLWithDisposition( | 3322 ui_test_utils::NavigateToURLWithDisposition( |
3323 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, | 3323 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
3324 ui_test_utils::BROWSER_TEST_NONE); | 3324 ui_test_utils::BROWSER_TEST_NONE); |
(...skipping 23 matching lines...) Expand all Loading... | |
3348 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | 3348 download_protection_service->feedback_service()->MaybeStorePingsForDownload( |
3349 safe_browsing::DownloadProtectionService::UNCOMMON, | 3349 safe_browsing::DownloadProtectionService::UNCOMMON, |
3350 downloads[0], | 3350 downloads[0], |
3351 ping_request, | 3351 ping_request, |
3352 ping_response); | 3352 ping_response); |
3353 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | 3353 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
3354 *(downloads[0]))); | 3354 *(downloads[0]))); |
3355 | 3355 |
3356 // Begin feedback and check that the file is "stolen". | 3356 // Begin feedback and check that the file is "stolen". |
3357 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 3357 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
3358 downloads[0]); | 3358 downloads[0], DownloadCommands::DISCARD); |
3359 std::vector<DownloadItem*> updated_downloads; | 3359 std::vector<DownloadItem*> updated_downloads; |
3360 GetDownloads(browser(), &updated_downloads); | 3360 GetDownloads(browser(), &updated_downloads); |
3361 ASSERT_TRUE(updated_downloads.empty()); | 3361 ASSERT_TRUE(updated_downloads.empty()); |
3362 } | 3362 } |
3363 | 3363 |
3364 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceKeepDownload) { | |
3365 // Make a dangerous file. | |
3366 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( | |
3367 "downloads/dangerous/dangerous.swf")); | |
3368 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( | |
3369 new content::DownloadTestObserverInterrupted( | |
3370 DownloadManagerForBrowser(browser()), 1, | |
3371 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | |
3372 ui_test_utils::NavigateToURLWithDisposition( | |
3373 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, | |
3374 ui_test_utils::BROWSER_TEST_NONE); | |
3375 observer->WaitForFinished(); | |
3376 | |
3377 // Get the download from the DownloadManager. | |
3378 std::vector<DownloadItem*> downloads; | |
3379 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
3380 ASSERT_EQ(1u, downloads.size()); | |
3381 EXPECT_TRUE(downloads[0]->IsDangerous()); | |
3382 | |
3383 // Save fake pings for the download. | |
3384 safe_browsing::ClientDownloadReport fake_metadata; | |
3385 fake_metadata.mutable_download_request()->set_url("http://test"); | |
3386 fake_metadata.mutable_download_request()->set_length(1); | |
3387 fake_metadata.mutable_download_request()->mutable_digests()->set_sha1("hi"); | |
3388 fake_metadata.mutable_download_response()->set_verdict( | |
3389 safe_browsing::ClientDownloadResponse::UNCOMMON); | |
3390 std::string ping_request( | |
3391 fake_metadata.download_request().SerializeAsString()); | |
3392 std::string ping_response( | |
3393 fake_metadata.download_response().SerializeAsString()); | |
3394 safe_browsing::SafeBrowsingService* sb_service = | |
3395 g_browser_process->safe_browsing_service(); | |
3396 safe_browsing::DownloadProtectionService* download_protection_service = | |
3397 sb_service->download_protection_service(); | |
3398 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | |
3399 safe_browsing::DownloadProtectionService::UNCOMMON, downloads[0], | |
3400 ping_request, ping_response); | |
3401 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | |
3402 *(downloads[0]))); | |
3403 | |
3404 // Begin feedback and check that file is still there. | |
3405 download_protection_service->feedback_service()->BeginFeedbackForDownload( | |
3406 downloads[0], DownloadCommands::KEEP); | |
3407 std::vector<DownloadItem*> updated_downloads; | |
3408 GetDownloads(browser(), &updated_downloads); | |
3409 ASSERT_FALSE(updated_downloads.empty()); | |
3410 for (auto download : updated_downloads) | |
3411 download->Cancel(true); | |
asanka
2016/11/01 20:58:58
Should also test that the target file exists. You
Jialiu Lin
2016/11/03 20:16:50
Done.
| |
3412 } | |
3413 | |
3364 IN_PROC_BROWSER_TEST_F( | 3414 IN_PROC_BROWSER_TEST_F( |
3365 DownloadTestWithFakeSafeBrowsing, | 3415 DownloadTestWithFakeSafeBrowsing, |
3366 SendUncommonDownloadReportIfUserProceed) { | 3416 SendUncommonDownloadReportIfUserProceed) { |
3367 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 3417 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
3368 true); | 3418 true); |
3369 // Make a dangerous file. | 3419 // Make a dangerous file. |
3370 GURL download_url( | 3420 GURL download_url( |
3371 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); | 3421 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); |
3372 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( | 3422 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( |
3373 DangerousDownloadWaiter( | 3423 DangerousDownloadWaiter( |
3374 browser(), 1, | 3424 browser(), 1, |
3375 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3425 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3376 ui_test_utils::NavigateToURL(browser(), download_url); | 3426 ui_test_utils::NavigateToURL(browser(), download_url); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3667 browser(), 1, | 3717 browser(), 1, |
3668 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3718 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3669 ui_test_utils::NavigateToURL(browser(), extension_url); | 3719 ui_test_utils::NavigateToURL(browser(), extension_url); |
3670 | 3720 |
3671 observer->WaitForFinished(); | 3721 observer->WaitForFinished(); |
3672 | 3722 |
3673 // Download shelf should close. | 3723 // Download shelf should close. |
3674 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3724 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3675 } | 3725 } |
3676 #endif // defined(OS_CHROMEOS) | 3726 #endif // defined(OS_CHROMEOS) |
OLD | NEW |