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 28 matching lines...) Expand all Loading... | |
39 #include "chrome/browser/download/download_test_file_activity_observer.h" | 39 #include "chrome/browser/download/download_test_file_activity_observer.h" |
40 #include "chrome/browser/extensions/extension_install_prompt.h" | 40 #include "chrome/browser/extensions/extension_install_prompt.h" |
41 #include "chrome/browser/extensions/extension_service.h" | 41 #include "chrome/browser/extensions/extension_service.h" |
42 #include "chrome/browser/history/download_row.h" | 42 #include "chrome/browser/history/download_row.h" |
43 #include "chrome/browser/history/history_service.h" | 43 #include "chrome/browser/history/history_service.h" |
44 #include "chrome/browser/history/history_service_factory.h" | 44 #include "chrome/browser/history/history_service_factory.h" |
45 #include "chrome/browser/infobars/infobar_service.h" | 45 #include "chrome/browser/infobars/infobar_service.h" |
46 #include "chrome/browser/net/url_request_mock_util.h" | 46 #include "chrome/browser/net/url_request_mock_util.h" |
47 #include "chrome/browser/profiles/profile.h" | 47 #include "chrome/browser/profiles/profile.h" |
48 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 48 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
49 #include "chrome/browser/safe_browsing/download_feedback_service.h" | |
50 #include "chrome/browser/safe_browsing/download_protection_service.h" | |
51 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
49 #include "chrome/browser/ui/browser.h" | 52 #include "chrome/browser/ui/browser.h" |
50 #include "chrome/browser/ui/browser_commands.h" | 53 #include "chrome/browser/ui/browser_commands.h" |
51 #include "chrome/browser/ui/browser_finder.h" | 54 #include "chrome/browser/ui/browser_finder.h" |
52 #include "chrome/browser/ui/browser_list.h" | 55 #include "chrome/browser/ui/browser_list.h" |
53 #include "chrome/browser/ui/browser_tabstrip.h" | 56 #include "chrome/browser/ui/browser_tabstrip.h" |
54 #include "chrome/browser/ui/browser_window.h" | 57 #include "chrome/browser/ui/browser_window.h" |
55 #include "chrome/browser/ui/chrome_pages.h" | 58 #include "chrome/browser/ui/chrome_pages.h" |
56 #include "chrome/browser/ui/host_desktop.h" | 59 #include "chrome/browser/ui/host_desktop.h" |
57 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 60 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
58 #include "chrome/common/chrome_paths.h" | 61 #include "chrome/common/chrome_paths.h" |
59 #include "chrome/common/pref_names.h" | 62 #include "chrome/common/pref_names.h" |
63 #include "chrome/common/safe_browsing/csd.pb.h" | |
60 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
61 #include "chrome/test/base/in_process_browser_test.h" | 65 #include "chrome/test/base/in_process_browser_test.h" |
62 #include "chrome/test/base/test_switches.h" | 66 #include "chrome/test/base/test_switches.h" |
63 #include "chrome/test/base/ui_test_utils.h" | 67 #include "chrome/test/base/ui_test_utils.h" |
64 #include "components/infobars/core/confirm_infobar_delegate.h" | 68 #include "components/infobars/core/confirm_infobar_delegate.h" |
65 #include "components/infobars/core/infobar.h" | 69 #include "components/infobars/core/infobar.h" |
66 #include "content/public/browser/download_interrupt_reasons.h" | 70 #include "content/public/browser/download_interrupt_reasons.h" |
67 #include "content/public/browser/download_item.h" | 71 #include "content/public/browser/download_item.h" |
68 #include "content/public/browser/download_manager.h" | 72 #include "content/public/browser/download_manager.h" |
69 #include "content/public/browser/download_save_info.h" | 73 #include "content/public/browser/download_save_info.h" |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 } | 798 } |
795 | 799 |
796 static void ExpectWindowCountAfterDownload(size_t expected) { | 800 static void ExpectWindowCountAfterDownload(size_t expected) { |
797 EXPECT_EQ(expected, chrome::GetTotalBrowserCount()); | 801 EXPECT_EQ(expected, chrome::GetTotalBrowserCount()); |
798 } | 802 } |
799 | 803 |
800 void EnableFileChooser(bool enable) { | 804 void EnableFileChooser(bool enable) { |
801 file_activity_observer_->EnableFileChooser(enable); | 805 file_activity_observer_->EnableFileChooser(enable); |
802 } | 806 } |
803 | 807 |
808 void SetDangerTypeForNewDownloads(bool modify, | |
809 content::DownloadDangerType danger_type) { | |
810 file_activity_observer_->SetDangerTypeForNewDownloads(modify, danger_type); | |
811 } | |
812 | |
804 bool DidShowFileChooser() { | 813 bool DidShowFileChooser() { |
805 return file_activity_observer_->TestAndResetDidShowFileChooser(); | 814 return file_activity_observer_->TestAndResetDidShowFileChooser(); |
806 } | 815 } |
807 | 816 |
808 // Checks that |path| is has |file_size| bytes, and matches the |value| | 817 // Checks that |path| is has |file_size| bytes, and matches the |value| |
809 // string. | 818 // string. |
810 bool VerifyFile(const base::FilePath& path, | 819 bool VerifyFile(const base::FilePath& path, |
811 const std::string& value, | 820 const std::string& value, |
812 const int64 file_size) { | 821 const int64 file_size) { |
813 std::string file_contents; | 822 std::string file_contents; |
(...skipping 2410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3224 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_GZipWithNoContent) { | 3233 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_GZipWithNoContent) { |
3225 ASSERT_TRUE(test_server()->Start()); | 3234 ASSERT_TRUE(test_server()->Start()); |
3226 GURL url(test_server()->GetURL("files/downloads/empty.bin")); | 3235 GURL url(test_server()->GetURL("files/downloads/empty.bin")); |
3227 // Downloading the same URL twice causes the second request to be served from | 3236 // Downloading the same URL twice causes the second request to be served from |
3228 // cached (with a high probability). This test verifies that that doesn't | 3237 // cached (with a high probability). This test verifies that that doesn't |
3229 // happen regardless of whether the request is served via the cache or from | 3238 // happen regardless of whether the request is served via the cache or from |
3230 // the network. | 3239 // the network. |
3231 DownloadAndWait(browser(), url); | 3240 DownloadAndWait(browser(), url); |
3232 DownloadAndWait(browser(), url); | 3241 DownloadAndWait(browser(), url); |
3233 } | 3242 } |
3243 | |
3244 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | |
asanka
2014/06/05 19:20:12
Let's wrap this in #if defined(FULL_SAFE_BROWSING)
felt
2014/06/07 15:45:05
Done.
| |
3245 // Make a dangerous/UNCOMMON file. | |
3246 SetDangerTypeForNewDownloads(true, | |
3247 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT); | |
3248 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | |
3249 GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file)); | |
3250 scoped_ptr<content::DownloadTestObserverInterrupted> observer( | |
3251 new content::DownloadTestObserverInterrupted( | |
3252 DownloadManagerForBrowser(browser()), 1, | |
3253 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | |
3254 ui_test_utils::NavigateToURLWithDisposition( | |
3255 browser(), | |
3256 GURL(download_url), | |
3257 NEW_BACKGROUND_TAB, | |
3258 ui_test_utils::BROWSER_TEST_NONE); | |
3259 observer->WaitForFinished(); | |
3260 | |
3261 // Get the download from the DownloadManager. | |
3262 std::vector<DownloadItem*> downloads; | |
3263 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
3264 ASSERT_EQ(1u, downloads.size()); | |
3265 EXPECT_TRUE(downloads[0]->IsDangerous()); | |
3266 | |
3267 // Save fake pings for the download. | |
3268 safe_browsing::ClientDownloadReport fake_metadata; | |
3269 fake_metadata.mutable_download_request()->set_url("http://test"); | |
3270 fake_metadata.mutable_download_request()->set_length(1); | |
3271 fake_metadata.mutable_download_request()->mutable_digests()->set_sha1("hi"); | |
3272 fake_metadata.mutable_download_response()->set_verdict( | |
3273 safe_browsing::ClientDownloadResponse::UNCOMMON); | |
3274 std::string ping_request( | |
3275 fake_metadata.download_request().SerializeAsString()); | |
3276 std::string ping_response( | |
3277 fake_metadata.download_response().SerializeAsString()); | |
3278 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | |
3279 safe_browsing::DownloadProtectionService* download_protection_service = | |
3280 sb_service->download_protection_service(); | |
3281 download_protection_service->feedback_service()->MaybeStorePingsForDownload( | |
3282 safe_browsing::DownloadProtectionService::UNCOMMON, | |
3283 downloads[0], | |
3284 ping_request, | |
3285 ping_response); | |
3286 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | |
3287 *(downloads[0]))); | |
3288 | |
3289 // Begin feedback and check that the file is "stolen". | |
3290 download_protection_service->feedback_service()->BeginFeedbackForDownload( | |
3291 downloads[0]); | |
3292 std::vector<DownloadItem*> updated_downloads; | |
3293 GetDownloads(browser(), &updated_downloads); | |
3294 ASSERT_TRUE(updated_downloads.empty()); | |
3295 | |
3296 SetDangerTypeForNewDownloads(false, | |
3297 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | |
3298 } | |
OLD | NEW |