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

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: Rebase 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/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"
14 #include "components/variations/variations_params_manager.h" 26 #include "components/variations/variations_params_manager.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
18 30
19 namespace safe_browsing { 31 namespace safe_browsing {
20 32
21 namespace { 33 namespace {
34
22 const char kPhishingURL[] = "http://phishing.com"; 35 const char kPhishingURL[] = "http://phishing.com";
36
37 std::unique_ptr<KeyedService> SigninManagerBuild(
38 content::BrowserContext* context) {
39 Profile* profile = static_cast<Profile*>(context);
40 std::unique_ptr<SigninManager> service(new SigninManager(
41 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile),
42 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
43 AccountTrackerServiceFactory::GetForProfile(profile),
44 GaiaCookieManagerServiceFactory::GetForProfile(profile)));
45 service->Initialize(NULL);
46 return std::move(service);
23 } 47 }
24 48
49 } // namespace
50
25 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { 51 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager {
26 public: 52 public:
27 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service) 53 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service)
28 : SafeBrowsingUIManager(service) {} 54 : SafeBrowsingUIManager(service) {}
29 55
30 MOCK_METHOD1(DisplayBlockingPage, void(const UnsafeResource& resource)); 56 MOCK_METHOD1(DisplayBlockingPage, void(const UnsafeResource& resource));
31 57
32 void InvokeOnBlockingPageComplete( 58 void InvokeOnBlockingPageComplete(
33 const security_interstitials::UnsafeResource::UrlCheckCallback& 59 const security_interstitials::UnsafeResource::UrlCheckCallback&
34 callback) { 60 callback) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 SafeBrowsingService::CreateSafeBrowsingService())); 129 SafeBrowsingService::CreateSafeBrowsingService()));
104 } 130 }
105 131
106 void TearDown() override { 132 void TearDown() override {
107 base::RunLoop().RunUntilIdle(); 133 base::RunLoop().RunUntilIdle();
108 service_.reset(); 134 service_.reset();
109 request_ = nullptr; 135 request_ = nullptr;
110 ChromeRenderViewHostTestHarness::TearDown(); 136 ChromeRenderViewHostTestHarness::TearDown();
111 } 137 }
112 138
139 content::BrowserContext* CreateBrowserContext() override {
140 TestingProfile::Builder builder;
141 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
142 BuildFakeProfileOAuth2TokenService);
143 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(),
144 signin::BuildTestSigninClient);
145 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
146 SigninManagerBuild);
147 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(),
148 FakeAccountFetcherServiceBuilder::BuildForTests);
149 return builder.Build().release();
150 }
151
113 // Sets up Finch trial feature parameters. 152 // Sets up Finch trial feature parameters.
114 void SetFeatureParams(const base::Feature& feature, 153 void SetFeatureParams(const base::Feature& feature,
115 const std::string& trial_name, 154 const std::string& trial_name,
116 const Parameters& params) { 155 const Parameters& params) {
117 static std::set<std::string> features = {feature.name}; 156 static std::set<std::string> features = {feature.name};
118 params_manager_.ClearAllVariationParams(); 157 params_manager_.ClearAllVariationParams();
119 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name, 158 params_manager_.SetVariationParamsWithFeatureAssociations(trial_name,
120 params, features); 159 params, features);
121 } 160 }
122 161
(...skipping 19 matching lines...) Expand all
142 verdict_ = base::MakeUnique<LoginReputationClientResponse>(); 181 verdict_ = base::MakeUnique<LoginReputationClientResponse>();
143 verdict_->set_verdict_type(type); 182 verdict_->set_verdict_type(type);
144 } 183 }
145 184
146 void RequestFinished( 185 void RequestFinished(
147 PasswordProtectionRequest* request, 186 PasswordProtectionRequest* request,
148 std::unique_ptr<LoginReputationClientResponse> response) { 187 std::unique_ptr<LoginReputationClientResponse> response) {
149 service_->RequestFinished(request, false, std::move(response)); 188 service_->RequestFinished(request, false, std::move(response));
150 } 189 }
151 190
191 void SetUpSyncAccount(const std::string& hosted_domain) {
192 FakeAccountFetcherService* account_fetcher_service =
193 static_cast<FakeAccountFetcherService*>(
194 AccountFetcherServiceFactory::GetForProfile(profile()));
195 account_fetcher_service->FakeUserInfoFetchSuccess(
196 "gaia", "foo@example.com", "gaia", hosted_domain, "full_name",
197 "given_name", "locale", "http://picture.example.com/picture.jpg");
198 }
199
152 protected: 200 protected:
153 variations::testing::VariationParamsManager params_manager_; 201 variations::testing::VariationParamsManager params_manager_;
154 base::test::ScopedFeatureList scoped_feature_list_; 202 base::test::ScopedFeatureList scoped_feature_list_;
155 std::unique_ptr<MockChromePasswordProtectionService> service_; 203 std::unique_ptr<MockChromePasswordProtectionService> service_;
156 scoped_refptr<PasswordProtectionRequest> request_; 204 scoped_refptr<PasswordProtectionRequest> request_;
157 std::unique_ptr<LoginReputationClientResponse> verdict_; 205 std::unique_ptr<LoginReputationClientResponse> verdict_;
158 }; 206 };
159 207
160 TEST_F(ChromePasswordProtectionServiceTest, 208 TEST_F(ChromePasswordProtectionServiceTest,
161 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) { 209 VerifyFinchControlForLowReputationPingSBEROnlyNoIncognito) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // LOW_REPUTATION. 482 // LOW_REPUTATION.
435 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION); 483 InitializeVerdict(LoginReputationClientResponse::LOW_REPUTATION);
436 RequestFinished(request_.get(), std::move(verdict_)); 484 RequestFinished(request_.get(), std::move(verdict_));
437 485
438 // For protected password entry request, no interstitial shown if verdict is 486 // For protected password entry request, no interstitial shown if verdict is
439 // SAFE. 487 // SAFE.
440 InitializeVerdict(LoginReputationClientResponse::SAFE); 488 InitializeVerdict(LoginReputationClientResponse::SAFE);
441 RequestFinished(request_.get(), std::move(verdict_)); 489 RequestFinished(request_.get(), std::move(verdict_));
442 } 490 }
443 491
492 TEST_F(ChromePasswordProtectionServiceTest, VerifyGetSyncAccountType) {
493 // AccountTrackerService* account_tracker_service =
494 // AccountTrackerServiceFactory::GetForProfile(profile());
495 // account_tracker_service->SeedAccountInfo("gaia", "foo@example.com");
496 SigninManager* signin_manager =
497 SigninManagerFactory::GetForProfile(profile());
498 signin_manager->SetAuthenticatedAccountInfo("gaia", "foo@example.com");
499 SetUpSyncAccount(std::string(AccountTrackerService::kNoHostedDomainFound));
500 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GMAIL,
501 service_->GetSyncAccountType());
502
503 SetUpSyncAccount(std::string());
504 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GMAIL,
505 service_->GetSyncAccountType());
506
507 SetUpSyncAccount("google.com");
508 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GOOGLE,
509 service_->GetSyncAccountType());
510
511 SetUpSyncAccount("example.edu");
512 EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::DASHER,
513 service_->GetSyncAccountType());
514 }
444 } // namespace safe_browsing 515 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698