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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
index f496f39066755f4fb368384931a3ec70c045753c..a1e29dde5daa7c48655e5a4780c90c57de80e8a2 100644
--- a/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
+++ b/chrome/browser/safe_browsing/chrome_password_protection_service_unittest.cc
@@ -6,11 +6,23 @@
#include "base/memory/ref_counted.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/safe_browsing/ui_manager.h"
+#include "chrome/browser/signin/account_fetcher_service_factory.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
+#include "chrome/browser/signin/chrome_signin_client_factory.h"
+#include "chrome/browser/signin/fake_account_fetcher_service_builder.h"
+#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
+#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/password_protection/password_protection_request.h"
+#include "components/signin/core/browser/account_tracker_service.h"
+#include "components/signin/core/browser/fake_account_fetcher_service.h"
+#include "components/signin/core/browser/signin_manager.h"
#include "components/variations/variations_params_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -19,9 +31,23 @@
namespace safe_browsing {
namespace {
+
const char kPhishingURL[] = "http://phishing.com";
+
+std::unique_ptr<KeyedService> SigninManagerBuild(
+ content::BrowserContext* context) {
+ Profile* profile = static_cast<Profile*>(context);
+ std::unique_ptr<SigninManager> service(new SigninManager(
+ ChromeSigninClientFactory::GetInstance()->GetForProfile(profile),
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
+ AccountTrackerServiceFactory::GetForProfile(profile),
+ GaiaCookieManagerServiceFactory::GetForProfile(profile)));
+ service->Initialize(NULL);
+ return std::move(service);
}
+} // namespace
+
class MockSafeBrowsingUIManager : public SafeBrowsingUIManager {
public:
explicit MockSafeBrowsingUIManager(SafeBrowsingService* service)
@@ -110,6 +136,19 @@ class ChromePasswordProtectionServiceTest
ChromeRenderViewHostTestHarness::TearDown();
}
+ content::BrowserContext* CreateBrowserContext() override {
+ TestingProfile::Builder builder;
+ builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
+ BuildFakeProfileOAuth2TokenService);
+ builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(),
+ signin::BuildTestSigninClient);
+ builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
+ SigninManagerBuild);
+ builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(),
+ FakeAccountFetcherServiceBuilder::BuildForTests);
+ return builder.Build().release();
+ }
+
// Sets up Finch trial feature parameters.
void SetFeatureParams(const base::Feature& feature,
const std::string& trial_name,
@@ -149,6 +188,15 @@ class ChromePasswordProtectionServiceTest
service_->RequestFinished(request, false, std::move(response));
}
+ void SetUpSyncAccount(const std::string& hosted_domain) {
+ FakeAccountFetcherService* account_fetcher_service =
+ static_cast<FakeAccountFetcherService*>(
+ AccountFetcherServiceFactory::GetForProfile(profile()));
+ account_fetcher_service->FakeUserInfoFetchSuccess(
+ "gaia", "foo@example.com", "gaia", hosted_domain, "full_name",
+ "given_name", "locale", "http://picture.example.com/picture.jpg");
+ }
+
protected:
variations::testing::VariationParamsManager params_manager_;
base::test::ScopedFeatureList scoped_feature_list_;
@@ -441,4 +489,27 @@ TEST_F(ChromePasswordProtectionServiceTest, NoInterstitialOnOtherVerdicts) {
RequestFinished(request_.get(), std::move(verdict_));
}
+TEST_F(ChromePasswordProtectionServiceTest, VerifyGetSyncAccountType) {
+ // AccountTrackerService* account_tracker_service =
+ // AccountTrackerServiceFactory::GetForProfile(profile());
+ // account_tracker_service->SeedAccountInfo("gaia", "foo@example.com");
+ SigninManager* signin_manager =
+ SigninManagerFactory::GetForProfile(profile());
+ signin_manager->SetAuthenticatedAccountInfo("gaia", "foo@example.com");
+ SetUpSyncAccount(std::string(AccountTrackerService::kNoHostedDomainFound));
+ EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GMAIL,
+ service_->GetSyncAccountType());
+
+ SetUpSyncAccount(std::string());
+ EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GMAIL,
+ service_->GetSyncAccountType());
+
+ SetUpSyncAccount("google.com");
+ EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::GOOGLE,
+ service_->GetSyncAccountType());
+
+ SetUpSyncAccount("example.edu");
+ EXPECT_EQ(LoginReputationClientRequest::PasswordReuseEvent::DASHER,
+ service_->GetSyncAccountType());
+}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698