Commit 90fcdb0a authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin] Add ConsentLevel to SetPrimaryAccount in test utils

First part of adding ConsentLevel support to identity_test_utils.
This CL merges two separate methods SetPrimaryAccount and
SetUnconsentedPrimaryAccount into a single one that takes ConsentLevel
as a parameter.

Bug: 1046746
Change-Id: I93f7811414b7c1ee583237681c567a881560ce23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401140
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807046}
parent f46065ea
...@@ -161,9 +161,10 @@ class SigninReauthViewControllerBrowserTest : public InProcessBrowserTest { ...@@ -161,9 +161,10 @@ class SigninReauthViewControllerBrowserTest : public InProcessBrowserTest {
https_server(), kChallengePath); https_server(), kChallengePath);
https_server()->StartAcceptingConnections(); https_server()->StartAcceptingConnections();
account_id_ = signin::SetUnconsentedPrimaryAccount(identity_manager(), account_id_ =
"alice@gmail.com") signin::SetPrimaryAccount(identity_manager(), "alice@gmail.com",
.account_id; signin::ConsentLevel::kNotRequired)
.account_id;
reauth_result_loop_ = std::make_unique<base::RunLoop>(); reauth_result_loop_ = std::make_unique<base::RunLoop>();
InProcessBrowserTest::SetUpOnMainThread(); InProcessBrowserTest::SetUpOnMainThread();
......
...@@ -491,7 +491,8 @@ class IdentityManager : public KeyedService, ...@@ -491,7 +491,8 @@ class IdentityManager : public KeyedService,
private: private:
// These test helpers need to use some of the private methods below. // These test helpers need to use some of the private methods below.
friend CoreAccountInfo SetPrimaryAccount(IdentityManager* identity_manager, friend CoreAccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
const std::string& email); const std::string& email,
ConsentLevel consent_level);
friend CoreAccountInfo SetUnconsentedPrimaryAccount( friend CoreAccountInfo SetUnconsentedPrimaryAccount(
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
......
...@@ -361,12 +361,14 @@ IdentityTestEnvironment::identity_manager_observer() { ...@@ -361,12 +361,14 @@ IdentityTestEnvironment::identity_manager_observer() {
CoreAccountInfo IdentityTestEnvironment::SetPrimaryAccount( CoreAccountInfo IdentityTestEnvironment::SetPrimaryAccount(
const std::string& email) { const std::string& email) {
return signin::SetPrimaryAccount(identity_manager(), email); return signin::SetPrimaryAccount(identity_manager(), email,
ConsentLevel::kSync);
} }
CoreAccountInfo IdentityTestEnvironment::SetUnconsentedPrimaryAccount( CoreAccountInfo IdentityTestEnvironment::SetUnconsentedPrimaryAccount(
const std::string& email) { const std::string& email) {
return signin::SetUnconsentedPrimaryAccount(identity_manager(), email); return signin::SetPrimaryAccount(identity_manager(), email,
ConsentLevel::kNotRequired);
} }
void IdentityTestEnvironment::SetRefreshTokenForPrimaryAccount() { void IdentityTestEnvironment::SetRefreshTokenForPrimaryAccount() {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "components/signin/public/base/list_accounts_test_utils.h" #include "components/signin/public/base/list_accounts_test_utils.h"
#include "components/signin/public/identity_manager/consent_level.h" #include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_mutator.h"
#include "components/signin/public/identity_manager/test_identity_manager_observer.h" #include "components/signin/public/identity_manager/test_identity_manager_observer.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
...@@ -113,42 +114,35 @@ AccountInfo EnsureAccountExists(AccountTrackerService* account_tracker_service, ...@@ -113,42 +114,35 @@ AccountInfo EnsureAccountExists(AccountTrackerService* account_tracker_service,
} // namespace } // namespace
CoreAccountInfo SetPrimaryAccount(IdentityManager* identity_manager, CoreAccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
const std::string& email) { const std::string& email,
DCHECK(!identity_manager->HasPrimaryAccount()); ConsentLevel consent_level) {
PrimaryAccountManager* primary_account_manager = // TODO(https://crbug.com/1046746): Change this to ConsentLevel::kNotRequired
identity_manager->GetPrimaryAccountManager(); // after fixing all callers.
DCHECK(!primary_account_manager->IsAuthenticated()); DCHECK(!identity_manager->HasPrimaryAccount(consent_level));
AccountInfo account_info =
EnsureAccountExists(identity_manager->GetAccountTrackerService(), email);
DCHECK(!account_info.gaia.empty());
primary_account_manager->SignIn(email);
DCHECK(primary_account_manager->IsAuthenticated());
DCHECK(identity_manager->HasPrimaryAccount());
return identity_manager->GetPrimaryAccountInfo();
}
CoreAccountInfo SetUnconsentedPrimaryAccount(IdentityManager* identity_manager,
const std::string& email) {
DCHECK(!identity_manager->HasPrimaryAccount(ConsentLevel::kNotRequired));
AccountInfo account_info = AccountInfo account_info =
EnsureAccountExists(identity_manager->GetAccountTrackerService(), email); EnsureAccountExists(identity_manager->GetAccountTrackerService(), email);
DCHECK(!account_info.gaia.empty()); DCHECK(!account_info.gaia.empty());
PrimaryAccountManager* primary_account_manager = PrimaryAccountMutator* primary_account_mutator =
identity_manager->GetPrimaryAccountManager(); identity_manager->GetPrimaryAccountMutator();
primary_account_manager->SetUnconsentedPrimaryAccountInfo(account_info); // TODO(https://crbug.com/1046746): Refactor PrimaryAccountMutator API and
// pass ConsentLevel directly there.
switch (consent_level) {
case ConsentLevel::kSync:
DCHECK(
primary_account_mutator->SetPrimaryAccount(account_info.account_id));
break;
case ConsentLevel::kNotRequired:
primary_account_mutator->SetUnconsentedPrimaryAccount(
account_info.account_id);
break;
}
DCHECK(identity_manager->HasPrimaryAccount(ConsentLevel::kNotRequired)); DCHECK(identity_manager->HasPrimaryAccount(consent_level));
DCHECK_EQ(account_info.gaia, DCHECK_EQ(account_info.gaia,
identity_manager identity_manager->GetPrimaryAccountInfo(consent_level).gaia);
->GetPrimaryAccountInfo(signin::ConsentLevel::kNotRequired) return identity_manager->GetPrimaryAccountInfo(consent_level);
.gaia);
return identity_manager->GetPrimaryAccountInfo(
signin::ConsentLevel::kNotRequired);
} }
void SetRefreshTokenForPrimaryAccount(IdentityManager* identity_manager, void SetRefreshTokenForPrimaryAccount(IdentityManager* identity_manager,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/consent_level.h"
namespace network { namespace network {
class TestURLLoaderFactory; class TestURLLoaderFactory;
...@@ -50,13 +51,10 @@ class IdentityManager; ...@@ -50,13 +51,10 @@ class IdentityManager;
// PrimaryAccountManager callbacks for signin success. Blocks until the primary // PrimaryAccountManager callbacks for signin success. Blocks until the primary
// account is set. Returns the CoreAccountInfo of the newly-set account. // account is set. Returns the CoreAccountInfo of the newly-set account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
CoreAccountInfo SetPrimaryAccount(IdentityManager* identity_manager, CoreAccountInfo SetPrimaryAccount(
const std::string& email); IdentityManager* identity_manager,
const std::string& email,
// As above, but adds an "unconsented" primary account. See ./README.md for ConsentLevel consent_level = ConsentLevel::kSync);
// the distinction between primary and unconsented primary accounts.
CoreAccountInfo SetUnconsentedPrimaryAccount(IdentityManager* identity_manager,
const std::string& email);
// Sets a refresh token for the primary account (which must already be set). // Sets a refresh token for the primary account (which must already be set).
// Blocks until the refresh token is set. If |token_value| is empty a default // Blocks until the refresh token is set. If |token_value| is empty a default
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment