Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" | |
| 5 | |
| 6 #include "base/test/scoped_feature_list.h" | |
| 7 #include "components/variations/variations_params_manager.h" | |
| 8 #include "content/public/test/test_browser_thread_bundle.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace safe_browsing { | |
| 12 | |
| 13 class MockChromePasswordProtectionService | |
| 14 : public ChromePasswordProtectionService { | |
| 15 public: | |
| 16 MockChromePasswordProtectionService() | |
| 17 : ChromePasswordProtectionService(), | |
| 18 is_incognito_(false), | |
| 19 is_extended_reporting_(false), | |
| 20 is_history_sync_enabled_(false) {} | |
| 21 bool IsExtendedReporting() override { return is_extended_reporting_; } | |
|
Nathan Parker
2017/05/05 20:58:22
nit: order these the same as how they're listed be
| |
| 22 bool IsIncognito() override { return is_incognito_; } | |
| 23 bool IsHistorySyncEnabled() override { return is_history_sync_enabled_; } | |
| 24 | |
| 25 // Configures the results returned by IsExtendedReporting(), IsIncognito(), | |
| 26 // and IsHistorySyncEnabled(). | |
| 27 void ConfigService(bool is_incognito, | |
| 28 bool is_extended_reporting, | |
| 29 bool is_history_sync_enabled) { | |
| 30 is_incognito_ = is_incognito; | |
| 31 is_extended_reporting_ = is_extended_reporting; | |
| 32 is_history_sync_enabled_ = is_history_sync_enabled; | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 bool is_incognito_; | |
| 37 bool is_extended_reporting_; | |
| 38 bool is_history_sync_enabled_; | |
| 39 }; | |
| 40 | |
| 41 class ChromePasswordProtectionServiceTest : public testing::Test { | |
| 42 public: | |
| 43 typedef std::map<std::string, std::string> Parameters; | |
| 44 ChromePasswordProtectionServiceTest() {} | |
| 45 | |
| 46 // Sets up Finch trial feature parameters. | |
| 47 void SetFeatureParams(const base::Feature& feature, | |
| 48 const std::string& trial_name, | |
| 49 const Parameters& params) { | |
| 50 static std::set<std::string> features = {feature.name}; | |
|
Nathan Parker
2017/05/05 20:58:22
Why is this static? This could cause tests to have
| |
| 51 params_manager_.ClearAllVariationParams(); | |
| 52 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name, | |
| 53 params, features); | |
| 54 } | |
| 55 | |
| 56 // Creates Finch trial parameters. | |
| 57 Parameters CreateParameters(bool allowed_for_incognito, | |
| 58 bool allowed_for_extended_reporting, | |
| 59 bool allowed_for_history_sync) { | |
| 60 return {{"incognito", allowed_for_incognito ? "true" : "false"}, | |
| 61 {"extended_reporting", | |
| 62 allowed_for_extended_reporting ? "true" : "false"}, | |
| 63 {"history_sync", allowed_for_history_sync ? "true" : "false"}}; | |
| 64 } | |
| 65 | |
| 66 protected: | |
| 67 content::TestBrowserThreadBundle thread_bundle_; | |
| 68 variations::testing::VariationParamsManager params_manager_; | |
| 69 base::test::ScopedFeatureList scoped_feature_list_; | |
| 70 }; | |
| 71 | |
| 72 TEST_F(ChromePasswordProtectionServiceTest, | |
| 73 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { | |
| 74 MockChromePasswordProtectionService service; | |
| 75 // By default kLowReputationPinging feature is disabled. | |
| 76 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 77 | |
| 78 // Enables kLowReputationPinging feature. | |
| 79 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); | |
| 80 // Creates finch trial parameters correspond to the following experiment: | |
| 81 // "name": "LowReputationPingSBEROnlyNoIncognito", | |
| 82 // "params": { | |
| 83 // "incognito": "false", | |
| 84 // "extended_reporting": "true", | |
| 85 // "history_sync": "false" | |
| 86 // }, | |
| 87 // "enable_features": [ | |
| 88 // "LowReputationPinging" | |
| 89 // ] | |
| 90 Parameters sber_and_no_incognito = CreateParameters(false, true, false); | |
| 91 SetFeatureParams(kLowReputationPinging, "SBEROnlyNoIncognito", | |
| 92 sber_and_no_incognito); | |
| 93 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 94 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 95 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 96 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 97 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 98 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 99 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 100 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 101 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 102 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 103 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 104 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 105 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 106 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 107 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 108 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 109 } | |
| 110 | |
| 111 TEST_F(ChromePasswordProtectionServiceTest, | |
| 112 VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) { | |
| 113 MockChromePasswordProtectionService service; | |
| 114 // By default kLowReputationPinging feature is disabled. | |
| 115 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 116 | |
| 117 // Enables kLowReputationPinging feature. | |
| 118 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); | |
| 119 // Creates finch trial parameters correspond to the following experiment: | |
| 120 // "name": "LowReputationPingSBERAndHistorySyncNoIncognito", | |
| 121 // "params": { | |
| 122 // "incognito": "false", | |
| 123 // "extended_reporting": "true", | |
| 124 // "history_sync": "true" | |
| 125 // }, | |
| 126 // "enable_features": [ | |
| 127 // "LowReputationPinging" | |
| 128 // ] | |
| 129 Parameters sber_and_sync_no_incognito = CreateParameters(false, true, true); | |
| 130 SetFeatureParams(kLowReputationPinging, "SBERAndHistorySyncNoIncognito", | |
| 131 sber_and_sync_no_incognito); | |
| 132 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 133 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 134 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 135 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 136 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 137 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 138 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 139 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 140 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 141 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 142 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 143 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 144 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 145 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 146 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 147 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 148 } | |
| 149 | |
| 150 TEST_F(ChromePasswordProtectionServiceTest, | |
| 151 VerifyFinchControlForLowReputationPingAll) { | |
| 152 MockChromePasswordProtectionService service; | |
| 153 // By default kLowReputationPinging feature is disabled. | |
| 154 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 155 | |
| 156 // Enables kLowReputationPinging feature. | |
| 157 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); | |
| 158 // Creates finch trial parameters correspond to the following experiment: | |
| 159 // "name": "LowReputationPingAll", | |
| 160 // "params": { | |
| 161 // "incognito": "true", | |
| 162 // "extended_reporting": "true", | |
| 163 // "history_sync": "true" | |
| 164 // }, | |
| 165 // "enable_features": [ | |
| 166 // "LowReputationPinging" | |
| 167 // ] | |
| 168 Parameters all_users = CreateParameters(true, true, true); | |
| 169 SetFeatureParams(kLowReputationPinging, "All", all_users); | |
| 170 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 171 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 172 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 173 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 174 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 175 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 176 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 177 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 178 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); | |
| 179 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 180 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); | |
| 181 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 182 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); | |
| 183 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 184 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); | |
| 185 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); | |
| 186 } | |
| 187 | |
| 188 } // namespace safe_browsing | |
| OLD | NEW |