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

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: nit in test 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..144d8a03a2ccdd6f3e232a36b764abe0691218bb 100644
--- a/chrome/browser/download/download_danger_prompt_browsertest.cc
+++ b/chrome/browser/download/download_danger_prompt_browsertest.cc
@@ -8,6 +8,7 @@
#include "build/build_config.h"
#include "chrome/browser/download/download_danger_prompt.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/download_protection_service.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
@@ -32,7 +33,10 @@ using safe_browsing::ClientDownloadResponse;
using safe_browsing::ClientSafeBrowsingReportRequest;
using safe_browsing::SafeBrowsingService;
+namespace safe_browsing {
+
const char kTestDownloadUrl[] = "http://evildownload.com";
+const char kDownloadResponseToken[] = "default_token";
class DownloadDangerPromptTest : public InProcessBrowserTest {
public:
@@ -69,13 +73,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 +118,44 @@ 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));
+ safe_browsing::DownloadProtectionService::DownloadPingToken* token_obj
+ = new safe_browsing::DownloadProtectionService::DownloadPingToken(
+ token);
+ download_.SetUserData(
+ safe_browsing::DownloadProtectionService::kDownloadPingTokenKey,
+ token_obj);
}
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 +201,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 +211,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,
+ std::string(),
+ false);
EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
SimulatePromptAction(DownloadDangerPrompt::CANCEL);
VerifyExpectations(true);
@@ -194,7 +222,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 +233,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 +245,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 +258,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 +268,37 @@ 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,
+ std::string(),
+ true);
+ EXPECT_CALL(download(), IsDangerous()).WillRepeatedly(Return(true));
+ SimulatePromptAction(DownloadDangerPrompt::CANCEL);
+ VerifyExpectations(true);
}
+
+} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698