Chromium Code Reviews| Index: chrome/browser/download/download_danger_prompt_browsertest.cc |
| diff --git a/chrome/browser/download/download_danger_prompt_browsertest.cc b/chrome/browser/download/download_danger_prompt_browsertest.cc |
| index 2b33e0e7e29eed67d4d2c660cc8ffa0e157ee051..6a0a8de64b644507526d8793c3fc4a4ad4edf37a 100644 |
| --- a/chrome/browser/download/download_danger_prompt_browsertest.cc |
| +++ b/chrome/browser/download/download_danger_prompt_browsertest.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/common/safe_browsing/csd.pb.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/test/mock_download_item.h" |
| @@ -23,14 +24,15 @@ using ::testing::Eq; |
| using ::testing::Return; |
| using ::testing::ReturnRef; |
| using ::testing::SaveArg; |
| +using safe_browsing::ClientSafeBrowsingReportRequest; |
| class DownloadDangerPromptTest : public InProcessBrowserTest { |
| public: |
| DownloadDangerPromptTest() |
| - : prompt_(NULL), |
| - expected_action_(DownloadDangerPrompt::CANCEL), |
| - did_receive_callback_(false) { |
| - } |
| + : prompt_(NULL), |
| + expected_action_(DownloadDangerPrompt::CANCEL), |
| + did_receive_callback_(false), |
| + report_sent_(false) {} |
| ~DownloadDangerPromptTest() override {} |
| @@ -48,6 +50,12 @@ class DownloadDangerPromptTest : public InProcessBrowserTest { |
| void SetUpExpectations(DownloadDangerPrompt::Action expected_action) { |
| did_receive_callback_ = false; |
| expected_action_ = expected_action; |
| + report_sent_ = false; |
| + expected_safe_browsing_report_.set_url(download_.GetURL().spec()); |
| + expected_safe_browsing_report_.set_type( |
| + ClientSafeBrowsingReportRequest::MALICIOUS_DOWNLOAD_RECOVERY); |
| + expected_safe_browsing_report_.set_did_proceed( |
| + expected_action == DownloadDangerPrompt::ACCEPT); |
| SetUpDownloadItemExpectations(); |
| CreatePrompt(); |
| } |
| @@ -59,10 +67,21 @@ class DownloadDangerPromptTest : public InProcessBrowserTest { |
| EXPECT_TRUE(did_receive_callback_); |
| EXPECT_FALSE(prompt_); |
| testing::Mock::VerifyAndClearExpectations(&download_); |
| + if (report_sent_) { |
| + std::string expected_report_string; |
| + expected_safe_browsing_report_.SerializeToString(&expected_report_string); |
| + EXPECT_EQ(expected_report_string, safe_browsing_report_); |
| + } |
| } |
| void SimulatePromptAction(DownloadDangerPrompt::Action action) { |
| - prompt_->InvokeActionForTesting(action); |
| + safe_browsing_report_ = |
| + prompt()->InvokeActionForTesting(action, download().GetURL()); |
| + // If download_ changes to safe, prompt will be dismiss instead. |
| + if (!download().IsDangerous()) { |
|
Nathan Parker
2015/11/14 01:04:27
If it changes to safe, doesn't that mean did_proce
Jialiu Lin
2015/11/16 19:30:14
Resolved in person.
This is a corner case, where
|
| + expected_safe_browsing_report_.set_did_proceed(false); |
| + } |
| + report_sent_ = true; |
| } |
| content::MockDownloadItem& download() { return download_; } |
| @@ -97,6 +116,9 @@ class DownloadDangerPromptTest : public InProcessBrowserTest { |
| DownloadDangerPrompt* prompt_; |
| DownloadDangerPrompt::Action expected_action_; |
| bool did_receive_callback_; |
| + std::string safe_browsing_report_; |
| + ClientSafeBrowsingReportRequest expected_safe_browsing_report_; |
| + bool report_sent_; |
| DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); |
| }; |
| @@ -109,11 +131,15 @@ class DownloadDangerPromptTest : public InProcessBrowserTest { |
| #endif |
| IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) { |
| // ExperienceSampling: Set default actions for DownloadItem methods we need. |
| + // Intentionally makes download() url empty, such that no actual report will |
| + // be sent to server side. |
| ON_CALL(download(), GetURL()).WillByDefault(ReturnRef(GURL::EmptyGURL())); |
| ON_CALL(download(), GetReferrerUrl()) |
| .WillByDefault(ReturnRef(GURL::EmptyGURL())); |
| ON_CALL(download(), GetBrowserContext()) |
| .WillByDefault(Return(browser()->profile())); |
| + ON_CALL(download(), IsDangerous()).WillByDefault(Return(true)); |
| + ON_CALL(download(), IsDone()).WillByDefault(Return(true)); |
| OpenNewTab(); |
| @@ -137,7 +163,6 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) { |
| // If the download is in a terminal state then the dialog should DISMISS |
| // itself. |
| SetUpExpectations(DownloadDangerPrompt::DISMISS); |
| - EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| EXPECT_CALL(download(), IsDone()).WillOnce(Return(true)); |
| download().NotifyObserversDownloadUpdated(); |
| VerifyExpectations(); |
| @@ -145,7 +170,6 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) { |
| // If the download is dangerous and is not in a terminal state, don't dismiss |
| // the dialog. |
| SetUpExpectations(DownloadDangerPrompt::ACCEPT); |
| - EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| EXPECT_CALL(download(), IsDone()).WillOnce(Return(false)); |
| download().NotifyObserversDownloadUpdated(); |
| SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |