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

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

Issue 2949243004: Distinguish G Suite accounts from regular gmail/googlemail accounts (Closed)
Patch Set: nits Created 3 years, 5 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/memory/ref_counted.h"
7 #include "base/test/scoped_feature_list.h" 7 #include "base/test/scoped_feature_list.h"
8 #include "chrome/browser/safe_browsing/ui_manager.h" 8 #include "chrome/browser/safe_browsing/ui_manager.h"
9 #include "chrome/browser/signin/account_fetcher_service_factory.h"
10 #include "chrome/browser/signin/account_tracker_service_factory.h"
11 #include "chrome/browser/signin/chrome_signin_client_factory.h"
12 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h"
13 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
14 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/browser/signin/test_signin_client_builder.h"
9 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
12 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
13 #include "components/safe_browsing/password_protection/password_protection_reque st.h" 22 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
23 #include "components/signin/core/browser/account_tracker_service.h"
24 #include "components/signin/core/browser/fake_account_fetcher_service.h"
25 #include "components/signin/core/browser/signin_manager.h"
26 #include "components/signin/core/browser/signin_manager_base.h"
14 #include "components/variations/variations_params_manager.h" 27 #include "components/variations/variations_params_manager.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
18 31
19 namespace safe_browsing { 32 namespace safe_browsing {
20 33
21 namespace { 34 namespace {
35
22 const char kPhishingURL[] = "http://phishing.com"; 36 const char kPhishingURL[] = "http://phishing.com";
37 const char kTestAccountID[] = "account_id";
38 const char kTestEmail[] = "foo@example.com";
39
40 std::unique_ptr<KeyedService> SigninManagerBuild(
41 content::BrowserContext* context) {
42 Profile* profile = static_cast<Profile*>(context);
43 std::unique_ptr<SigninManagerBase> service(new SigninManagerBase(
44 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile),
45 AccountTrackerServiceFactory::GetForProfile(profile)));
46 service->Initialize(NULL);
47 return std::move(service);
23 } 48 }
24 49
50 } // namespace
51
25 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { 52 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager {
26 public: 53 public:
27 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service) 54 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service)
28 : SafeBrowsingUIManager(service) {} 55 : SafeBrowsingUIManager(service) {}
29 56
30 MOCK_METHOD1(DisplayBlockingPage, void(const UnsafeResource& resource)); 57 MOCK_METHOD1(DisplayBlockingPage, void(const UnsafeResource& resource));
31 58
32 void InvokeOnBlockingPageComplete( 59 void InvokeOnBlockingPageComplete(
33 const security_interstitials::UnsafeResource::UrlCheckCallback& 60 const security_interstitials::UnsafeResource::UrlCheckCallback&
34 callback) { 61 callback) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 SafeBrowsingService::CreateSafeBrowsingService())); 130 SafeBrowsingService::CreateSafeBrowsingService()));
104 } 131 }
105 132
106 void TearDown() override { 133 void TearDown() override {
107 base::RunLoop().RunUntilIdle(); 134 base::RunLoop().RunUntilIdle();
108 service_.reset(); 135 service_.reset();
109 request_ = nullptr; 136 request_ = nullptr;
110 ChromeRenderViewHostTestHarness::TearDown(); 137 ChromeRenderViewHostTestHarness::TearDown();
111 } 138 }
112 139
140 content::BrowserContext* CreateBrowserContext() override {
141 TestingProfile::Builder builder;
142 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
143 BuildFakeProfileOAuth2TokenService);
144 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(),
145 signin::BuildTestSigninClient);
146 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
147 SigninManagerBuild);
148 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(),
149 FakeAccountFetcherServiceBuilder::BuildForTests);
150 return builder.Build().release();
151 }
152
113 // Sets up Finch trial feature parameters. 153 // Sets up Finch trial feature parameters.
114 void SetFeatureParams(const base::Feature& feature, 154 void SetFeatureParams(const base::Feature& feature,
115 const std::string& trial_name, 155 const std::string& trial_name,
116 const Parameters& params) { 156 const Parameters& params) {
117 static std::set<std::string> features = {feature.name}; 157 static std::set<std::string> features = {feature.name};
118 params_manager_.ClearAllVariationParams(); 158 params_manager_.ClearAllVariationParams();
119 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name, 159 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name,
120 params, features); 160 params, features);
121 } 161 }
122 162
(...skipping 19 matching lines...) Expand all
142 verdict_ = base::MakeUnique<LoginReputationClientResponse>(); 182 verdict_ = base::MakeUnique<LoginReputationClientResponse>();
143 verdict_->set_verdict_type(type); 183 verdict_->set_verdict_type(type);
144 } 184 }
145 185
146 void RequestFinished( 186 void RequestFinished(
147 PasswordProtectionRequest* request, 187 PasswordProtectionRequest* request,
148 std::unique_ptr<LoginReputationClientResponse> response) { 188 std::unique_ptr<LoginReputationClientResponse> response) {
149 service_->RequestFinished(request, false, std::move(response)); 189 service_->RequestFinished(request, false, std::move(response));
150 } 190 }
151 191
192 void SetUpSyncAccount(const std::string& hosted_domain) {
193 FakeAccountFetcherService* account_fetcher_service =
194 static_cast<FakeAccountFetcherService*>(
195 AccountFetcherServiceFactory::GetForProfile(profile()));
196 AccountTrackerService* account_tracker_service =
197 AccountTrackerServiceFactory::GetForProfile(profile());
198 account_fetcher_service->FakeUserInfoFetchSuccess(
199 account_tracker_service->PickAccountIdForAccount(kTestAccountID,
200 kTestEmail),
201 kTestEmail, kTestAccountID, hosted_domain, "full_name", "given_name",
202 "locale", "http://picture.example.com/picture.jpg");
203 }
204
152 protected: 205 protected:
153 variations::testing::VariationParamsManager params_manager_; 206 variations::testing::VariationParamsManager params_manager_;
154 base::test::ScopedFeatureList scoped_feature_list_; 207 base::test::ScopedFeatureList scoped_feature_list_;
155 std::unique_ptr<MockChromePasswordProtectionService> service_; 208 std::unique_ptr<MockChromePasswordProtectionService> service_;
156 scoped_refptr<PasswordProtectionRequest> request_; 209 scoped_refptr<PasswordProtectionRequest> request_;
157 std::unique_ptr<LoginReputationClientResponse> verdict_; 210 std::unique_ptr<LoginReputationClientResponse> verdict_;
158 }; 211 };
159 212
160 TEST_F(ChromePasswordProtectionServiceTest, 213 TEST_F(ChromePasswordProtectionServiceTest,
161 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { 214 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // LOW_REPUTATION. 487 // LOW_REPUTATION.
435 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION); 488 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION);
436 RequestFinished(request_.get(), std::move(verdict_)); 489 RequestFinished(request_.get(), std::move(verdict_));
437 490
438 // For protected password entry request, no interstitial shown if verdict is 491 // For protected password entry request, no interstitial shown if verdict is
439 // SAFE. 492 // SAFE.
440 InitializeVerdict(LoginReputationClientResponse::SAFE); 493 InitializeVerdict(LoginReputationClientResponse::SAFE);
441 RequestFinished(request_.get(), std::move(verdict_)); 494 RequestFinished(request_.get(), std::move(verdict_));
442 } 495 }
443 496
497 TEST_F(ChromePasswordProtectionServiceTest, VerifyGetSyncAccountType) {
498 SigninManagerBase* signin_manager = static_cast<SigninManagerBase*>(
499 SigninManagerFactory::GetForProfile(profile()));
500 signin_manager->SetAuthenticatedAccountInfo(kTestAccountID, kTestEmail);
501 SetUpSyncAccount(std::string(AccountTrackerService::kNoHostedDomainFound));
502 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GMAIL,
503 service_->GetSyncAccountType());
504
505 SetUpSyncAccount("example.edu");
506 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GSUITE,
507 service_->GetSyncAccountType());
508 }
444 } // namespace safe_browsing 509 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/chrome_password_protection_service.cc ('k') | components/safe_browsing/csd.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698