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

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

Issue 2029903002: Add token field to ClientSafeBrowsingReportReqeust (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak comments Created 4 years, 6 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
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 b893f5664de71fe5adda6caeca3c4de5cd82de89..5bc0145af2faa931c126859a971a7c60d9cf224b 100644
--- a/chrome/browser/download/download_danger_prompt_browsertest.cc
+++ b/chrome/browser/download/download_danger_prompt_browsertest.cc
@@ -33,6 +33,7 @@ using safe_browsing::ClientSafeBrowsingReportRequest;
using safe_browsing::SafeBrowsingService;
const char kTestDownloadUrl[] = "http://evildownload.com";
+const char kDownloadResponseToken[] = "default_token";
class DownloadDangerPromptTest : public InProcessBrowserTest {
public:
@@ -69,13 +70,18 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
void SetUpExpectations(
const DownloadDangerPrompt::Action& expected_action,
const content::DownloadDangerType& danger_type,
- const ClientDownloadResponse::Verdict& download_verdict) {
+ const ClientDownloadResponse::Verdict& download_verdict,
+ const std::string& token,
+ bool from_download_api) {
did_receive_callback_ = false;
expected_action_ = expected_action;
- SetUpDownloadItemExpectations(danger_type);
+ SetUpDownloadItemExpectations(danger_type, token);
SetUpSafeBrowsingReportExpectations(
- expected_action == DownloadDangerPrompt::ACCEPT, download_verdict);
- CreatePrompt();
+ expected_action == DownloadDangerPrompt::ACCEPT,
+ download_verdict,
+ token,
+ from_download_api);
+ CreatePrompt(from_download_api);
}
void VerifyExpectations(bool should_send_report) {
@@ -109,29 +115,40 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
private:
void SetUpDownloadItemExpectations(
- const content::DownloadDangerType& danger_type) {
+ const content::DownloadDangerType& danger_type,
+ const std::string& token) {
EXPECT_CALL(download_, GetFileNameToReportUser()).WillRepeatedly(Return(
base::FilePath(FILE_PATH_LITERAL("evil.exe"))));
EXPECT_CALL(download_, GetDangerType()).WillRepeatedly(Return(danger_type));
+ EXPECT_CALL(download_, GetDownloadPingToken())
+ .WillRepeatedly(Return(token));
}
void SetUpSafeBrowsingReportExpectations(
bool did_proceed,
- const ClientDownloadResponse::Verdict& download_verdict) {
+ const ClientDownloadResponse::Verdict& download_verdict,
+ const std::string& token,
+ bool from_download_api) {
ClientSafeBrowsingReportRequest expected_report;
expected_report.set_url(GURL(kTestDownloadUrl).spec());
- expected_report.set_type(
- ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY);
+ if (from_download_api)
+ expected_report.set_type(
+ ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_BY_API);
+ else
+ expected_report.set_type(
+ ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY);
expected_report.set_download_verdict(download_verdict);
expected_report.set_did_proceed(did_proceed);
+ if (!token.empty())
+ expected_report.set_token(token);
expected_report.SerializeToString(&expected_serialized_report_);
}
- void CreatePrompt() {
+ void CreatePrompt(bool from_download_api) {
prompt_ = DownloadDangerPrompt::Create(
&download_,
browser()->tab_strip_model()->GetActiveWebContents(),
- false,
+ from_download_api,
base::Bind(&DownloadDangerPromptTest::PromptCallback, this));
content::RunAllPendingInMessageLoop();
}
@@ -177,7 +194,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// Clicking the Accept button should invoke the ACCEPT action.
SetUpExpectations(DownloadDangerPrompt::ACCEPT,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
- ClientDownloadResponse::DANGEROUS);
+ ClientDownloadResponse::DANGEROUS,
+ kDownloadResponseToken,
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
SimulatePromptAction(DownloadDangerPrompt::ACCEPT);
VerifyExpectations(true);
@@ -185,7 +204,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// Clicking the Cancel button should invoke the CANCEL action.
SetUpExpectations(DownloadDangerPrompt::CANCEL,
content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT,
- ClientDownloadResponse::UNCOMMON);
+ ClientDownloadResponse::UNCOMMON,
+ base::EmptyString(),
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
SimulatePromptAction(DownloadDangerPrompt::CANCEL);
VerifyExpectations(true);
@@ -194,7 +215,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// dialog should DISMISS itself.
SetUpExpectations(DownloadDangerPrompt::DISMISS,
content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED,
- ClientDownloadResponse::POTENTIALLY_UNWANTED);
+ ClientDownloadResponse::POTENTIALLY_UNWANTED,
+ kDownloadResponseToken,
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(false));
download().NotifyObserversDownloadUpdated();
VerifyExpectations(false);
@@ -203,7 +226,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// itself.
SetUpExpectations(DownloadDangerPrompt::DISMISS,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST,
- ClientDownloadResponse::DANGEROUS_HOST);
+ ClientDownloadResponse::DANGEROUS_HOST,
+ kDownloadResponseToken,
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
EXPECT_CALL(download(), IsDone()).WillRepeatedly(Return(true));
download().NotifyObserversDownloadUpdated();
@@ -213,7 +238,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// the dialog.
SetUpExpectations(DownloadDangerPrompt::ACCEPT,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT,
- ClientDownloadResponse::DANGEROUS);
+ ClientDownloadResponse::DANGEROUS,
+ kDownloadResponseToken,
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
EXPECT_CALL(download(), IsDone()).WillRepeatedly(Return(false));
download().NotifyObserversDownloadUpdated();
@@ -224,7 +251,9 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
// If the download is not dangerous, no report will be sent.
SetUpExpectations(DownloadDangerPrompt::ACCEPT,
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- ClientDownloadResponse::SAFE);
+ ClientDownloadResponse::SAFE,
+ kDownloadResponseToken,
+ false);
SimulatePromptAction(DownloadDangerPrompt::ACCEPT);
VerifyExpectations(false);
@@ -232,7 +261,35 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
OpenNewTab();
SetUpExpectations(DownloadDangerPrompt::DISMISS,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
- ClientDownloadResponse::DANGEROUS);
+ ClientDownloadResponse::DANGEROUS,
+ kDownloadResponseToken,
+ false);
chrome::CloseTab(browser());
VerifyExpectations(false);
+
+ // If file is downloaded through download api, a confirm download dialog
+ // instead of a recovery dialog is shown. Clicking the Accept button should
+ // invoke the ACCEPT action, a report will be sent with type
+ // DANGEROUS_DOWNLOAD_BY_API.
+ SetUpExpectations(DownloadDangerPrompt::ACCEPT,
+ content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
+ ClientDownloadResponse::DANGEROUS,
+ kDownloadResponseToken,
+ true);
+ EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
+ SimulatePromptAction(DownloadDangerPrompt::ACCEPT);
+ VerifyExpectations(true);
+
+ // If file is downloaded through download api, a confirm download dialog
+ // instead of a recovery dialog is shown. Clicking the Cancel button should
+ // invoke the CANCEL action, a report will be sent with type
+ // DANGEROUS_DOWNLOAD_BY_API.
+ SetUpExpectations(DownloadDangerPrompt::CANCEL,
+ content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT,
+ ClientDownloadResponse::UNCOMMON,
+ base::EmptyString(),
+ true);
+ EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
+ SimulatePromptAction(DownloadDangerPrompt::CANCEL);
+ VerifyExpectations(true);
}

Powered by Google App Engine
This is Rietveld 408576698