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