Commit be225f58 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Develop IdentityManager::Observer equivalent to GCMS::Observer::OnSetAccountsInCookieCompleted

This is a preliminary step to port AccountReconcilor and its unittests
away from GaiaCookieManagerService::Observer

BUG=926890

Change-Id: Ifa3b7e18cad45627e29730d2d422688c68a831ab
Reviewed-on: https://chromium-review.googlesource.com/c/1446473Reviewed-by: default avatarLowell Manners <lowell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#628333}
parent 579015de
......@@ -434,6 +434,13 @@ void IdentityManager::OnAddAccountToCookieCompleted(
}
}
void IdentityManager::OnSetAccountsInCookieCompleted(
const GoogleServiceAuthError& error) {
for (auto& observer : observer_list_) {
observer.OnSetAccountsInCookieCompleted(error);
}
}
void IdentityManager::OnAccessTokenRequested(
const std::string& account_id,
const std::string& consumer_id,
......
......@@ -137,6 +137,15 @@ class IdentityManager : public SigninManagerBase::Observer,
const std::string& account_id,
const GoogleServiceAuthError& error) {}
// Called whenever setting cookies is completed. If |error| is equal to
// GoogleServiceAuthError::AuthErrorNone() then the call succeeded.
//
// This observer method is called only in response to a call to
// SetAccountsInCookie(). To listen for cookie changes, use
// OnAccountsInCookieUpdated instead.
virtual void OnSetAccountsInCookieCompleted(
const GoogleServiceAuthError& error) {}
// Called before a batch of refresh token state changes is started.
virtual void OnStartBatchOfRefreshTokenStateChanges() {}
......@@ -465,6 +474,8 @@ class IdentityManager : public SigninManagerBase::Observer,
void OnAddAccountToCookieCompleted(
const std::string& account_id,
const GoogleServiceAuthError& error) override;
void OnSetAccountsInCookieCompleted(
const GoogleServiceAuthError& error) override;
// OAuth2TokenService::DiagnosticsObserver:
void OnAccessTokenRequested(
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "services/identity/public/cpp/identity_manager.h"
#include "base/bind.h"
#include "base/command_line.h"
......@@ -270,6 +272,11 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
return error_from_add_account_to_cookie_completed_callback_;
}
const GoogleServiceAuthError&
error_from_set_accounts_in_cookie_completed_callback() const {
return error_from_set_accounts_in_cookie_completed_callback_;
}
const GoogleServiceAuthError& error_from_signin_failed_callback() const {
return google_signin_failed_error_;
}
......@@ -351,6 +358,10 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
account_from_add_account_to_cookie_completed_callback_ = account_id;
error_from_add_account_to_cookie_completed_callback_ = error;
}
void OnSetAccountsInCookieCompleted(
const GoogleServiceAuthError& error) override {
error_from_set_accounts_in_cookie_completed_callback_ = error;
}
void OnStartBatchOfRefreshTokenStateChanges() override {
EXPECT_FALSE(is_inside_batch_);
......@@ -395,6 +406,7 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
AccountsInCookieJarInfo accounts_info_from_cookie_change_callback_;
std::string account_from_add_account_to_cookie_completed_callback_;
GoogleServiceAuthError error_from_add_account_to_cookie_completed_callback_;
GoogleServiceAuthError error_from_set_accounts_in_cookie_completed_callback_;
GoogleServiceAuthError google_signin_failed_error_;
bool is_inside_batch_ = false;
bool was_called_account_removed_with_info_callback_ = false;
......@@ -576,6 +588,11 @@ class IdentityManagerTest : public testing::Test {
consumer->OnMergeSessionFailure(error);
}
void SimulateOAuthMultiloginFinished(GaiaAuthConsumer* consumer,
const OAuthMultiloginResult& result) {
consumer->OnOAuthMultiloginFinished(result);
}
network::TestURLLoaderFactory* test_url_loader_factory() {
return &test_url_loader_factory_;
}
......@@ -2075,6 +2092,67 @@ TEST_F(IdentityManagerTest, CallbackSentOnFailureAdditionOfAccountToCookie) {
error);
}
TEST_F(IdentityManagerTest,
CallbackSentOnSetAccountsInCookieCompleted_Success) {
const char kTestAccountId[] = "account_id";
const char kTestAccountId2[] = "account_id2";
const std::vector<std::string> account_ids = {kTestAccountId,
kTestAccountId2};
// Needed to insert request in the queue.
gaia_cookie_manager_service()->SetAccountsInCookie(account_ids,
gaia::GaiaSource::kChrome);
// Sample success cookie response.
std::string data =
R"()]}'
{
"status": "OK",
"cookies":[
{
"name":"SID",
"value":"vAlUe1",
"domain":".google.ru",
"path":"/",
"isSecure":true,
"isHttpOnly":false,
"priority":"HIGH",
"maxAge":63070000
}
]
}
)";
OAuthMultiloginResult result(data);
SimulateOAuthMultiloginFinished(gaia_cookie_manager_service(), result);
EXPECT_EQ(identity_manager_observer()
->error_from_set_accounts_in_cookie_completed_callback(),
GoogleServiceAuthError::AuthErrorNone());
}
TEST_F(IdentityManagerTest,
CallbackSentOnSetAccountsInCookieCompleted_Failure) {
const char kTestAccountId[] = "account_id";
const char kTestAccountId2[] = "account_id2";
const std::vector<std::string> account_ids = {kTestAccountId,
kTestAccountId2};
// Needed to insert request in the queue.
gaia_cookie_manager_service()->SetAccountsInCookie(account_ids,
gaia::GaiaSource::kChrome);
// Sample an erroneous response.
GoogleServiceAuthError error(GoogleServiceAuthError::SERVICE_ERROR);
OAuthMultiloginResult result(error);
SimulateOAuthMultiloginFinished(gaia_cookie_manager_service(), result);
EXPECT_EQ(identity_manager_observer()
->error_from_set_accounts_in_cookie_completed_callback(),
error);
}
TEST_F(IdentityManagerTest,
BatchChangeObserversAreNotifiedOnCredentialsUpdate) {
signin_manager()->SetAuthenticatedAccountInfo(kTestGaiaId, kTestEmail);
......
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