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

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

Issue 2856033002: Add finch control of user population in low reputation requests (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « chrome/browser/safe_browsing/chrome_password_protection_service.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..03ec3dbd813154bb9cf279ecb609effc8dfb39b9
--- /dev/null
+++ b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
@@ -0,0 +1,228 @@
+// Copyright 2017 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/chrome_password_protection_service.h"
+
+#include "base/test/scoped_feature_list.h"
+#include "components/variations/variations_params_manager.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace safe_browsing {
+
+class MockChromePasswordProtectionService
+ : public ChromePasswordProtectionService {
+ public:
+ MockChromePasswordProtectionService()
+ : ChromePasswordProtectionService(),
+ is_incognito_(false),
+ is_extended_reporting_(false),
+ is_history_sync_enabled_(false) {}
+ bool IsExtendedReporting() override { return is_extended_reporting_; }
+ bool IsIncognito() override { return is_incognito_; }
+ bool IsHistorySyncEnabled() override { return is_history_sync_enabled_; }
+
+ // Configures the results returned by IsExtendedReporting(), IsIncognito(),
+ // and IsHistorySyncEnabled().
+ void ConfigService(bool is_incognito,
+ bool is_extended_reporting,
+ bool is_history_sync_enabled) {
+ is_incognito_ = is_incognito;
+ is_extended_reporting_ = is_extended_reporting;
+ is_history_sync_enabled_ = is_history_sync_enabled;
+ }
+
+ private:
+ bool is_incognito_;
+ bool is_extended_reporting_;
+ bool is_history_sync_enabled_;
+};
+
+class ChromePasswordProtectionServiceTest : public testing::Test {
+ public:
+ typedef std::map<std::string, std::string> Parameters;
+ ChromePasswordProtectionServiceTest() {}
+
+ // Sets up Finch trial feature parameters.
+ void SetFeatureParams(const base::Feature& feature,
+ const std::string& trial_name,
+ const Parameters& params) {
+ static std::set<std::string> features = {feature.name};
+ params_manager_.ClearAllVariationParams();
+ params_manager_.SetVariationParamsWithFeatureAssociations(trial_name,
+ params, features);
+ }
+
+ // Creates Finch trial parameters.
+ Parameters CreateParameters(bool allowed_for_incognito,
+ bool allowed_for_all,
+ bool allowed_for_extended_reporting,
+ bool allowed_for_history_sync) {
+ return {{"incognito", allowed_for_incognito ? "true" : "false"},
+ {"all_population", allowed_for_all ? "true" : "false"},
+ {"extended_reporting",
+ allowed_for_extended_reporting ? "true" : "false"},
+ {"history_sync", allowed_for_history_sync ? "true" : "false"}};
+ }
+
+ protected:
+ content::TestBrowserThreadBundle thread_bundle_;
+ variations::testing::VariationParamsManager params_manager_;
+ base::test::ScopedFeatureList scoped_feature_list_;
+};
+
+TEST_F(ChromePasswordProtectionServiceTest,
+ VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) {
+ MockChromePasswordProtectionService service;
+ // By default kLowReputationPinging feature is disabled.
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+
+ // Enables kLowReputationPinging feature.
+ scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging);
+ // Creates finch trial parameters correspond to the following experiment:
+ // "name": "SBEROnlyNoIncognito",
+ // "params": {
+ // "incognito": "false",
+ // "extended_reporting": "true",
+ // "history_sync": "false"
+ // },
+ // "enable_features": [
+ // "LowReputationPinging"
+ // ]
+ Parameters sber_and_no_incognito =
+ CreateParameters(false, false, true, false);
+ SetFeatureParams(kLowReputationPinging, "SBEROnlyNoIncognito",
+ sber_and_no_incognito);
+ service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+}
+
+TEST_F(ChromePasswordProtectionServiceTest,
+ VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) {
+ MockChromePasswordProtectionService service;
+ // By default kLowReputationPinging feature is disabled.
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+
+ // Enables kLowReputationPinging feature.
+ scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging);
+ // Creates finch trial parameters correspond to the following experiment:
+ // "name": "SBERAndHistorySyncNoIncognito",
+ // "params": {
+ // "incognito": "false",
+ // "extended_reporting": "true",
+ // "history_sync": "true"
+ // },
+ // "enable_features": [
+ // "LowReputationPinging"
+ // ]
+ Parameters sber_and_sync_no_incognito =
+ CreateParameters(false, false, true, true);
+ SetFeatureParams(kLowReputationPinging, "SBERAndHistorySyncNoIncognito",
+ sber_and_sync_no_incognito);
+ service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+}
+
+TEST_F(ChromePasswordProtectionServiceTest,
+ VerifyFinchControlForLowReputationPingAllButNoIncognito) {
+ MockChromePasswordProtectionService service;
+ // By default kLowReputationPinging feature is disabled.
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+
+ // Enables kLowReputationPinging feature.
+ scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging);
+ // Creates finch trial parameters correspond to the following experiment:
+ // "name": "AllButNoIncognito",
+ // "params": {
+ // "all_population": "true",
+ // "incongito": "false"
+ // },
+ // "enable_features": [
+ // "LowReputationPinging"
+ // ]
+ Parameters all_users = CreateParameters(false, true, true, true);
+ SetFeatureParams(kLowReputationPinging, "AllButNoIncognito", all_users);
+ service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+}
+
+TEST_F(ChromePasswordProtectionServiceTest,
+ VerifyFinchControlForLowReputationPingAll) {
+ MockChromePasswordProtectionService service;
+ // By default kLowReputationPinging feature is disabled.
+ EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging));
+
+ // Enables kLowReputationPinging feature.
+ scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging);
+ // Creates finch trial parameters correspond to the following experiment:
+ // "name": "All",
+ // "params": {
+ // "all_population": "true",
+ // "incognito": "true"
+ // },
+ // "enable_features": [
+ // "LowReputationPinging"
+ // ]
+ Parameters all_users = CreateParameters(true, true, true, true);
+ SetFeatureParams(kLowReputationPinging, "All", all_users);
+ service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+ service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
+ EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging));
+}
+
+} // namespace safe_browsing
« no previous file with comments | « chrome/browser/safe_browsing/chrome_password_protection_service.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698