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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 #include "chrome/browser/extensions/extension_service.h" | 40 #include "chrome/browser/extensions/extension_service.h" |
41 #include "chrome/browser/history/download_row.h" | 41 #include "chrome/browser/history/download_row.h" |
42 #include "chrome/browser/history/history_service.h" | 42 #include "chrome/browser/history/history_service.h" |
43 #include "chrome/browser/history/history_service_factory.h" | 43 #include "chrome/browser/history/history_service_factory.h" |
44 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 44 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
45 #include "chrome/browser/infobars/infobar.h" | 45 #include "chrome/browser/infobars/infobar.h" |
46 #include "chrome/browser/infobars/infobar_service.h" | 46 #include "chrome/browser/infobars/infobar_service.h" |
47 #include "chrome/browser/net/url_request_mock_util.h" | 47 #include "chrome/browser/net/url_request_mock_util.h" |
48 #include "chrome/browser/profiles/profile.h" | 48 #include "chrome/browser/profiles/profile.h" |
49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
50 #include "chrome/browser/safe_browsing/download_feedback_service.h" | |
51 #include "chrome/browser/safe_browsing/download_protection_service.h" | |
52 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
50 #include "chrome/browser/ui/browser.h" | 53 #include "chrome/browser/ui/browser.h" |
51 #include "chrome/browser/ui/browser_commands.h" | 54 #include "chrome/browser/ui/browser_commands.h" |
52 #include "chrome/browser/ui/browser_finder.h" | 55 #include "chrome/browser/ui/browser_finder.h" |
53 #include "chrome/browser/ui/browser_list.h" | 56 #include "chrome/browser/ui/browser_list.h" |
54 #include "chrome/browser/ui/browser_tabstrip.h" | 57 #include "chrome/browser/ui/browser_tabstrip.h" |
55 #include "chrome/browser/ui/browser_window.h" | 58 #include "chrome/browser/ui/browser_window.h" |
56 #include "chrome/browser/ui/chrome_pages.h" | 59 #include "chrome/browser/ui/chrome_pages.h" |
57 #include "chrome/browser/ui/host_desktop.h" | 60 #include "chrome/browser/ui/host_desktop.h" |
58 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 61 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
59 #include "chrome/common/chrome_paths.h" | 62 #include "chrome/common/chrome_paths.h" |
60 #include "chrome/common/pref_names.h" | 63 #include "chrome/common/pref_names.h" |
64 #include "chrome/common/safe_browsing/csd.pb.h" | |
61 #include "chrome/common/url_constants.h" | 65 #include "chrome/common/url_constants.h" |
62 #include "chrome/test/base/in_process_browser_test.h" | 66 #include "chrome/test/base/in_process_browser_test.h" |
63 #include "chrome/test/base/test_switches.h" | 67 #include "chrome/test/base/test_switches.h" |
64 #include "chrome/test/base/ui_test_utils.h" | 68 #include "chrome/test/base/ui_test_utils.h" |
65 #include "content/public/browser/download_interrupt_reasons.h" | 69 #include "content/public/browser/download_interrupt_reasons.h" |
66 #include "content/public/browser/download_item.h" | 70 #include "content/public/browser/download_item.h" |
67 #include "content/public/browser/download_manager.h" | 71 #include "content/public/browser/download_manager.h" |
68 #include "content/public/browser/download_save_info.h" | 72 #include "content/public/browser/download_save_info.h" |
69 #include "content/public/browser/download_url_parameters.h" | 73 #include "content/public/browser/download_url_parameters.h" |
70 #include "content/public/browser/notification_source.h" | 74 #include "content/public/browser/notification_source.h" |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 } | 797 } |
794 | 798 |
795 static void ExpectWindowCountAfterDownload(size_t expected) { | 799 static void ExpectWindowCountAfterDownload(size_t expected) { |
796 EXPECT_EQ(expected, chrome::GetTotalBrowserCount()); | 800 EXPECT_EQ(expected, chrome::GetTotalBrowserCount()); |
797 } | 801 } |
798 | 802 |
799 void EnableFileChooser(bool enable) { | 803 void EnableFileChooser(bool enable) { |
800 file_activity_observer_->EnableFileChooser(enable); | 804 file_activity_observer_->EnableFileChooser(enable); |
801 } | 805 } |
802 | 806 |
807 void ChangeDangerTypeForFeedbackTest() { | |
808 file_activity_observer_->ChangeDangerTypeForFeedbackTest(); | |
809 } | |
810 | |
803 bool DidShowFileChooser() { | 811 bool DidShowFileChooser() { |
804 return file_activity_observer_->TestAndResetDidShowFileChooser(); | 812 return file_activity_observer_->TestAndResetDidShowFileChooser(); |
805 } | 813 } |
806 | 814 |
807 // Checks that |path| is has |file_size| bytes, and matches the |value| | 815 // Checks that |path| is has |file_size| bytes, and matches the |value| |
808 // string. | 816 // string. |
809 bool VerifyFile(const base::FilePath& path, | 817 bool VerifyFile(const base::FilePath& path, |
810 const std::string& value, | 818 const std::string& value, |
811 const int64 file_size) { | 819 const int64 file_size) { |
812 std::string file_contents; | 820 std::string file_contents; |
(...skipping 2410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3223 | 3231 |
3224 // No errors this time. The download should complete successfully. | 3232 // No errors this time. The download should complete successfully. |
3225 EXPECT_FALSE(completion_observer->IsFinished()); | 3233 EXPECT_FALSE(completion_observer->IsFinished()); |
3226 completion_observer->StartObserving(); | 3234 completion_observer->StartObserving(); |
3227 download->Resume(); | 3235 download->Resume(); |
3228 completion_observer->WaitForFinished(); | 3236 completion_observer->WaitForFinished(); |
3229 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 3237 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
3230 | 3238 |
3231 EXPECT_FALSE(DidShowFileChooser()); | 3239 EXPECT_FALSE(DidShowFileChooser()); |
3232 } | 3240 } |
3241 | |
3242 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | |
3243 // Make a dangerous/UNCOMMON file. | |
3244 ChangeDangerTypeForFeedbackTest(); | |
3245 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | |
3246 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
3247 | |
3248 // Download the url and wait until the object has been completely stored. | |
3249 scoped_ptr<content::DownloadTestObserver> download_observer( | |
3250 new content::DownloadTestObserverTerminal( | |
3251 DownloadManagerForBrowser(browser()), 1, | |
3252 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); | |
3253 HistoryObserver observer(browser()->profile()); | |
3254 observer.SetFilterCallback(base::Bind(&HasDataAndName)); | |
3255 ui_test_utils::NavigateToURL(browser(), download_url); | |
3256 observer.WaitForStored(); | |
asanka
2014/03/26 18:01:30
This observer only waits for the download to begin
felt
2014/06/03 00:35:22
I think this is fixed.
| |
3257 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; | |
3258 ASSERT_TRUE(DownloadsHistoryDataCollector( | |
3259 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | |
3260 ASSERT_EQ(1u, downloads_in_database->size()); | |
3261 | |
3262 // Get the download from the DownloadManager. | |
3263 std::vector<DownloadItem*> downloads; | |
3264 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
3265 ASSERT_EQ(1u, downloads.size()); | |
3266 EXPECT_TRUE(downloads[0]->IsDangerous()); | |
3267 | |
3268 // Save fake pings for the download. | |
3269 safe_browsing::ClientDownloadReport fake_metadata; | |
3270 fake_metadata.mutable_download_request()->set_url("http://test"); | |
3271 fake_metadata.mutable_download_request()->set_length(1); | |
3272 fake_metadata.mutable_download_request()->mutable_digests()->set_sha1("hi"); | |
3273 fake_metadata.mutable_download_response()->set_verdict( | |
3274 safe_browsing::ClientDownloadResponse::UNCOMMON); | |
3275 std::string ping_request( | |
3276 fake_metadata.download_request().SerializeAsString()); | |
3277 std::string ping_response( | |
3278 fake_metadata.download_response().SerializeAsString()); | |
3279 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | |
3280 safe_browsing::DownloadProtectionService* download_protection_service = | |
3281 sb_service->download_protection_service(); | |
3282 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | |
3283 safe_browsing::DownloadProtectionService::UNCOMMON, | |
3284 downloads[0], | |
3285 ping_request, | |
3286 ping_response); | |
3287 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | |
3288 *(downloads[0]))); | |
3289 | |
3290 // Begin feedback and check that the file to is "stolen". | |
3291 download_protection_service->feedback_service()->BeginFeedbackForDownload( | |
3292 downloads[0]); | |
3293 GetDownloads(browser(), &downloads); | |
asanka
2014/03/26 18:01:30
GetDownloads() appends to the vector that's passed
felt
2014/06/03 00:35:22
Done.
| |
3294 ASSERT_TRUE(downloads.empty()); | |
3295 } | |
OLD | NEW |