| 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 49eeccfd342bdb53c2e7467aba6b67aeb3b1dea4..e09a22d324f4e3d1a99a5d89bd9f7130f57a49c7 100644
|
| --- a/chrome/browser/download/download_danger_prompt_browsertest.cc
|
| +++ b/chrome/browser/download/download_danger_prompt_browsertest.cc
|
| @@ -3,6 +3,7 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/files/file_path.h"
|
| #include "base/macros.h"
|
| #include "build/build_config.h"
|
| @@ -21,6 +22,7 @@
|
| #include "content/public/test/mock_download_item.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/ui_base_switches.h"
|
| #include "url/gurl.h"
|
|
|
| using ::testing::_;
|
| @@ -29,23 +31,48 @@ using ::testing::Eq;
|
| using ::testing::Return;
|
| using ::testing::ReturnRef;
|
| using ::testing::SaveArg;
|
| -using safe_browsing::ClientDownloadResponse;
|
| -using safe_browsing::ClientSafeBrowsingReportRequest;
|
| -using safe_browsing::SafeBrowsingService;
|
|
|
| namespace safe_browsing {
|
|
|
| +namespace {
|
| +
|
| const char kTestDownloadUrl[] = "http://evildownload.com";
|
| const char kDownloadResponseToken[] = "default_token";
|
|
|
| -class DownloadDangerPromptTest : public InProcessBrowserTest {
|
| +// An enum to parameterize the tests so that the tests can be run with and
|
| +// without the secondary-ui-md flag.
|
| +enum class SecondaryUiMd {
|
| + ENABLED,
|
| + DISABLED,
|
| +};
|
| +
|
| +// Parameterised test name generator for tests depending on whether
|
| +// secondary-ui-md is enabled.
|
| +struct PrintSecondaryUiMdStatus {
|
| + template <class ParamType>
|
| + std::string operator()(const testing::TestParamInfo<ParamType>& info) const {
|
| + switch (info.param) {
|
| + case SecondaryUiMd::ENABLED:
|
| + return "SecondaryUiMdEnabled";
|
| + case SecondaryUiMd::DISABLED:
|
| + return "SecondaryUiMdDisabled";
|
| + }
|
| + NOTREACHED();
|
| + return std::string();
|
| + }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +class DownloadDangerPromptTest
|
| + : public InProcessBrowserTest,
|
| + public ::testing::WithParamInterface<SecondaryUiMd> {
|
| public:
|
| DownloadDangerPromptTest()
|
| : prompt_(nullptr),
|
| expected_action_(DownloadDangerPrompt::CANCEL),
|
| did_receive_callback_(false),
|
| - test_safe_browsing_factory_(
|
| - new safe_browsing::TestSafeBrowsingServiceFactory()) {}
|
| + test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {}
|
|
|
| ~DownloadDangerPromptTest() override {}
|
|
|
| @@ -59,6 +86,13 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
|
| InProcessBrowserTest::TearDown();
|
| }
|
|
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + // TODO(crbug.com/630357): Remove when secondary-ui-md is enabled by default
|
| + // on all platforms.
|
| + if (GetParam() == SecondaryUiMd::ENABLED)
|
| + command_line->AppendSwitch(switches::kExtendMdToSecondaryUi);
|
| + }
|
| +
|
| // Opens a new tab and waits for navigations to finish. If there are pending
|
| // navigations, the constrained prompt might be dismissed when the navigation
|
| // completes.
|
| @@ -123,12 +157,10 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
|
| 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);
|
| + DownloadProtectionService::DownloadPingToken* token_obj =
|
| + new DownloadProtectionService::DownloadPingToken(token);
|
| + download_.SetUserData(DownloadProtectionService::kDownloadPingTokenKey,
|
| + token_obj);
|
| }
|
|
|
| void SetUpSafeBrowsingReportExpectations(
|
| @@ -172,8 +204,7 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
|
| DownloadDangerPrompt* prompt_;
|
| DownloadDangerPrompt::Action expected_action_;
|
| bool did_receive_callback_;
|
| - std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory>
|
| - test_safe_browsing_factory_;
|
| + std::unique_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_;
|
| std::string expected_serialized_report_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest);
|
| @@ -185,7 +216,7 @@ class DownloadDangerPromptTest : public InProcessBrowserTest {
|
| #else
|
| #define MAYBE_TestAll TestAll
|
| #endif
|
| -IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
|
| +IN_PROC_BROWSER_TEST_P(DownloadDangerPromptTest, MAYBE_TestAll) {
|
| // ExperienceSampling: Set default actions for DownloadItem methods we need.
|
| GURL download_url(kTestDownloadUrl);
|
| ON_CALL(download(), GetURL()).WillByDefault(ReturnRef(download_url));
|
| @@ -302,4 +333,12 @@ IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
|
| VerifyExpectations(true);
|
| }
|
|
|
| +// Prefix for test instantiations intentionally left blank since the test
|
| +// fixture class has a single parameterization.
|
| +INSTANTIATE_TEST_CASE_P(,
|
| + DownloadDangerPromptTest,
|
| + ::testing::Values(SecondaryUiMd::ENABLED,
|
| + SecondaryUiMd::DISABLED),
|
| + PrintSecondaryUiMdStatus());
|
| +
|
| } // namespace safe_browsing
|
|
|