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

Side by Side Diff: chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc

Issue 2905343002: Show interstitial on a password on focus ping with PHISHING verdict. (Closed)
Patch Set: nit 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" 4 #include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
5 5
6 #include "base/memory/ref_counted.h"
6 #include "base/test/scoped_feature_list.h" 7 #include "base/test/scoped_feature_list.h"
8 #include "chrome/browser/safe_browsing/ui_manager.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "components/prefs/pref_service.h"
13 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
7 #include "components/variations/variations_params_manager.h" 14 #include "components/variations/variations_params_manager.h"
8 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
10 18
11 namespace safe_browsing { 19 namespace safe_browsing {
12 20
21 namespace {
22 const char kPhishingURL[] = "http://phishing.com";
23 }
24
25 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager {
26 public:
27 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service)
28 : SafeBrowsingUIManager(service) {}
29
30 MOCK_METHOD1(DisplayBlockingPage, void(const UnsafeResource& resource));
31
32 void InvokeOnBlockingPageComplete(
33 const security_interstitials::UnsafeResource::UrlCheckCallback&
34 callback) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
36 // Note: this will delete the client object in the case of the CsdClient
Nathan Parker 2017/05/30 18:26:57 Which is the client object? The callback?
Jialiu Lin 2017/05/30 19:12:48 Oops, this comment is not relevant here. Removed.
37 // implementation.
38 if (!callback.is_null())
39 callback.Run(false);
40 }
41
42 protected:
43 virtual ~MockSafeBrowsingUIManager() {}
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager);
47 };
48
13 class MockChromePasswordProtectionService 49 class MockChromePasswordProtectionService
14 : public ChromePasswordProtectionService { 50 : public ChromePasswordProtectionService {
15 public: 51 public:
16 MockChromePasswordProtectionService() 52 explicit MockChromePasswordProtectionService(Profile* profile)
17 : ChromePasswordProtectionService(), 53 : ChromePasswordProtectionService(profile),
18 is_incognito_(false), 54 is_incognito_(false),
19 is_extended_reporting_(false), 55 is_extended_reporting_(false),
20 is_history_sync_enabled_(false) {} 56 is_history_sync_enabled_(false) {}
21 bool IsExtendedReporting() override { return is_extended_reporting_; } 57 bool IsExtendedReporting() override { return is_extended_reporting_; }
22 bool IsIncognito() override { return is_incognito_; } 58 bool IsIncognito() override { return is_incognito_; }
23 bool IsHistorySyncEnabled() override { return is_history_sync_enabled_; } 59 bool IsHistorySyncEnabled() override { return is_history_sync_enabled_; }
24 60
25 // Configures the results returned by IsExtendedReporting(), IsIncognito(), 61 // Configures the results returned by IsExtendedReporting(), IsIncognito(),
26 // and IsHistorySyncEnabled(). 62 // and IsHistorySyncEnabled().
27 void ConfigService(bool is_incognito, 63 void ConfigService(bool is_incognito,
28 bool is_extended_reporting, 64 bool is_extended_reporting,
29 bool is_history_sync_enabled) { 65 bool is_history_sync_enabled) {
30 is_incognito_ = is_incognito; 66 is_incognito_ = is_incognito;
31 is_extended_reporting_ = is_extended_reporting; 67 is_extended_reporting_ = is_extended_reporting;
32 is_history_sync_enabled_ = is_history_sync_enabled; 68 is_history_sync_enabled_ = is_history_sync_enabled;
33 } 69 }
34 70
71 void SetUIManager(scoped_refptr<SafeBrowsingUIManager> ui_manager) {
72 ui_manager_ = ui_manager;
73 }
74
75 MockSafeBrowsingUIManager* ui_manager() {
76 return static_cast<MockSafeBrowsingUIManager*>(ui_manager_.get());
77 }
78
79 void CacheVerdict(const GURL& url,
80 LoginReputationClientResponse* verdict,
81 const base::Time& receive_time) override {}
82
83 protected:
84 friend class ChromePasswordProtectionServiceTest;
85
35 private: 86 private:
36 bool is_incognito_; 87 bool is_incognito_;
37 bool is_extended_reporting_; 88 bool is_extended_reporting_;
38 bool is_history_sync_enabled_; 89 bool is_history_sync_enabled_;
39 }; 90 };
40 91
41 class ChromePasswordProtectionServiceTest : public testing::Test { 92 class ChromePasswordProtectionServiceTest
93 : public ChromeRenderViewHostTestHarness {
42 public: 94 public:
43 typedef std::map<std::string, std::string> Parameters; 95 typedef std::map<std::string, std::string> Parameters;
96
44 ChromePasswordProtectionServiceTest() {} 97 ChromePasswordProtectionServiceTest() {}
45 98
99 void SetUp() override {
100 ChromeRenderViewHostTestHarness::SetUp();
101 profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, true);
102 service_ = base::MakeUnique<MockChromePasswordProtectionService>(profile());
103 service_->SetUIManager(new testing::StrictMock<MockSafeBrowsingUIManager>(
104 SafeBrowsingService::CreateSafeBrowsingService()));
105 }
106
107 void TearDown() override {
108 base::RunLoop().RunUntilIdle();
109 service_.reset();
110 request_ = nullptr;
111 ChromeRenderViewHostTestHarness::TearDown();
112 }
113
46 // Sets up Finch trial feature parameters. 114 // Sets up Finch trial feature parameters.
47 void SetFeatureParams(const base::Feature& feature, 115 void SetFeatureParams(const base::Feature& feature,
48 const std::string& trial_name, 116 const std::string& trial_name,
49 const Parameters& params) { 117 const Parameters& params) {
50 static std::set<std::string> features = {feature.name}; 118 static std::set<std::string> features = {feature.name};
51 params_manager_.ClearAllVariationParams(); 119 params_manager_.ClearAllVariationParams();
52 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name, 120 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name,
53 params, features); 121 params, features);
54 } 122 }
55 123
56 // Creates Finch trial parameters. 124 // Creates Finch trial parameters.
57 Parameters CreateParameters(bool allowed_for_incognito, 125 Parameters CreateParameters(bool allowed_for_incognito,
58 bool allowed_for_all, 126 bool allowed_for_all,
59 bool allowed_for_extended_reporting, 127 bool allowed_for_extended_reporting,
60 bool allowed_for_history_sync) { 128 bool allowed_for_history_sync) {
61 return {{"incognito", allowed_for_incognito ? "true" : "false"}, 129 return {{"incognito", allowed_for_incognito ? "true" : "false"},
62 {"all_population", allowed_for_all ? "true" : "false"}, 130 {"all_population", allowed_for_all ? "true" : "false"},
63 {"extended_reporting", 131 {"extended_reporting",
64 allowed_for_extended_reporting ? "true" : "false"}, 132 allowed_for_extended_reporting ? "true" : "false"},
65 {"history_sync", allowed_for_history_sync ? "true" : "false"}}; 133 {"history_sync", allowed_for_history_sync ? "true" : "false"}};
66 } 134 }
67 135
136 void InitializeRequest(LoginReputationClientRequest::TriggerType type) {
137 request_ = new PasswordProtectionRequest(web_contents(), GURL(kPhishingURL),
138 GURL(), GURL(), std::string(),
139 type, service_.get(), 0);
140 }
141
142 void InitializeVerdict(LoginReputationClientResponse::VerdictType type) {
143 verdict_ = base::MakeUnique<LoginReputationClientResponse>();
144 verdict_->set_verdict_type(type);
145 }
146
147 void RequestFinished(
148 PasswordProtectionRequest* request,
149 std::unique_ptr<LoginReputationClientResponse> response) {
150 service_->RequestFinished(request, false, std::move(response));
151 }
152
68 protected: 153 protected:
69 content::TestBrowserThreadBundle thread_bundle_;
70 variations::testing::VariationParamsManager params_manager_; 154 variations::testing::VariationParamsManager params_manager_;
71 base::test::ScopedFeatureList scoped_feature_list_; 155 base::test::ScopedFeatureList scoped_feature_list_;
156 std::unique_ptr<MockChromePasswordProtectionService> service_;
157 scoped_refptr<PasswordProtectionRequest> request_;
158 std::unique_ptr<LoginReputationClientResponse> verdict_;
72 }; 159 };
73 160
74 TEST_F(ChromePasswordProtectionServiceTest, 161 TEST_F(ChromePasswordProtectionServiceTest,
75 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { 162 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) {
76 MockChromePasswordProtectionService service;
77 PasswordProtectionService::RequestOutcome reason; 163 PasswordProtectionService::RequestOutcome reason;
78 164
79 // By default kPasswordFieldOnFocusPinging feature is disabled. 165 // By default kPasswordFieldOnFocusPinging feature is disabled.
80 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 166 EXPECT_FALSE(
167 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
81 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_FEATURE_DISABLED, 168 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_FEATURE_DISABLED,
82 reason); 169 reason);
83 170
84 // Enables kPasswordFieldOnFocusPinging feature. 171 // Enables kPasswordFieldOnFocusPinging feature.
85 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); 172 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging);
86 // Creates finch trial parameters correspond to the following experiment: 173 // Creates finch trial parameters correspond to the following experiment:
87 // "name": "SBEROnlyNoIncognito", 174 // "name": "SBEROnlyNoIncognito",
88 // "params": { 175 // "params": {
89 // "incognito": "false", 176 // "incognito": "false",
90 // "extended_reporting": "true", 177 // "extended_reporting": "true",
91 // "history_sync": "false" 178 // "history_sync": "false"
92 // }, 179 // },
93 // "enable_features": [ 180 // "enable_features": [
94 // "PasswordFieldOnFocusPinging" 181 // "PasswordFieldOnFocusPinging"
95 // ] 182 // ]
96 Parameters sber_and_no_incognito = 183 Parameters sber_and_no_incognito =
97 CreateParameters(false, false, true, false); 184 CreateParameters(false, false, true, false);
98 SetFeatureParams(kPasswordFieldOnFocusPinging, "SBEROnlyNoIncognito", 185 SetFeatureParams(kPasswordFieldOnFocusPinging, "SBEROnlyNoIncognito",
99 sber_and_no_incognito); 186 sber_and_no_incognito);
100 187
101 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); 188 service_->ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
102 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 189 EXPECT_FALSE(
190 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
103 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason); 191 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason);
104 192
105 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); 193 service_->ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
106 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 194 EXPECT_FALSE(
195 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
107 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason); 196 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason);
108 197
109 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); 198 service_->ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
110 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 199 EXPECT_TRUE(
200 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
111 201
112 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); 202 service_->ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
113 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 203 EXPECT_TRUE(
204 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
114 205
115 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); 206 service_->ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
116 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 207 EXPECT_FALSE(
208 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
117 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 209 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
118 210
119 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); 211 service_->ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
120 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 212 EXPECT_FALSE(
213 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
121 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 214 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
122 215
123 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); 216 service_->ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
124 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 217 EXPECT_FALSE(
218 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
125 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 219 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
126 220
127 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); 221 service_->ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
128 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 222 EXPECT_FALSE(
223 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
129 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 224 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
130 } 225 }
131 226
132 TEST_F(ChromePasswordProtectionServiceTest, 227 TEST_F(ChromePasswordProtectionServiceTest,
133 VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) { 228 VerifyFinchControlForLowReputationPingSBERAndHistorySyncNoIncognito) {
134 MockChromePasswordProtectionService service;
135 PasswordProtectionService::RequestOutcome reason; 229 PasswordProtectionService::RequestOutcome reason;
136 230
137 // Enables kPasswordFieldOnFocusPinging feature. 231 // Enables kPasswordFieldOnFocusPinging feature.
138 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); 232 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging);
139 // Creates finch trial parameters correspond to the following experiment: 233 // Creates finch trial parameters correspond to the following experiment:
140 // "name": "SBERAndHistorySyncNoIncognito", 234 // "name": "SBERAndHistorySyncNoIncognito",
141 // "params": { 235 // "params": {
142 // "incognito": "false", 236 // "incognito": "false",
143 // "extended_reporting": "true", 237 // "extended_reporting": "true",
144 // "history_sync": "true" 238 // "history_sync": "true"
145 // }, 239 // },
146 // "enable_features": [ 240 // "enable_features": [
147 // "PasswordFieldOnFocusPinging" 241 // "PasswordFieldOnFocusPinging"
148 // ] 242 // ]
149 Parameters sber_and_sync_no_incognito = 243 Parameters sber_and_sync_no_incognito =
150 CreateParameters(false, false, true, true); 244 CreateParameters(false, false, true, true);
151 SetFeatureParams(kPasswordFieldOnFocusPinging, 245 SetFeatureParams(kPasswordFieldOnFocusPinging,
152 "SBERAndHistorySyncNoIncognito", sber_and_sync_no_incognito); 246 "SBERAndHistorySyncNoIncognito", sber_and_sync_no_incognito);
153 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); 247 service_->ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
154 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 248 EXPECT_FALSE(
249 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
155 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason); 250 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_USER_POPULATION, reason);
156 251
157 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); 252 service_->ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
158 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 253 EXPECT_TRUE(
254 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
159 255
160 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); 256 service_->ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
161 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 257 EXPECT_TRUE(
258 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
162 259
163 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); 260 service_->ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
164 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 261 EXPECT_TRUE(
262 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
165 263
166 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); 264 service_->ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
167 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 265 EXPECT_FALSE(
266 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
168 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 267 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
169 268
170 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); 269 service_->ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
171 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 270 EXPECT_FALSE(
271 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
172 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 272 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
173 273
174 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); 274 service_->ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
175 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 275 EXPECT_FALSE(
276 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
176 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 277 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
177 278
178 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); 279 service_->ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
179 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 280 EXPECT_FALSE(
281 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
180 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 282 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
181 } 283 }
182 284
183 TEST_F(ChromePasswordProtectionServiceTest, 285 TEST_F(ChromePasswordProtectionServiceTest,
184 VerifyFinchControlForLowReputationPingAllButNoIncognito) { 286 VerifyFinchControlForLowReputationPingAllButNoIncognito) {
185 MockChromePasswordProtectionService service;
186 PasswordProtectionService::RequestOutcome reason; 287 PasswordProtectionService::RequestOutcome reason;
187 288
188 // Enables kPasswordFieldOnFocusPinging feature. 289 // Enables kPasswordFieldOnFocusPinging feature.
189 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); 290 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging);
190 // Creates finch trial parameters correspond to the following experiment: 291 // Creates finch trial parameters correspond to the following experiment:
191 // "name": "AllButNoIncognito", 292 // "name": "AllButNoIncognito",
192 // "params": { 293 // "params": {
193 // "all_population": "true", 294 // "all_population": "true",
194 // "incongito": "false" 295 // "incongito": "false"
195 // }, 296 // },
196 // "enable_features": [ 297 // "enable_features": [
197 // "PasswordFieldOnFocusPinging" 298 // "PasswordFieldOnFocusPinging"
198 // ] 299 // ]
199 Parameters all_users = CreateParameters(false, true, true, true); 300 Parameters all_users = CreateParameters(false, true, true, true);
200 SetFeatureParams(kPasswordFieldOnFocusPinging, "AllButNoIncognito", 301 SetFeatureParams(kPasswordFieldOnFocusPinging, "AllButNoIncognito",
201 all_users); 302 all_users);
202 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); 303 service_->ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
203 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 304 EXPECT_TRUE(
305 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
204 306
205 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); 307 service_->ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
206 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 308 EXPECT_TRUE(
309 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
207 310
208 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); 311 service_->ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
209 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 312 EXPECT_TRUE(
313 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
210 314
211 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); 315 service_->ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
212 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 316 EXPECT_TRUE(
317 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
213 318
214 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); 319 service_->ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
215 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 320 EXPECT_FALSE(
321 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
216 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 322 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
217 323
218 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); 324 service_->ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
219 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 325 EXPECT_FALSE(
326 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
220 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 327 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
221 328
222 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); 329 service_->ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
223 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 330 EXPECT_FALSE(
331 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
224 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 332 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
225 333
226 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); 334 service_->ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
227 EXPECT_FALSE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 335 EXPECT_FALSE(
336 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
228 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason); 337 EXPECT_EQ(PasswordProtectionService::DISABLED_DUE_TO_INCOGNITO, reason);
229 } 338 }
230 339
231 TEST_F(ChromePasswordProtectionServiceTest, 340 TEST_F(ChromePasswordProtectionServiceTest,
232 VerifyFinchControlForLowReputationPingAll) { 341 VerifyFinchControlForLowReputationPingAll) {
233 MockChromePasswordProtectionService service;
234 PasswordProtectionService::RequestOutcome reason; 342 PasswordProtectionService::RequestOutcome reason;
235 343
236 // Enables kPasswordFieldOnFocusPinging feature. 344 // Enables kPasswordFieldOnFocusPinging feature.
237 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging); 345 scoped_feature_list_.InitAndEnableFeature(kPasswordFieldOnFocusPinging);
238 // Creates finch trial parameters correspond to the following experiment: 346 // Creates finch trial parameters correspond to the following experiment:
239 // "name": "All", 347 // "name": "All",
240 // "params": { 348 // "params": {
241 // "all_population": "true", 349 // "all_population": "true",
242 // "incognito": "true" 350 // "incognito": "true"
243 // }, 351 // },
244 // "enable_features": [ 352 // "enable_features": [
245 // "PasswordFieldOnFocusPinging" 353 // "PasswordFieldOnFocusPinging"
246 // ] 354 // ]
247 Parameters all_users = CreateParameters(true, true, true, true); 355 Parameters all_users = CreateParameters(true, true, true, true);
248 SetFeatureParams(kPasswordFieldOnFocusPinging, "All", all_users); 356 SetFeatureParams(kPasswordFieldOnFocusPinging, "All", all_users);
249 service.ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/); 357 service_->ConfigService(false /*incognito*/, false /*SBER*/, false /*sync*/);
250 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 358 EXPECT_TRUE(
251 service.ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/); 359 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
252 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 360 service_->ConfigService(false /*incognito*/, false /*SBER*/, true /*sync*/);
253 service.ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/); 361 EXPECT_TRUE(
254 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 362 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
255 service.ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/); 363 service_->ConfigService(false /*incognito*/, true /*SBER*/, false /*sync*/);
256 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 364 EXPECT_TRUE(
257 service.ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/); 365 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
258 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 366 service_->ConfigService(false /*incognito*/, true /*SBER*/, true /*sync*/);
259 service.ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/); 367 EXPECT_TRUE(
260 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 368 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
261 service.ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/); 369 service_->ConfigService(true /*incognito*/, false /*SBER*/, false /*sync*/);
262 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 370 EXPECT_TRUE(
263 service.ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/); 371 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
264 EXPECT_TRUE(service.IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason)); 372 service_->ConfigService(true /*incognito*/, false /*SBER*/, true /*sync*/);
373 EXPECT_TRUE(
374 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
375 service_->ConfigService(true /*incognito*/, true /*SBER*/, false /*sync*/);
376 EXPECT_TRUE(
377 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
378 service_->ConfigService(true /*incognito*/, true /*SBER*/, true /*sync*/);
379 EXPECT_TRUE(
380 service_->IsPingingEnabled(kPasswordFieldOnFocusPinging, &reason));
381 }
382
383 TEST_F(ChromePasswordProtectionServiceTest,
384 ShowInterstitialOnPasswordOnFocusPhishingVerdict) {
385 // Enables kPasswordProtectionInterstitial feature.
386 scoped_feature_list_.InitAndEnableFeature(kPasswordProtectionInterstitial);
387
388 InitializeRequest(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
389 InitializeVerdict(LoginReputationClientResponse::PHISHING);
390
391 security_interstitials::UnsafeResource resource;
392 EXPECT_CALL(*service_->ui_manager(), DisplayBlockingPage(testing::_))
393 .WillOnce(testing::SaveArg<0>(&resource));
394 RequestFinished(request_.get(), std::move(verdict_));
395 EXPECT_EQ(GURL(kPhishingURL), resource.url);
396 EXPECT_EQ(GURL(kPhishingURL), resource.original_url);
397 EXPECT_FALSE(resource.is_subresource);
398 EXPECT_EQ(SB_THREAT_TYPE_PASSWORD_PROTECTION_PHISHING_URL,
399 resource.threat_type);
400 EXPECT_EQ(ThreatSource::PASSWORD_PROTECTION_SERVICE, resource.threat_source);
401 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run());
402
403 content::BrowserThread::PostTask(
404 content::BrowserThread::IO, FROM_HERE,
405 base::BindOnce(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete,
406 service_->ui_manager(), resource.callback));
407 }
408
409 TEST_F(ChromePasswordProtectionServiceTest, NoInterstitialOnOtherVerdicts) {
410 // Enables kPasswordProtectionInterstitial feature.
411 scoped_feature_list_.InitAndEnableFeature(kPasswordProtectionInterstitial);
412
413 // For password on focus request, no interstitial shown if verdict is
414 // LOW_REPUTATION.
415 InitializeRequest(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
416 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION);
417
418 security_interstitials::UnsafeResource resource;
419 EXPECT_CALL(*service_->ui_manager(), DisplayBlockingPage(testing::_))
420 .Times(0);
421 RequestFinished(request_.get(), std::move(verdict_));
422
423 // For password on focus request, no interstitial shown if verdict is
424 // SAFE.
425 InitializeVerdict(LoginReputationClientResponse::SAFE);
426 RequestFinished(request_.get(), std::move(verdict_));
427
428 // For protected password entry request, no interstitial shown if verdict is
429 // PHISHING.
430 InitializeRequest(LoginReputationClientRequest::PASSWORD_REUSE_EVENT);
431 InitializeVerdict(LoginReputationClientResponse::PHISHING);
432 RequestFinished(request_.get(), std::move(verdict_));
433
434 // For protected password entry request, no interstitial shown if verdict is
435 // LOW_REPUTATION.
436 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION);
437 RequestFinished(request_.get(), std::move(verdict_));
438
439 // For protected password entry request, no interstitial shown if verdict is
440 // SAFE.
441 InitializeVerdict(LoginReputationClientResponse::SAFE);
442 RequestFinished(request_.get(), std::move(verdict_));
265 } 443 }
266 444
267 } // namespace safe_browsing 445 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698