Commit c9f6f551 authored by mlerman's avatar mlerman Committed by Commit bot

GaiaCookieServiceManager handles general request types. This is a prerequisite...

GaiaCookieServiceManager handles general request types. This is a prerequisite to the GCMS being able to handle ListAccounts requests as part if its queue. Remove the unused single-account LogOut() method, and rework LogOutInternal() method.

Still to do, in future CLs:
- Make the GaiaCookieManagerService independently check for freshness of ExternalCCConnections before executing any MergeSession (every 3 hours?)
- Move all /ListAccounts calls into the GaiaCookieManagerService, and have it publish to all observers when that fails/succeeds
- Move all logic that listens to cookie changes into GCMS, publish a notification when change happens
- Rename the MergeSessionComplete method of the signin_tracker
- Add retry (and backoff) logic for AddAccount calls
- Remove CrOS's direct calls to gaia_auth_fetcher->StartMergeSession

BUG=466799

Review URL: https://codereview.chromium.org/1044933002

Cr-Commit-Position: refs/heads/master@{#324218}
parent d3f2f69a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/signin/core/browser/gaia_cookie_manager_service.h" #include "components/signin/core/browser/gaia_cookie_manager_service.h"
#include <queue>
#include <vector> #include <vector>
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
...@@ -22,7 +23,6 @@ ...@@ -22,7 +23,6 @@
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_fetcher_delegate.h"
namespace { namespace {
// In case of an error while fetching using the GaiaAuthFetcher, retry with // In case of an error while fetching using the GaiaAuthFetcher, retry with
...@@ -61,8 +61,56 @@ bool IsTransientError(const GoogleServiceAuthError& error) { ...@@ -61,8 +61,56 @@ bool IsTransientError(const GoogleServiceAuthError& error) {
error.state() == GoogleServiceAuthError::REQUEST_CANCELED; error.state() == GoogleServiceAuthError::REQUEST_CANCELED;
} }
enum GaiaCookieRequestType {
ADD_ACCOUNT,
LOG_OUT_ALL_ACCOUNTS,
LOG_OUT_ONE_ACCOUNT,
LIST_ACCOUNTS
};
} // namespace } // namespace
GaiaCookieManagerService::GaiaCookieRequest::GaiaCookieRequest(
GaiaCookieRequestType request_type,
const std::string& account_id,
const GaiaCookieManagerService::ListAccountsCallback&
list_accounts_callback)
: request_type_(request_type),
account_id_(account_id),
list_accounts_callback_(list_accounts_callback) {}
GaiaCookieManagerService::GaiaCookieRequest::~GaiaCookieRequest() {
}
// static
GaiaCookieManagerService::GaiaCookieRequest
GaiaCookieManagerService::GaiaCookieRequest::CreateAddAccountRequest(
const std::string& account_id) {
return GaiaCookieManagerService::GaiaCookieRequest(
GaiaCookieManagerService::GaiaCookieRequestType::ADD_ACCOUNT,
account_id,
GaiaCookieManagerService::ListAccountsCallback());
}
// static
GaiaCookieManagerService::GaiaCookieRequest
GaiaCookieManagerService::GaiaCookieRequest::CreateLogOutRequest() {
return GaiaCookieManagerService::GaiaCookieRequest(
GaiaCookieManagerService::GaiaCookieRequestType::LOG_OUT,
std::string(),
GaiaCookieManagerService::ListAccountsCallback());
}
GaiaCookieManagerService::GaiaCookieRequest
GaiaCookieManagerService::GaiaCookieRequest::CreateListAccountsRequest(
const GaiaCookieManagerService::ListAccountsCallback&
list_accounts_callback) {
return GaiaCookieManagerService::GaiaCookieRequest(
GaiaCookieManagerService::GaiaCookieRequestType::LIST_ACCOUNTS,
std::string(),
list_accounts_callback);
}
GaiaCookieManagerService::ExternalCcResultFetcher::ExternalCcResultFetcher( GaiaCookieManagerService::ExternalCcResultFetcher::ExternalCcResultFetcher(
GaiaCookieManagerService* helper) GaiaCookieManagerService* helper)
: helper_(helper) { : helper_(helper) {
...@@ -235,85 +283,98 @@ GaiaCookieManagerService::GaiaCookieManagerService( ...@@ -235,85 +283,98 @@ GaiaCookieManagerService::GaiaCookieManagerService(
GaiaCookieManagerService::~GaiaCookieManagerService() { GaiaCookieManagerService::~GaiaCookieManagerService() {
CancelAll(); CancelAll();
DCHECK(accounts_.empty()); DCHECK(requests_.empty());
} }
void GaiaCookieManagerService::AddAccountToCookie( void GaiaCookieManagerService::AddAccountToCookie(
const std::string& account_id) { const std::string& account_id) {
DCHECK(!account_id.empty()); DCHECK(!account_id.empty());
VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id; VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id;
accounts_.push_back(account_id); requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id));
if (accounts_.size() == 1) if (requests_.size() == 1)
StartFetching(); StartFetchingUbertoken();
} }
void GaiaCookieManagerService::AddObserver(Observer* observer) { void GaiaCookieManagerService::ListAccounts(
observer_list_.AddObserver(observer); const ListAccountsCallback& callback) {
} // Not implemented yet.
NOTREACHED();
void GaiaCookieManagerService::RemoveObserver(Observer* observer) { // TODO(mlerman): Once this service listens to all GAIA cookie changes, cache
observer_list_.RemoveObserver(observer); // the results of ListAccounts, and return them here if the GAIA cookie
} // hasn't changed since the last call.
void GaiaCookieManagerService::CancelAll() { // If there's a GAIA call being executed, wait for it to complete. If it was
VLOG(1) << "GaiaCookieManagerService::CancelAll"; // another /ListAccounts then we'll use the results it caches.
gaia_auth_fetcher_.reset(); if (gaia_auth_fetcher_)
uber_token_fetcher_.reset(); return;
accounts_.clear();
gaia_auth_fetcher_timer_.Stop();
}
void GaiaCookieManagerService::LogOut( VLOG(1) << "GaiaCookieManagerService::ListAccounts";
const std::string& account_id, gaia_auth_fetcher_.reset(
const std::vector<std::string>& accounts) { new GaiaAuthFetcher(this, source_,
DCHECK(!account_id.empty()); signin_client_->GetURLRequestContext()));
VLOG(1) << "GaiaCookieManagerService::LogOut: " << account_id gaia_auth_fetcher_->StartListAccounts();
<< " accounts=" << accounts.size();
LogOutInternal(account_id, accounts);
} }
void GaiaCookieManagerService::LogOutInternal( void GaiaCookieManagerService::LogOutAllAccounts() {
const std::string& account_id, VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts";
const std::vector<std::string>& accounts) {
bool pending = !accounts_.empty(); bool log_out_queued = false;
if (!requests_.empty()) {
if (pending) { // Track requests to keep; all other unstarted requests will be removed.
for (std::deque<std::string>::const_iterator it = accounts_.begin() + 1; std::vector<GaiaCookieRequest> requests_to_keep;
it != accounts_.end(); it++) {
if (!it->empty() && // Check all pending, non-executing requests.
(std::find(accounts.begin(), accounts.end(), *it) == accounts.end() || for (auto it = requests_.begin() + 1; it != requests_.end(); ++it) {
*it == account_id)) { if (it->request_type() == GaiaCookieRequestType::ADD_ACCOUNT) {
// We have a pending log in request for an account followed by // We have a pending log in request for an account followed by
// a signout. // a signout.
GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
SignalComplete(*it, error); SignalComplete(it->account_id(), error);
}
} }
// Remove every thing in the work list besides the one that is running. // Keep all requests except for ADD_ACCOUNTS.
accounts_.resize(1); if (it->request_type() != GaiaCookieRequestType::ADD_ACCOUNT)
requests_to_keep.push_back(*it);
// Verify a LOG_OUT isn't already queued.
if (it->request_type() == GaiaCookieRequestType::LOG_OUT)
log_out_queued = true;
} }
// Signal a logout to be the next thing to do unless the pending // Verify a LOG_OUT isn't currently being processed.
// action is already a logout. if (requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT)
if (!pending || !accounts_.front().empty()) log_out_queued = true;
accounts_.push_back("");
for (std::vector<std::string>::const_iterator it = accounts.begin(); // Remove all but the executing request. Re-add all requests being kept.
it != accounts.end(); it++) { if (requests_.size() > 1) {
if (*it != account_id) { requests_.erase(requests_.begin() + 1, requests_.end());
DCHECK(!it->empty()); requests_.insert(
accounts_.push_back(*it); requests_.end(), requests_to_keep.begin(), requests_to_keep.end());
} }
} }
if (!pending) if (!log_out_queued) {
requests_.push_back(GaiaCookieRequest::CreateLogOutRequest());
if (requests_.size() == 1)
StartLogOutUrlFetch(); StartLogOutUrlFetch();
}
} }
void GaiaCookieManagerService::LogOutAllAccounts() { void GaiaCookieManagerService::AddObserver(Observer* observer) {
VLOG(1) << "GaiaCookieManagerService::LogOutAllAccounts"; observer_list_.AddObserver(observer);
LogOutInternal("", std::vector<std::string>()); }
void GaiaCookieManagerService::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
void GaiaCookieManagerService::CancelAll() {
VLOG(1) << "GaiaCookieManagerService::CancelAll";
gaia_auth_fetcher_.reset();
uber_token_fetcher_.reset();
requests_.clear();
gaia_auth_fetcher_timer_.Stop();
} }
void GaiaCookieManagerService::SignalComplete( void GaiaCookieManagerService::SignalComplete(
...@@ -332,7 +393,7 @@ void GaiaCookieManagerService::StartFetchingExternalCcResult() { ...@@ -332,7 +393,7 @@ void GaiaCookieManagerService::StartFetchingExternalCcResult() {
} }
void GaiaCookieManagerService::StartLogOutUrlFetch() { void GaiaCookieManagerService::StartLogOutUrlFetch() {
DCHECK(accounts_.front().empty()); DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT);
VLOG(1) << "GaiaCookieManagerService::StartLogOutUrlFetch"; VLOG(1) << "GaiaCookieManagerService::StartLogOutUrlFetch";
GURL logout_url(GaiaUrls::GetInstance()->service_logout_url().Resolve( GURL logout_url(GaiaUrls::GetInstance()->service_logout_url().Resolve(
base::StringPrintf("?source=%s", source_.c_str()))); base::StringPrintf("?source=%s", source_.c_str())));
...@@ -345,7 +406,7 @@ void GaiaCookieManagerService::StartLogOutUrlFetch() { ...@@ -345,7 +406,7 @@ void GaiaCookieManagerService::StartLogOutUrlFetch() {
void GaiaCookieManagerService::OnUbertokenSuccess( void GaiaCookieManagerService::OnUbertokenSuccess(
const std::string& uber_token) { const std::string& uber_token) {
VLOG(1) << "GaiaCookieManagerService::OnUbertokenSuccess" VLOG(1) << "GaiaCookieManagerService::OnUbertokenSuccess"
<< " account=" << accounts_.front(); << " account=" << requests_.front().account_id();
gaia_auth_fetcher_retries_ = 0; gaia_auth_fetcher_retries_ = 0;
uber_token_ = uber_token; uber_token_ = uber_token;
StartFetchingMergeSession(); StartFetchingMergeSession();
...@@ -354,16 +415,18 @@ void GaiaCookieManagerService::OnUbertokenSuccess( ...@@ -354,16 +415,18 @@ void GaiaCookieManagerService::OnUbertokenSuccess(
void GaiaCookieManagerService::OnUbertokenFailure( void GaiaCookieManagerService::OnUbertokenFailure(
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
VLOG(1) << "Failed to retrieve ubertoken" VLOG(1) << "Failed to retrieve ubertoken"
<< " account=" << accounts_.front() << " error=" << error.ToString(); << " account=" << requests_.front().account_id()
const std::string account_id = accounts_.front(); << " error=" << error.ToString();
HandleNextAccount(); const std::string account_id = requests_.front().account_id();
HandleNextRequest();
SignalComplete(account_id, error); SignalComplete(account_id, error);
} }
void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) {
VLOG(1) << "MergeSession successful account=" << accounts_.front(); VLOG(1) << "MergeSession successful account="
const std::string account_id = accounts_.front(); << requests_.front().account_id();
HandleNextAccount(); const std::string account_id = requests_.front().account_id();
HandleNextRequest();
SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone()); SignalComplete(account_id, GoogleServiceAuthError::AuthErrorNone());
gaia_auth_fetcher_backoff_.InformOfRequest(true); gaia_auth_fetcher_backoff_.InformOfRequest(true);
...@@ -373,8 +436,8 @@ void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { ...@@ -373,8 +436,8 @@ void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) {
void GaiaCookieManagerService::OnMergeSessionFailure( void GaiaCookieManagerService::OnMergeSessionFailure(
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
VLOG(1) << "Failed MergeSession" VLOG(1) << "Failed MergeSession"
<< " account=" << accounts_.front() << " error=" << error.ToString() << " account=" << requests_.front().account_id()
<< " on retry=" << gaia_auth_fetcher_retries_; << " error=" << error.ToString();
if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries && if (++gaia_auth_fetcher_retries_ < kMaxGaiaAuthFetcherRetries &&
IsTransientError(error)) { IsTransientError(error)) {
...@@ -386,18 +449,18 @@ void GaiaCookieManagerService::OnMergeSessionFailure( ...@@ -386,18 +449,18 @@ void GaiaCookieManagerService::OnMergeSessionFailure(
} }
uber_token_ = std::string(); uber_token_ = std::string();
const std::string account_id = accounts_.front(); const std::string account_id = requests_.front().account_id();
HandleNextAccount(); HandleNextRequest();
SignalComplete(account_id, error); SignalComplete(account_id, error);
} }
void GaiaCookieManagerService::StartFetching() { void GaiaCookieManagerService::StartFetchingUbertoken() {
VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" VLOG(1) << "GaiaCookieManagerService::StartFetching account_id="
<< accounts_.front(); << requests_.front().account_id();
uber_token_fetcher_.reset( uber_token_fetcher_.reset(
new UbertokenFetcher(token_service_, this, source_, new UbertokenFetcher(token_service_, this, source_,
signin_client_->GetURLRequestContext())); signin_client_->GetURLRequestContext()));
uber_token_fetcher_->StartFetchingToken(accounts_.front()); uber_token_fetcher_->StartFetchingToken(requests_.front().account_id());
} }
void GaiaCookieManagerService::StartFetchingMergeSession() { void GaiaCookieManagerService::StartFetchingMergeSession() {
...@@ -414,23 +477,28 @@ void GaiaCookieManagerService::StartFetchingMergeSession() { ...@@ -414,23 +477,28 @@ void GaiaCookieManagerService::StartFetchingMergeSession() {
void GaiaCookieManagerService::OnURLFetchComplete( void GaiaCookieManagerService::OnURLFetchComplete(
const net::URLFetcher* source) { const net::URLFetcher* source) {
DCHECK(accounts_.front().empty()); DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT);
VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete"; VLOG(1) << "GaiaCookieManagerService::OnURLFetchComplete";
HandleNextAccount(); HandleNextRequest();
} }
void GaiaCookieManagerService::HandleNextAccount() { void GaiaCookieManagerService::HandleNextRequest() {
VLOG(1) << "GaiaCookieManagerService::HandleNextAccount"; VLOG(1) << "GaiaCookieManagerService::HandleNextRequest";
accounts_.pop_front(); requests_.pop_front();
gaia_auth_fetcher_.reset(); gaia_auth_fetcher_.reset();
if (accounts_.empty()) { if (requests_.empty()) {
VLOG(1) << "GaiaCookieManagerService::HandleNextAccount: no more"; VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more";
uber_token_fetcher_.reset(); uber_token_fetcher_.reset();
} else { } else {
if (accounts_.front().empty()) { switch (requests_.front().request_type()) {
case GaiaCookieRequestType::ADD_ACCOUNT:
StartFetchingUbertoken();
break;
case GaiaCookieRequestType::LOG_OUT:
StartLogOutUrlFetch(); StartLogOutUrlFetch();
} else { break;
StartFetching(); case GaiaCookieRequestType::LIST_ACCOUNTS:
} break;
};
} }
} }
...@@ -36,6 +36,48 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -36,6 +36,48 @@ class GaiaCookieManagerService : public KeyedService,
public UbertokenConsumer, public UbertokenConsumer,
public net::URLFetcherDelegate { public net::URLFetcherDelegate {
public: public:
typedef base::Callback<void(const std::string& data,
const GoogleServiceAuthError& error)>
ListAccountsCallback;
enum GaiaCookieRequestType {
ADD_ACCOUNT,
LOG_OUT,
LIST_ACCOUNTS
};
// Contains the information and parameters for any request.
class GaiaCookieRequest {
public:
~GaiaCookieRequest();
GaiaCookieRequestType request_type() const { return request_type_; }
const std::string& account_id() const {return account_id_; }
const GaiaCookieManagerService::ListAccountsCallback&
list_accounts_callback() const {
return list_accounts_callback_;
}
static GaiaCookieRequest CreateAddAccountRequest(
const std::string& account_id);
static GaiaCookieRequest CreateLogOutRequest();
static GaiaCookieRequest CreateListAccountsRequest(
const GaiaCookieManagerService::ListAccountsCallback&
list_accounts_callback);
private:
GaiaCookieRequest(
GaiaCookieRequestType request_type,
const std::string& account_id,
const GaiaCookieManagerService::ListAccountsCallback&
list_accounts_callback);
GaiaCookieRequestType request_type_;
std::string account_id_;
GaiaCookieManagerService::ListAccountsCallback list_accounts_callback_;
};
class Observer { class Observer {
public: public:
// Called whenever a merge session is completed. The account that was // Called whenever a merge session is completed. The account that was
...@@ -124,6 +166,8 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -124,6 +166,8 @@ class GaiaCookieManagerService : public KeyedService,
void AddAccountToCookie(const std::string& account_id); void AddAccountToCookie(const std::string& account_id);
void ListAccounts(const ListAccountsCallback& callback);
// Add or remove observers of this helper. // Add or remove observers of this helper.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
...@@ -131,13 +175,6 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -131,13 +175,6 @@ class GaiaCookieManagerService : public KeyedService,
// Cancel all login requests. // Cancel all login requests.
void CancelAll(); void CancelAll();
// Signout of |account_id| given a list of accounts already signed in.
// Since this involves signing out of all accounts and resigning back in,
// the order which |accounts| are given is important as it will dictate
// the sign in order. |account_id| does not have to be in |accounts|.
void LogOut(const std::string& account_id,
const std::vector<std::string>& accounts);
// Signout all accounts. // Signout all accounts.
void LogOutAllAccounts(); void LogOutAllAccounts();
...@@ -148,7 +185,7 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -148,7 +185,7 @@ class GaiaCookieManagerService : public KeyedService,
const GoogleServiceAuthError& error); const GoogleServiceAuthError& error);
// Returns true of there are pending log ins or outs. // Returns true of there are pending log ins or outs.
bool is_running() const { return accounts_.size() > 0; } bool is_running() const { return requests_.size() > 0; }
// Start the process of fetching the external check connection result so that // Start the process of fetching the external check connection result so that
// its ready when we try to perform a merge session. // its ready when we try to perform a merge session.
...@@ -167,12 +204,9 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -167,12 +204,9 @@ class GaiaCookieManagerService : public KeyedService,
void OnMergeSessionSuccess(const std::string& data) override; void OnMergeSessionSuccess(const std::string& data) override;
void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
void LogOutInternal(const std::string& account_id, // Starts the proess of fetching the uber token and performing a merge session
const std::vector<std::string>& accounts); // for the next account. Virtual so that it can be overriden in tests.
virtual void StartFetchingUbertoken();
// Starts the process of fetching the uber token and then performing a merge
// session for the next account. Virtual so that it can be overriden in tests.
virtual void StartFetching();
// Virtual for testing purposes. // Virtual for testing purposes.
virtual void StartFetchingMergeSession(); virtual void StartFetchingMergeSession();
...@@ -180,8 +214,8 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -180,8 +214,8 @@ class GaiaCookieManagerService : public KeyedService,
// Virtual for testing purpose. // Virtual for testing purpose.
virtual void StartLogOutUrlFetch(); virtual void StartLogOutUrlFetch();
// Start the next merge session, if needed. // Start the next request, if needed.
void HandleNextAccount(); void HandleNextRequest();
// Overridden from URLFetcherDelgate. // Overridden from URLFetcherDelgate.
void OnURLFetchComplete(const net::URLFetcher* source) override; void OnURLFetchComplete(const net::URLFetcher* source) override;
...@@ -200,10 +234,10 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -200,10 +234,10 @@ class GaiaCookieManagerService : public KeyedService,
// The last fetched ubertoken, for use in MergeSession retries. // The last fetched ubertoken, for use in MergeSession retries.
std::string uber_token_; std::string uber_token_;
// A worklist for this class. Accounts names are stored here if // A worklist for this class. Stores any pending requests that couldn't be
// we are pending a signin action for that account. Empty strings // executed right away, since this class only permits one request to be
// represent a signout request. // executed at a time.
std::deque<std::string> accounts_; std::deque<GaiaCookieRequest> requests_;
// List of observers to notify when merge session completes. // List of observers to notify when merge session completes.
// Makes sure list is empty on destruction. // Makes sure list is empty on destruction.
......
...@@ -58,7 +58,7 @@ class InstrumentedGaiaCookieManagerService : public GaiaCookieManagerService { ...@@ -58,7 +58,7 @@ class InstrumentedGaiaCookieManagerService : public GaiaCookieManagerService {
virtual ~InstrumentedGaiaCookieManagerService() { total--; } virtual ~InstrumentedGaiaCookieManagerService() { total--; }
MOCK_METHOD0(StartFetching, void()); MOCK_METHOD0(StartFetchingUbertoken, void());
MOCK_METHOD0(StartFetchingMergeSession, void()); MOCK_METHOD0(StartFetchingMergeSession, void());
MOCK_METHOD0(StartLogOutUrlFetch, void()); MOCK_METHOD0(StartLogOutUrlFetch, void());
...@@ -137,7 +137,7 @@ TEST_F(GaiaCookieManagerServiceTest, Success) { ...@@ -137,7 +137,7 @@ TEST_F(GaiaCookieManagerServiceTest, Success) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
...@@ -149,7 +149,7 @@ TEST_F(GaiaCookieManagerServiceTest, FailedMergeSession) { ...@@ -149,7 +149,7 @@ TEST_F(GaiaCookieManagerServiceTest, FailedMergeSession) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
error())); error()));
...@@ -163,7 +163,7 @@ TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetried) { ...@@ -163,7 +163,7 @@ TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetried) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(helper, StartFetchingMergeSession()); EXPECT_CALL(helper, StartFetchingMergeSession());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
...@@ -185,7 +185,7 @@ TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) { ...@@ -185,7 +185,7 @@ TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2); EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
...@@ -215,7 +215,7 @@ TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) { ...@@ -215,7 +215,7 @@ TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
error())); error()));
...@@ -227,7 +227,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterSuccess) { ...@@ -227,7 +227,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterSuccess) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()).Times(2); EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
...@@ -243,7 +243,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterFailure1) { ...@@ -243,7 +243,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterFailure1) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()).Times(2); EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
error())); error()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
...@@ -259,7 +259,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterFailure2) { ...@@ -259,7 +259,7 @@ TEST_F(GaiaCookieManagerServiceTest, ContinueAfterFailure2) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()).Times(2); EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
error())); error()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
...@@ -275,7 +275,7 @@ TEST_F(GaiaCookieManagerServiceTest, AllRequestsInMultipleGoes) { ...@@ -275,7 +275,7 @@ TEST_F(GaiaCookieManagerServiceTest, AllRequestsInMultipleGoes) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetching()).Times(4); EXPECT_CALL(helper, StartFetchingUbertoken()).Times(4);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted(_, no_error())).Times(4); EXPECT_CALL(observer, OnAddAccountToCookieCompleted(_, no_error())).Times(4);
helper.AddAccountToCookie("acc1@gmail.com"); helper.AddAccountToCookie("acc1@gmail.com");
...@@ -293,36 +293,127 @@ TEST_F(GaiaCookieManagerServiceTest, AllRequestsInMultipleGoes) { ...@@ -293,36 +293,127 @@ TEST_F(GaiaCookieManagerServiceTest, AllRequestsInMultipleGoes) {
SimulateMergeSessionSuccess(&helper, "token4"); SimulateMergeSessionSuccess(&helper, "token4");
} }
TEST_F(GaiaCookieManagerServiceTest, LogOut) { TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsNoQueue) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
std::vector<std::string> current_accounts; EXPECT_CALL(helper, StartFetchingUbertoken());
current_accounts.push_back("acc1@gmail.com"); EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
current_accounts.push_back("acc2@gmail.com"); no_error()));
current_accounts.push_back("acc3@gmail.com"); EXPECT_CALL(helper, StartLogOutUrlFetch());
helper.AddAccountToCookie("acc2@gmail.com");
SimulateMergeSessionSuccess(&helper, "token1");
helper.LogOutAllAccounts();
SimulateLogoutSuccess(&helper);
}
TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsAfterOneAddInQueue) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
no_error()));
EXPECT_CALL(helper, StartLogOutUrlFetch()); EXPECT_CALL(helper, StartLogOutUrlFetch());
EXPECT_CALL(helper, StartFetching()).Times(2);
helper.AddAccountToCookie("acc2@gmail.com");
helper.LogOutAllAccounts();
SimulateMergeSessionSuccess(&helper, "token1");
SimulateLogoutSuccess(&helper);
}
TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsAfterTwoAddsInQueue) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
canceled()));
EXPECT_CALL(helper, StartLogOutUrlFetch());
helper.AddAccountToCookie("acc1@gmail.com");
// The Log Out should prevent this AddAccount from being fetched.
helper.AddAccountToCookie("acc2@gmail.com");
helper.LogOutAllAccounts();
SimulateMergeSessionSuccess(&helper, "token1");
SimulateLogoutSuccess(&helper);
}
TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsTwice) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
no_error()));
EXPECT_CALL(helper, StartLogOutUrlFetch());
helper.AddAccountToCookie("acc2@gmail.com");
SimulateMergeSessionSuccess(&helper, "token1");
helper.LogOutAllAccounts();
// Only one LogOut will be fetched.
helper.LogOutAllAccounts();
SimulateLogoutSuccess(&helper);
}
TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsBeforeAdd) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
no_error()));
EXPECT_CALL(helper, StartLogOutUrlFetch());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc3@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc3@gmail.com",
no_error())); no_error()));
helper.LogOut("acc2@gmail.com", current_accounts); helper.AddAccountToCookie("acc2@gmail.com");
SimulateMergeSessionSuccess(&helper, "token1");
helper.LogOutAllAccounts();
helper.AddAccountToCookie("acc3@gmail.com");
SimulateLogoutSuccess(&helper); SimulateLogoutSuccess(&helper);
// After LogOut the MergeSession should be fetched.
SimulateMergeSessionSuccess(&helper, "token2");
}
TEST_F(GaiaCookieManagerServiceTest, LogOutAllAccountsBeforeLogoutAndAdd) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
no_error()));
EXPECT_CALL(helper, StartLogOutUrlFetch());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc3@gmail.com",
no_error()));
helper.AddAccountToCookie("acc2@gmail.com");
SimulateMergeSessionSuccess(&helper, "token1"); SimulateMergeSessionSuccess(&helper, "token1");
SimulateMergeSessionSuccess(&helper, "token3");
helper.LogOutAllAccounts();
// Second LogOut will never be fetched.
helper.LogOutAllAccounts();
helper.AddAccountToCookie("acc3@gmail.com");
SimulateLogoutSuccess(&helper);
// After LogOut the MergeSession should be fetched.
SimulateMergeSessionSuccess(&helper, "token2");
} }
TEST_F(GaiaCookieManagerServiceTest, PendingSigninThenSignout) { TEST_F(GaiaCookieManagerServiceTest, PendingSigninThenSignout) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper); MockObserver observer(&helper);
std::vector<std::string> current_accounts;
current_accounts.push_back("acc2@gmail.com");
current_accounts.push_back("acc3@gmail.com");
// From the first Signin. // From the first Signin.
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error())); no_error()));
...@@ -333,13 +424,15 @@ TEST_F(GaiaCookieManagerServiceTest, PendingSigninThenSignout) { ...@@ -333,13 +424,15 @@ TEST_F(GaiaCookieManagerServiceTest, PendingSigninThenSignout) {
no_error())); no_error()));
// Total sign in 2 times, not enforcing ordered sequences. // Total sign in 2 times, not enforcing ordered sequences.
EXPECT_CALL(helper, StartFetching()).Times(2); EXPECT_CALL(helper, StartFetchingUbertoken()).Times(2);
helper.AddAccountToCookie("acc1@gmail.com"); helper.AddAccountToCookie("acc1@gmail.com");
helper.LogOut("acc2@gmail.com", current_accounts); helper.LogOutAllAccounts();
SimulateMergeSessionSuccess(&helper, "token1"); SimulateMergeSessionSuccess(&helper, "token1");
SimulateLogoutSuccess(&helper); SimulateLogoutSuccess(&helper);
helper.AddAccountToCookie("acc3@gmail.com");
SimulateMergeSessionSuccess(&helper, "token3"); SimulateMergeSessionSuccess(&helper, "token3");
} }
...@@ -349,7 +442,7 @@ TEST_F(GaiaCookieManagerServiceTest, CancelSignIn) { ...@@ -349,7 +442,7 @@ TEST_F(GaiaCookieManagerServiceTest, CancelSignIn) {
std::vector<std::string> current_accounts; std::vector<std::string> current_accounts;
EXPECT_CALL(helper, StartFetching()); EXPECT_CALL(helper, StartFetchingUbertoken());
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc2@gmail.com",
canceled())); canceled()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
...@@ -358,42 +451,12 @@ TEST_F(GaiaCookieManagerServiceTest, CancelSignIn) { ...@@ -358,42 +451,12 @@ TEST_F(GaiaCookieManagerServiceTest, CancelSignIn) {
helper.AddAccountToCookie("acc1@gmail.com"); helper.AddAccountToCookie("acc1@gmail.com");
helper.AddAccountToCookie("acc2@gmail.com"); helper.AddAccountToCookie("acc2@gmail.com");
helper.LogOut("acc2@gmail.com", current_accounts); helper.LogOutAllAccounts();
SimulateMergeSessionSuccess(&helper, "token1"); SimulateMergeSessionSuccess(&helper, "token1");
SimulateLogoutSuccess(&helper); SimulateLogoutSuccess(&helper);
} }
TEST_F(GaiaCookieManagerServiceTest, DoubleSignout) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
MockObserver observer(&helper);
std::vector<std::string> current_accounts1;
current_accounts1.push_back("acc1@gmail.com");
current_accounts1.push_back("acc2@gmail.com");
current_accounts1.push_back("acc3@gmail.com");
std::vector<std::string> current_accounts2;
current_accounts2.push_back("acc1@gmail.com");
current_accounts2.push_back("acc3@gmail.com");
EXPECT_CALL(helper, StartFetching()).Times(2);
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc3@gmail.com",
canceled()));
EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com",
no_error()))
.Times(2);
EXPECT_CALL(helper, StartLogOutUrlFetch());
helper.AddAccountToCookie("acc1@gmail.com");
helper.LogOut("acc2@gmail.com", current_accounts1);
helper.LogOut("acc3@gmail.com", current_accounts2);
SimulateMergeSessionSuccess(&helper, "token1");
SimulateLogoutSuccess(&helper);
SimulateMergeSessionSuccess(&helper, "token1");
}
TEST_F(GaiaCookieManagerServiceTest, ExternalCcResultFetcher) { TEST_F(GaiaCookieManagerServiceTest, ExternalCcResultFetcher) {
InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); InstrumentedGaiaCookieManagerService helper(token_service(), signin_client());
GaiaCookieManagerService::ExternalCcResultFetcher result_fetcher(&helper); GaiaCookieManagerService::ExternalCcResultFetcher result_fetcher(&helper);
......
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