Commit d0138da3 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

FakeProfileOAuth2TokenService: fix auto_post_fetch_response vs manual response

FakeProfileOAuth2TokenService has two modes of operation:
auto_post_fetch_response mode, which means it'll automatically post
successful responses to all access token requests to the message loop,
or regular (manual) mode, where the user calls IssueToken*/IssueError*
etc. This CL adds DCHECKs to make sure the two modes are not mixed.
It also fixes some ProfileSyncService tests which did just that.

Bug: 825190
Change-Id: Ibed800c7defa09fb8efbf8cb8a56608731aaf70e
Reviewed-on: https://chromium-review.googlesource.com/995434Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548067}
parent ef18e86a
...@@ -649,6 +649,10 @@ TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) { ...@@ -649,6 +649,10 @@ TEST_F(ProfileSyncServiceTest, ClearDataOnSignOut) {
// Verify that credential errors get returned from GetAuthError(). // Verify that credential errors get returned from GetAuthError().
TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
// This test needs to manually send access tokens (or errors), so disable
// automatic replies to access token requests.
auth_service()->set_auto_post_fetch_response_on_message_loop(false);
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); IssueTestTokens();
ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
...@@ -663,6 +667,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { ...@@ -663,6 +667,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
signin_manager()->GetAuthenticatedAccountId(); signin_manager()->GetAuthenticatedAccountId();
auth_service()->LoadCredentials(primary_account_id); auth_service()->LoadCredentials(primary_account_id);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueAllTokensForAccount(primary_account_id, "access token",
base::Time::Max());
ASSERT_FALSE(service()->GetAccessTokenForTest().empty()); ASSERT_FALSE(service()->GetAccessTokenForTest().empty());
ASSERT_EQ(GoogleServiceAuthError::NONE, service()->GetAuthError().state()); ASSERT_EQ(GoogleServiceAuthError::NONE, service()->GetAuthError().state());
...@@ -685,6 +691,10 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { ...@@ -685,6 +691,10 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
// Verify that credential errors get cleared when a new token is fetched // Verify that credential errors get cleared when a new token is fetched
// successfully. // successfully.
TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
// This test needs to manually send access tokens (or errors), so disable
// automatic replies to access token requests.
auth_service()->set_auto_post_fetch_response_on_message_loop(false);
CreateService(ProfileSyncService::AUTO_START); CreateService(ProfileSyncService::AUTO_START);
IssueTestTokens(); IssueTestTokens();
ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
...@@ -699,6 +709,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { ...@@ -699,6 +709,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
signin_manager()->GetAuthenticatedAccountId(); signin_manager()->GetAuthenticatedAccountId();
auth_service()->LoadCredentials(primary_account_id); auth_service()->LoadCredentials(primary_account_id);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueAllTokensForAccount(primary_account_id, "access token",
base::Time::Max());
ASSERT_FALSE(service()->GetAccessTokenForTest().empty()); ASSERT_FALSE(service()->GetAccessTokenForTest().empty());
ASSERT_EQ(GoogleServiceAuthError::NONE, service()->GetAuthError().state()); ASSERT_EQ(GoogleServiceAuthError::NONE, service()->GetAuthError().state());
......
...@@ -35,6 +35,7 @@ void FakeProfileOAuth2TokenService::IssueAllTokensForAccount( ...@@ -35,6 +35,7 @@ void FakeProfileOAuth2TokenService::IssueAllTokensForAccount(
const std::string& account_id, const std::string& account_id,
const std::string& access_token, const std::string& access_token,
const base::Time& expiration) { const base::Time& expiration) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests(account_id, true, ScopeSet(), CompleteRequests(account_id, true, ScopeSet(),
GoogleServiceAuthError::AuthErrorNone(), access_token, GoogleServiceAuthError::AuthErrorNone(), access_token,
expiration); expiration);
...@@ -43,6 +44,7 @@ void FakeProfileOAuth2TokenService::IssueAllTokensForAccount( ...@@ -43,6 +44,7 @@ void FakeProfileOAuth2TokenService::IssueAllTokensForAccount(
void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount( void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequestsForAccount(
const std::string& account_id, const std::string& account_id,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests(account_id, true, ScopeSet(), error, std::string(), CompleteRequests(account_id, true, ScopeSet(), error, std::string(),
base::Time()); base::Time());
} }
...@@ -51,6 +53,7 @@ void FakeProfileOAuth2TokenService::IssueTokenForScope( ...@@ -51,6 +53,7 @@ void FakeProfileOAuth2TokenService::IssueTokenForScope(
const ScopeSet& scope, const ScopeSet& scope,
const std::string& access_token, const std::string& access_token,
const base::Time& expiration) { const base::Time& expiration) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests("", false, scope, GoogleServiceAuthError::AuthErrorNone(), CompleteRequests("", false, scope, GoogleServiceAuthError::AuthErrorNone(),
access_token, expiration); access_token, expiration);
} }
...@@ -58,17 +61,20 @@ void FakeProfileOAuth2TokenService::IssueTokenForScope( ...@@ -58,17 +61,20 @@ void FakeProfileOAuth2TokenService::IssueTokenForScope(
void FakeProfileOAuth2TokenService::IssueErrorForScope( void FakeProfileOAuth2TokenService::IssueErrorForScope(
const ScopeSet& scope, const ScopeSet& scope,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests("", false, scope, error, std::string(), base::Time()); CompleteRequests("", false, scope, error, std::string(), base::Time());
} }
void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests( void FakeProfileOAuth2TokenService::IssueErrorForAllPendingRequests(
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests("", true, ScopeSet(), error, std::string(), base::Time()); CompleteRequests("", true, ScopeSet(), error, std::string(), base::Time());
} }
void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests( void FakeProfileOAuth2TokenService::IssueTokenForAllPendingRequests(
const std::string& access_token, const std::string& access_token,
const base::Time& expiration) { const base::Time& expiration) {
DCHECK(!auto_post_fetch_response_on_message_loop_);
CompleteRequests("", true, ScopeSet(), CompleteRequests("", true, ScopeSet(),
GoogleServiceAuthError::AuthErrorNone(), access_token, GoogleServiceAuthError::AuthErrorNone(), access_token,
expiration); expiration);
...@@ -125,9 +131,11 @@ void FakeProfileOAuth2TokenService::FetchOAuth2Token( ...@@ -125,9 +131,11 @@ void FakeProfileOAuth2TokenService::FetchOAuth2Token(
if (auto_post_fetch_response_on_message_loop_) { if (auto_post_fetch_response_on_message_loop_) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&FakeProfileOAuth2TokenService::IssueAllTokensForAccount, base::BindOnce(&FakeProfileOAuth2TokenService::CompleteRequests,
weak_ptr_factory_.GetWeakPtr(), account_id, "access_token", weak_ptr_factory_.GetWeakPtr(), account_id,
base::Time::Max())); /*all_scoped=*/true, ScopeSet(),
GoogleServiceAuthError::AuthErrorNone(), "access_token",
base::Time::Max()));
} }
} }
......
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