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

Unified Diff: chrome/browser/safe_browsing/unverified_download_field_trial_unittest.cc

Issue 1409003002: [SafeBrowsing] Block dangerous unchecked downloads based on a Finch trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/safe_browsing/unverified_download_field_trial_unittest.cc
diff --git a/chrome/browser/safe_browsing/unverified_download_field_trial_unittest.cc b/chrome/browser/safe_browsing/unverified_download_field_trial_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae7eabca0833eeff8ba58eb6e9efcbe8a118b4cd
--- /dev/null
+++ b/chrome/browser/safe_browsing/unverified_download_field_trial_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/unverified_download_field_trial.h"
+
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/metrics/field_trial.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/safe_browsing/download_protection_util.h"
+#include "components/variations/variations_associated_data.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace safe_browsing {
+
+namespace {
+
+const base::FilePath::CharType kSafeFilename[] = FILE_PATH_LITERAL("foo.txt");
+const base::FilePath::CharType kHandledFilename[] =
+ FILE_PATH_LITERAL("foo.exe");
+
+} // namespace
+
+TEST(UnverifiedDownloadFieldTrialTest, Assumptions) {
+ EXPECT_TRUE(safe_browsing::download_protection_util::IsSupportedBinaryFile(
+ base::FilePath(kHandledFilename)));
mattm 2015/10/21 00:26:05 also verify the kSafeFilename is not a supported b
asanka 2015/10/22 21:55:12 Done.
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, AllowAll) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kAllowUncheckedDangerousDownloads);
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, DisallowDangerous) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kDisallowUncheckedDangerousDownloads);
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, DisableAll) {
+ base::FieldTrialList field_trial_list(nullptr);
+ base::FieldTrialList::CreateFieldTrial(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableAll);
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, DisableByParam) {
+ base::FieldTrialList field_trial_list(nullptr);
+ std::map<std::string, std::string> param_map;
+ param_map[kUnverifiedDownloadFieldTrialBlacklistParam] = ".abc,.def";
+ param_map[kUnverifiedDownloadFieldTrialWhitelistParam] = ".xyz";
+ variations::AssociateVariationParams(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableByParameter, param_map);
+ base::FieldTrialList::CreateFieldTrial(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableByParameter);
+
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.xyz"))));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.abc"))));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.def"))));
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, DisableSBTypesAndByParameter) {
+ base::FieldTrialList field_trial_list(nullptr);
+ std::map<std::string, std::string> param_map;
+ param_map[kUnverifiedDownloadFieldTrialBlacklistParam] = ".abc,.def";
+ param_map[kUnverifiedDownloadFieldTrialWhitelistParam] = ".xyz";
mattm 2015/10/21 00:26:05 Also test that you can override a SB type by white
asanka 2015/10/22 21:55:12 Done and good point.
+ variations::AssociateVariationParams(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter, param_map);
+ base::FieldTrialList::CreateFieldTrial(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter);
+
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.xyz"))));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.abc"))));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(FILE_PATH_LITERAL("foo.def"))));
+}
+
+TEST(UnverifiedDownloadFieldTrialTest, DisableBySBTypes) {
+ base::FieldTrialList field_trial_list(nullptr);
+ base::FieldTrialList::CreateFieldTrial(
+ kUnverifiedDownloadFieldTrialName,
+ kUnverifiedDownloadFieldTrialDisableSBTypes);
+ EXPECT_TRUE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kSafeFilename)));
+ EXPECT_FALSE(safe_browsing::IsUnverifiedDownloadAllowedByFieldTrial(
+ base::FilePath(kHandledFilename)));
+}
+
+} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698