Commit 66ef2a87 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

IdentityManager: Relax some constraints on test APIs

Various test APIs around IdentityManager currently DCHECK preconditions
when invoked (e.g., clearing the primary account DCHECKs that there is
a primary account). However, unittests for GCM that will shortly be
converted intentionally stress-test the system in various exceptional
ways, e.g., invoking the flow that the primary account was cleared when
there is no primary account. To accomodate porting those unittests
without having to reduce their coverage, this CL relaxes the constraints
on the relevant IdentityManager test APIs.

Bug: 798699, 809923
Change-Id: Ibe2db519d0e231ea707ad09b329d6abc6ad7a9d2
Reviewed-on: https://chromium-review.googlesource.com/1149864
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578615}
parent 257ad1da
...@@ -39,8 +39,8 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -39,8 +39,8 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// already be set). Blocks until the refresh token is set. // already be set). Blocks until the refresh token is set.
void SetInvalidRefreshTokenForPrimaryAccount(); void SetInvalidRefreshTokenForPrimaryAccount();
// Removes any refresh token for the primary account (which must already be // Removes any refresh token for the primary account, if present. Blocks until
// set). Blocks until the refresh token is removed. // the refresh token is removed.
void RemoveRefreshTokenForPrimaryAccount(); void RemoveRefreshTokenForPrimaryAccount();
// Makes the primary account available for the given email address, generating // Makes the primary account available for the given email address, generating
...@@ -51,10 +51,10 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -51,10 +51,10 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// Returns the AccountInfo of the newly-available account. // Returns the AccountInfo of the newly-available account.
AccountInfo MakePrimaryAccountAvailable(const std::string& email); AccountInfo MakePrimaryAccountAvailable(const std::string& email);
// Clears the primary account, with |policy| used to determine whether to keep // Clears the primary account if present, with |policy| used to determine
// or remove all accounts. On non-ChromeOS, results in the firing of the // whether to keep or remove all accounts. On non-ChromeOS, results in the
// IdentityManager and SigninManager callbacks for signout. Blocks until the // firing of the IdentityManager and SigninManager callbacks for signout.
// primary account is cleared. // Blocks until the primary account is cleared.
void ClearPrimaryAccount( void ClearPrimaryAccount(
ClearPrimaryAccountPolicy policy = ClearPrimaryAccountPolicy::DEFAULT); ClearPrimaryAccountPolicy policy = ClearPrimaryAccountPolicy::DEFAULT);
...@@ -74,9 +74,9 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { ...@@ -74,9 +74,9 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// disclaimer at top of file re: direct usage. // disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForAccount(const std::string& account_id); void SetInvalidRefreshTokenForAccount(const std::string& account_id);
// Removes any refresh token for the given account (which must already be // Removes any refresh token that is present for the given account. Blocks
// available). Blocks until the refresh token is removed. NOTE: See disclaimer // until the refresh token is removed.
// at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForAccount(const std::string& account_id); void RemoveRefreshTokenForAccount(const std::string& account_id);
// When this is set, access token requests will be automatically granted with // When this is set, access token requests will be automatically granted with
......
...@@ -177,7 +177,9 @@ void SetInvalidRefreshTokenForPrimaryAccount( ...@@ -177,7 +177,9 @@ void SetInvalidRefreshTokenForPrimaryAccount(
void RemoveRefreshTokenForPrimaryAccount( void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager) { IdentityManager* identity_manager) {
DCHECK(identity_manager->HasPrimaryAccount()); if (!identity_manager->HasPrimaryAccount())
return;
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id; std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
RemoveRefreshTokenForAccount(token_service, identity_manager, account_id); RemoveRefreshTokenForAccount(token_service, identity_manager, account_id);
...@@ -203,7 +205,8 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager, ...@@ -203,7 +205,8 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager,
// synchronously with IdentityManager. // synchronously with IdentityManager.
NOTREACHED(); NOTREACHED();
#else #else
DCHECK(identity_manager->HasPrimaryAccount()); if (!identity_manager->HasPrimaryAccount())
return;
base::RunLoop run_loop; base::RunLoop run_loop;
OneShotIdentityManagerObserver signout_observer( OneShotIdentityManagerObserver signout_observer(
...@@ -274,7 +277,8 @@ void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, ...@@ -274,7 +277,8 @@ void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
DCHECK(identity_manager->HasAccountWithRefreshToken(account_id)); if (!identity_manager->HasAccountWithRefreshToken(account_id))
return;
base::RunLoop run_loop; base::RunLoop run_loop;
OneShotIdentityManagerObserver token_updated_observer( OneShotIdentityManagerObserver token_updated_observer(
......
...@@ -45,11 +45,11 @@ enum class ClearPrimaryAccountPolicy { ...@@ -45,11 +45,11 @@ enum class ClearPrimaryAccountPolicy {
class IdentityManager; class IdentityManager;
// Sets the primary account for the given email address, generating a GAIA ID // Sets the primary account (which must not already be set) to the given email
// that corresponds uniquely to that email address. On non-ChromeOS, results in // address, generating a GAIA ID that corresponds uniquely to that email
// the firing of the IdentityManager and SigninManager callbacks for signin // address. On non-ChromeOS, results in the firing of the IdentityManager and
// success. Blocks until the primary account is set. Returns the AccountInfo // SigninManager callbacks for signin success. Blocks until the primary account
// of the newly-set account. // is set. Returns the AccountInfo 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.
AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager, AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager,
IdentityManager* identity_manager, IdentityManager* identity_manager,
...@@ -62,24 +62,25 @@ void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service, ...@@ -62,24 +62,25 @@ void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Sets a special invalid refresh token for the primary account (which must // Sets a special invalid refresh token for the primary account (which must
// already be set). Blocks until the refresh token is set. NOTE: See disclaimer // already be set). Blocks until the refresh token is set.
// at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForPrimaryAccount( void SetInvalidRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Removes any refresh token for the primary account (which must already be // Removes any refresh token for the primary account, if present. Blocks until
// set). Blocks until the refresh token is removed. NOTE: See disclaimer at top // the refresh token is removed.
// of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForPrimaryAccount( void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Makes the primary account available for the given email address, generating a // Makes the primary account (which must not already be set) available for the
// GAIA ID and refresh token that correspond uniquely to that email address. On // given email address, generating a GAIA ID and refresh token that correspond
// non-ChromeOS, results in the firing of the IdentityManager and SigninManager // uniquely to that email address. On non-ChromeOS, results in the firing of the
// callbacks for signin success. Blocks until the primary account is available. // IdentityManager and SigninManager callbacks for signin success. Blocks until
// Returns the AccountInfo of the newly-available account. // the primary account is available. Returns the AccountInfo of the
// newly-available account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
AccountInfo MakePrimaryAccountAvailable( AccountInfo MakePrimaryAccountAvailable(
SigninManagerBase* signin_manager, SigninManagerBase* signin_manager,
...@@ -87,10 +88,10 @@ AccountInfo MakePrimaryAccountAvailable( ...@@ -87,10 +88,10 @@ AccountInfo MakePrimaryAccountAvailable(
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
// Clears the primary account, with |policy| used to determine whether to keep // Clears the primary account if present, with |policy| used to determine
// or remove all accounts. On non-ChromeOS, results in the firing of the // whether to keep or remove all accounts. On non-ChromeOS, results in the
// IdentityManager and SigninManager callbacks for signout. Blocks until the // firing of the IdentityManager and SigninManager callbacks for signout. Blocks
// primary account is cleared. // until the primary account is cleared.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void ClearPrimaryAccount( void ClearPrimaryAccount(
SigninManagerBase* signin_manager, SigninManagerBase* signin_manager,
...@@ -121,9 +122,10 @@ void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, ...@@ -121,9 +122,10 @@ void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& account_id); const std::string& account_id);
// Removes any refresh token for the given account (which must already be // Removes any refresh token that is present for the given account. Blocks until
// available). Blocks until the refresh token is removed. NOTE: See disclaimer // the refresh token is removed. Is a no-op if no refresh token is present for
// at top of file re: direct usage. // the given account.
// NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& account_id); const std::string& account_id);
......
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