Commit b9b47487 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[IdentityManager] Add DCHECK to make error case less cryptic in tests

When tests set the refresh token for a given account, IdentityManager
must already know about the account (i.e., the account must be
seeded in AccountTrackerService). However, the error that occurs if
tests invoke SetRefreshTokenForAccount() rather than
MakeAccountAvailable() is cryptic and hard to debug. This CL adds a
DCHECK to make the error more transparent and give instructions on the
proper invocation.

Change-Id: I26e38bbccfd16e3e9b0e5c45931edb26ea0e4f0d
Bug: 798699
Reviewed-on: https://chromium-review.googlesource.com/c/1350610Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610832}
parent 00f78b5b
...@@ -114,10 +114,16 @@ void OneShotIdentityManagerObserver::OnAccountsInCookieUpdated( ...@@ -114,10 +114,16 @@ void OneShotIdentityManagerObserver::OnAccountsInCookieUpdated(
// Helper function that updates the refresh token for |account_id| to // Helper function that updates the refresh token for |account_id| to
// |new_token|. Blocks until the update is processed by |identity_manager|. // |new_token|. Blocks until the update is processed by |identity_manager|.
void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void UpdateRefreshTokenForAccount(
IdentityManager* identity_manager, ProfileOAuth2TokenService* token_service,
const std::string& account_id, AccountTrackerService* account_tracker_service,
const std::string& new_token) { IdentityManager* identity_manager,
const std::string& account_id,
const std::string& new_token) {
DCHECK_EQ(account_tracker_service->GetAccountInfo(account_id).account_id,
account_id)
<< "To set the refresh token for an unknown account, use "
"MakeAccountAvailable()";
base::RunLoop run_loop; base::RunLoop run_loop;
OneShotIdentityManagerObserver token_updated_observer( OneShotIdentityManagerObserver token_updated_observer(
identity_manager, run_loop.QuitClosure(), identity_manager, run_loop.QuitClosure(),
...@@ -272,14 +278,17 @@ void SetRefreshTokenForAccount(IdentityManager* identity_manager, ...@@ -272,14 +278,17 @@ void SetRefreshTokenForAccount(IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
std::string refresh_token = "refresh_token_for_" + account_id; std::string refresh_token = "refresh_token_for_" + account_id;
UpdateRefreshTokenForAccount(identity_manager->GetTokenService(), UpdateRefreshTokenForAccount(identity_manager->GetTokenService(),
identity_manager->GetAccountTrackerService(),
identity_manager, account_id, refresh_token); identity_manager, account_id, refresh_token);
} }
void SetInvalidRefreshTokenForAccount(IdentityManager* identity_manager, void SetInvalidRefreshTokenForAccount(IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
UpdateRefreshTokenForAccount( UpdateRefreshTokenForAccount(
identity_manager->GetTokenService(), identity_manager, account_id, identity_manager->GetTokenService(),
OAuth2TokenServiceDelegate::kInvalidRefreshToken);
identity_manager->GetAccountTrackerService(), identity_manager,
account_id, OAuth2TokenServiceDelegate::kInvalidRefreshToken);
} }
void RemoveRefreshTokenForAccount(IdentityManager* identity_manager, void RemoveRefreshTokenForAccount(IdentityManager* identity_manager,
......
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