| 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_; } |
| 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}; |
| 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_all, |
| 59 bool allowed_for_extended_reporting, |
| 60 bool allowed_for_history_sync) { |
| 61 return {{"incognito", allowed_for_incognito ? "true" : "false"}, |
| 62 {"all_population", allowed_for_all ? "true" : "false"}, |
| 63 {"extended_reporting", |
| 64 allowed_for_extended_reporting ? "true" : "false"}, |
| 65 {"history_sync", allowed_for_history_sync ? "true" : "false"}}; |
| 66 } |
| 67 |
| 68 protected: |
| 69 content::TestBrowserThreadBundle thread_bundle_; |
| 70 variations::testing::VariationParamsManager params_manager_; |
| 71 base::test::ScopedFeatureList scoped_feature_list_; |
| 72 }; |
| 73 |
| 74 TEST_F(ChromePasswordProtectionServiceTest, |
| 75 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { |
| 76 MockChromePasswordProtectionService service; |
| 77 // By default kLowReputationPinging feature is disabled. |
| 78 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 79 |
| 80 // Enables kLowReputationPinging feature. |
| 81 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); |
| 82 // Creates finch trial parameters correspond to the following experiment: |
| 83 // "name": "SBEROnlyNoIncognito", |
| 84 // "params": { |
| 85 // "incognito": "false", |
| 86 // "extended_reporting": "true", |
| 87 // "history_sync": "false" |
| 88 // }, |
| 89 // "enable_features": [ |
| 90 // "LowReputationPinging" |
| 91 // ] |
| 92 Parameters sber_and_no_incognito = |
| 93 CreateParameters(false, false, true, false); |
| 94 SetFeatureParams(kLowReputationPinging, "SBEROnlyNoIncognito", |
| 95 sber_and_no_incognito); |
| 96 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
| 97 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 98 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
| 99 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 100 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
| 101 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 102 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
| 103 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 104 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
| 105 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 106 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
| 107 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 108 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
| 109 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 110 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
| 111 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 112 } |
| 113 |
| 114 TEST_F(ChromePasswordProtectionServiceTest, |
| 115 VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) { |
| 116 MockChromePasswordProtectionService service; |
| 117 // By default kLowReputationPinging feature is disabled. |
| 118 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 119 |
| 120 // Enables kLowReputationPinging feature. |
| 121 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); |
| 122 // Creates finch trial parameters correspond to the following experiment: |
| 123 // "name": "SBERAndHistorySyncNoIncognito", |
| 124 // "params": { |
| 125 // "incognito": "false", |
| 126 // "extended_reporting": "true", |
| 127 // "history_sync": "true" |
| 128 // }, |
| 129 // "enable_features": [ |
| 130 // "LowReputationPinging" |
| 131 // ] |
| 132 Parameters sber_and_sync_no_incognito = |
| 133 CreateParameters(false, false, true, true); |
| 134 SetFeatureParams(kLowReputationPinging, "SBERAndHistorySyncNoIncognito", |
| 135 sber_and_sync_no_incognito); |
| 136 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
| 137 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 138 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
| 139 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 140 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
| 141 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 142 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
| 143 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 144 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
| 145 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 146 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
| 147 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 148 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
| 149 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 150 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
| 151 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 152 } |
| 153 |
| 154 TEST_F(ChromePasswordProtectionServiceTest, |
| 155 VerifyFinchControlForLowReputationPingAllButNoIncognito) { |
| 156 MockChromePasswordProtectionService service; |
| 157 // By default kLowReputationPinging feature is disabled. |
| 158 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 159 |
| 160 // Enables kLowReputationPinging feature. |
| 161 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); |
| 162 // Creates finch trial parameters correspond to the following experiment: |
| 163 // "name": "AllButNoIncognito", |
| 164 // "params": { |
| 165 // "all_population": "true", |
| 166 // "incongito": "false" |
| 167 // }, |
| 168 // "enable_features": [ |
| 169 // "LowReputationPinging" |
| 170 // ] |
| 171 Parameters all_users = CreateParameters(false, true, true, true); |
| 172 SetFeatureParams(kLowReputationPinging, "AllButNoIncognito", all_users); |
| 173 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
| 174 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 175 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
| 176 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 177 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
| 178 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 179 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
| 180 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 181 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
| 182 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 183 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
| 184 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 185 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
| 186 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 187 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
| 188 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 189 } |
| 190 |
| 191 TEST_F(ChromePasswordProtectionServiceTest, |
| 192 VerifyFinchControlForLowReputationPingAll) { |
| 193 MockChromePasswordProtectionService service; |
| 194 // By default kLowReputationPinging feature is disabled. |
| 195 EXPECT_FALSE(service.IsPingingEnabled(kLowReputationPinging)); |
| 196 |
| 197 // Enables kLowReputationPinging feature. |
| 198 scoped_feature_list_.InitAndEnableFeature(kLowReputationPinging); |
| 199 // Creates finch trial parameters correspond to the following experiment: |
| 200 // "name": "All", |
| 201 // "params": { |
| 202 // "all_population": "true", |
| 203 // "incognito": "true" |
| 204 // }, |
| 205 // "enable_features": [ |
| 206 // "LowReputationPinging" |
| 207 // ] |
| 208 Parameters all_users = CreateParameters(true, true, true, true); |
| 209 SetFeatureParams(kLowReputationPinging, "All", all_users); |
| 210 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); |
| 211 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 212 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); |
| 213 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 214 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); |
| 215 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 216 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); |
| 217 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 218 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); |
| 219 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 220 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); |
| 221 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 222 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); |
| 223 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 224 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); |
| 225 EXPECT_TRUE(service.IsPingingEnabled(kLowReputationPinging)); |
| 226 } |
| 227 |
| 228 } // namespace safe_browsing |
| OLD | NEW |