Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: chrome/browser/download/download_browsertest.cc

Issue 1784433003: Track CTR of uncommon download warning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add one more test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_browsertest.cc
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index 7c933fb50f9540bb128359458f5d073aaefc019f..7311dda68ae1d17e9a2f0bed441658d8a0afc90d 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
+#include "chrome/browser/download/download_commands.h"
#include "chrome/browser/download/download_crx_util.h"
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_item_model.h"
@@ -75,6 +76,7 @@
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#include "components/prefs/pref_service.h"
+#include "content/public/browser/download_danger_type.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
@@ -1076,6 +1078,81 @@ class DownloadTest : public InProcessBrowserTest {
scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_;
};
+class FakeDownloadProtectionService
+ : public safe_browsing::DownloadProtectionService {
+ public:
+ FakeDownloadProtectionService()
+ : safe_browsing::DownloadProtectionService(nullptr, nullptr) {}
+
+ void CheckClientDownload(DownloadItem* download_item,
+ const CheckDownloadCallback& callback) override {
+ callback.Run(
+ safe_browsing::DownloadProtectionService::UNCOMMON);
+ }
+};
+
+class FakeSafeBrowsingService : public safe_browsing::SafeBrowsingService {
+ public:
+ FakeSafeBrowsingService() {}
+
+ safe_browsing::DownloadProtectionService* CreateDownloadProtectionService(
+ net::URLRequestContextGetter* not_used_request_context_getter) override {
+ return new FakeDownloadProtectionService();
+ }
+
+ std::string GetDownloadReport() const { return report_; }
+
+ protected:
+ ~FakeSafeBrowsingService() override {}
+
+ void SendSerializedDownloadReport(const std::string& report) override {
+ report_ = report;
+ }
+
+ std::string report_;
+};
+
+// Factory that creates FakeSafeBrowsingService instances.
+class TestSafeBrowsingServiceFactory
Nico 2016/03/21 16:03:42 This is 8th TestSafeBrowsingServiceFactory we have
+ : public safe_browsing::SafeBrowsingServiceFactory {
+ public:
+ TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {}
+ ~TestSafeBrowsingServiceFactory() override {}
+
+ safe_browsing::SafeBrowsingService* CreateSafeBrowsingService() override {
+ DCHECK(!fake_safe_browsing_service_);
+ fake_safe_browsing_service_ = new FakeSafeBrowsingService();
+ return fake_safe_browsing_service_.get();
+ }
+
+ scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service() {
+ return fake_safe_browsing_service_;
+ }
+
+ private:
+ scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service_;
+};
+
+class DownloadTestWithFakeSafeBrowsing : public DownloadTest {
+ public:
+ DownloadTestWithFakeSafeBrowsing()
+ : test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {}
+
+ void SetUp() override {
+ safe_browsing::SafeBrowsingService::RegisterFactory(
+ test_safe_browsing_factory_.get());
+ DownloadTest::SetUp();
+ }
+
+ void TearDown() override {
+ safe_browsing::SafeBrowsingService::RegisterFactory(nullptr);
+ DownloadTest::TearDown();
+ }
+
+ protected:
+ scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_;
+};
+
// NOTES:
//
// Files for these tests are found in DIR_TEST_DATA (currently
@@ -3270,6 +3347,68 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) {
GetDownloads(browser(), &updated_downloads);
ASSERT_TRUE(updated_downloads.empty());
}
+
+IN_PROC_BROWSER_TEST_F(
+ DownloadTestWithFakeSafeBrowsing,
+ SendUncommonDownloadReportIfUserProceed) {
+ browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
+ true);
+ // Make a dangerous file.
+ GURL download_url(
+ net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
+ scoped_ptr<content::DownloadTestObserver> dangerous_observer(
+ DangerousDownloadWaiter(
+ browser(), 1,
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT));
+ ui_test_utils::NavigateToURL(browser(), download_url);
+ dangerous_observer->WaitForFinished();
+
+ std::vector<DownloadItem*> downloads;
+ DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
+ ASSERT_EQ(1u, downloads.size());
+ DownloadItem* download = downloads[0];
+ DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP);
+
+ safe_browsing::ClientSafeBrowsingReportRequest actual_report;
+ actual_report.ParseFromString(
+ test_safe_browsing_factory_->fake_safe_browsing_service()
+ ->GetDownloadReport());
+ EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest::
+ DANGEROUS_DOWNLOAD_WARNING,
+ actual_report.type());
+ EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON,
+ actual_report.download_verdict());
+ EXPECT_EQ(download_url.spec(), actual_report.url());
+ EXPECT_TRUE(actual_report.did_proceed());
+
+ download->Cancel(true);
+}
+
+IN_PROC_BROWSER_TEST_F(
+ DownloadTestWithFakeSafeBrowsing,
+ NoUncommonDownloadReportWithoutUserProceed) {
+ browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
+ true);
+ // Make a dangerous file.
+ GURL download_url(
+ net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
+ scoped_ptr<content::DownloadTestObserver> dangerous_observer(
+ DangerousDownloadWaiter(
+ browser(), 1,
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT));
+ ui_test_utils::NavigateToURL(browser(), download_url);
+ dangerous_observer->WaitForFinished();
+
+ std::vector<DownloadItem*> downloads;
+ DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
+ ASSERT_EQ(1u, downloads.size());
+ DownloadItem* download = downloads[0];
+ DownloadCommands(download).ExecuteCommand(DownloadCommands::DISCARD);
+
+ EXPECT_TRUE(
+ test_safe_browsing_factory_->fake_safe_browsing_service()
+ ->GetDownloadReport().empty());
+}
#endif // FULL_SAFE_BROWSING
class DownloadTestWithShelf : public DownloadTest {
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698