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

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

Powered by Google App Engine
This is Rietveld 408576698