| Index: google_apis/gaia/account_tracker_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/identity/account_tracker_unittest.cc b/google_apis/gaia/account_tracker_unittest.cc
|
| similarity index 73%
|
| copy from chrome/browser/extensions/api/identity/account_tracker_unittest.cc
|
| copy to google_apis/gaia/account_tracker_unittest.cc
|
| index 998462aeecae41e0d69cf219d9c11358160b537e..596b3ad68300fee181238dbaf4a3514046886f9e 100644
|
| --- a/chrome/browser/extensions/api/identity/account_tracker_unittest.cc
|
| +++ b/google_apis/gaia/account_tracker_unittest.cc
|
| @@ -2,20 +2,15 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/extensions/api/identity/account_tracker.h"
|
| +#include "google_apis/gaia/account_tracker.h"
|
|
|
| #include <algorithm>
|
| #include <vector>
|
|
|
| +#include "base/message_loop/message_loop.h"
|
| #include "base/strings/stringprintf.h"
|
| -#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
|
| -#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
|
| -#include "chrome/browser/signin/fake_signin_manager.h"
|
| -#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| -#include "chrome/browser/signin/signin_manager_factory.h"
|
| -#include "chrome/test/base/testing_profile.h"
|
| -#include "components/signin/core/browser/signin_manager_base.h"
|
| -#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "google_apis/gaia/fake_identity_provider.h"
|
| +#include "google_apis/gaia/fake_oauth2_token_service.h"
|
| #include "google_apis/gaia/gaia_oauth_client.h"
|
| #include "net/http/http_status_code.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| @@ -23,12 +18,6 @@
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -// TODO(courage): Account removal really only applies to the primary account,
|
| -// because that's the only account tracked by the SigninManager. Many of the
|
| -// tests here remove non-primary accounts. They still properly test the account
|
| -// state machine, but it may be confusing to readers. Update these tests to
|
| -// avoid causing confusion.
|
| -
|
| namespace {
|
|
|
| const char kPrimaryAccountKey[] = "primary_account@example.com";
|
| @@ -114,7 +103,7 @@ std::string Str(const std::vector<TrackingEvent>& events) {
|
|
|
| } // namespace
|
|
|
| -namespace extensions {
|
| +namespace gaia {
|
|
|
| class AccountTrackerObserver : public AccountTracker::Observer {
|
| public:
|
| @@ -278,34 +267,17 @@ class IdentityAccountTrackerTest : public testing::Test {
|
| virtual ~IdentityAccountTrackerTest() {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - TestingProfile::Builder builder;
|
| - builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
|
| - BuildFakeProfileOAuth2TokenService);
|
| - builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
|
| - FakeSigninManagerBase::Build);
|
| -
|
| - test_profile_ = builder.Build();
|
| -
|
| - fake_oauth2_token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
|
| - ProfileOAuth2TokenServiceFactory::GetForProfile(test_profile_.get()));
|
| -
|
| - fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
|
| - SigninManagerFactory::GetForProfile(test_profile_.get()));
|
| -#if defined(OS_CHROMEOS)
|
| - // We don't sign the primary user in and out on ChromeOS, so set the
|
| - // username once in setup.
|
| - fake_signin_manager_->SetAuthenticatedUsername(kPrimaryAccountKey);
|
| -#endif
|
| -
|
| - account_tracker_.reset(new AccountTracker(test_profile_.get()));
|
| - account_tracker_->AddObserver(&observer_);
|
|
|
| - // Start off signed into the primary account, because most tests need the
|
| - // profile to be signed in. Remove the initial sign-in events that the
|
| - // tests don't care about.
|
| - NotifyTokenAvailable(kPrimaryAccountKey);
|
| - ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| - observer()->Clear();
|
| + fake_oauth2_token_service_.reset(new FakeOAuth2TokenService());
|
| +
|
| + scoped_ptr<FakeIdentityProvider> fake_identity_provider(
|
| + new FakeIdentityProvider(fake_oauth2_token_service_.get()));
|
| +
|
| + account_tracker_.reset(
|
| + new AccountTracker(fake_identity_provider.PassAs<IdentityProvider>(),
|
| + new net::TestURLRequestContextGetter(
|
| + message_loop_.message_loop_proxy())));
|
| + account_tracker_->AddObserver(&observer_);
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| @@ -313,10 +285,6 @@ class IdentityAccountTrackerTest : public testing::Test {
|
| account_tracker_->Shutdown();
|
| }
|
|
|
| - Profile* profile() {
|
| - return test_profile_.get();
|
| - }
|
| -
|
| AccountTrackerObserver* observer() {
|
| return &observer_;
|
| }
|
| @@ -327,29 +295,18 @@ class IdentityAccountTrackerTest : public testing::Test {
|
|
|
| // Helpers to pass fake events to the tracker.
|
|
|
| - void NotifyRemoveAccount(const std::string& username) {
|
| -#if !defined(OS_CHROMEOS)
|
| - if (username == kPrimaryAccountKey)
|
| - fake_signin_manager_->SignOut();
|
| - else
|
| - account_tracker()->GoogleSignedOut(username);
|
| -#else
|
| - account_tracker()->GoogleSignedOut(username);
|
| -#endif
|
| + void NotifyLogin(const std::string account_key) {
|
| + identity_provider()->LogIn(account_key);
|
| }
|
|
|
| + void NotifyLogout() { identity_provider()->LogOut(); }
|
| +
|
| void NotifyTokenAvailable(const std::string& username) {
|
| - fake_oauth2_token_service_->IssueRefreshTokenForUser(username,
|
| - "refresh_token");
|
| -#if !defined(OS_CHROMEOS)
|
| - if (username == kPrimaryAccountKey)
|
| - fake_signin_manager_->OnExternalSigninCompleted(username);
|
| -#endif
|
| + fake_oauth2_token_service_->AddAccount(username);
|
| }
|
|
|
| void NotifyTokenRevoked(const std::string& username) {
|
| - fake_oauth2_token_service_->IssueRefreshTokenForUser(username,
|
| - std::string());
|
| + fake_oauth2_token_service_->RemoveAccount(username);
|
| }
|
|
|
| // Helpers to fake access token and user info fetching
|
| @@ -370,12 +327,27 @@ class IdentityAccountTrackerTest : public testing::Test {
|
| void ReturnOAuthUrlFetchSuccess(const std::string& account_key);
|
| void ReturnOAuthUrlFetchFailure(const std::string& account_key);
|
|
|
| + void SetupPrimaryLogin() {
|
| + // Initial setup for tests that start with a signed in profile.
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + observer()->Clear();
|
| + }
|
| +
|
| + std::string active_account_id() {
|
| + return identity_provider()->GetActiveAccountId();
|
| + }
|
| +
|
| private:
|
| - scoped_ptr<TestingProfile> test_profile_;
|
| + FakeIdentityProvider* identity_provider() {
|
| + return static_cast<FakeIdentityProvider*>(
|
| + account_tracker_->identity_provider());
|
| + }
|
| +
|
| + base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop.
|
| net::TestURLFetcherFactory test_fetcher_factory_;
|
| - FakeProfileOAuth2TokenService* fake_oauth2_token_service_;
|
| - FakeSigninManagerForTesting* fake_signin_manager_;
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| + scoped_ptr<FakeOAuth2TokenService> fake_oauth2_token_service_;
|
|
|
| scoped_ptr<AccountTracker> account_tracker_;
|
| AccountTrackerObserver observer_;
|
| @@ -409,56 +381,140 @@ void IdentityAccountTrackerTest::ReturnOAuthUrlFetchFailure(
|
| gaia::GaiaOAuthClient::kUrlFetcherId, net::HTTP_BAD_REQUEST, "");
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, Available) {
|
| - NotifyTokenAvailable("user@example.com");
|
| +// Primary tests just involve the Active account
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryNoEventsBeforeLogin) {
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + NotifyLogout();
|
| EXPECT_TRUE(observer()->CheckEvents());
|
| +}
|
|
|
| - ReturnOAuthUrlFetchSuccess("user@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "user@example.com"),
|
| - TrackingEvent(SIGN_IN, "user@example.com")));
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryLoginThenTokenAvailable) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey),
|
| + TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, Revoke) {
|
| - account_tracker()->OnRefreshTokenRevoked("user@example.com");
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryTokenAvailableThenLogin) {
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| EXPECT_TRUE(observer()->CheckEvents());
|
| +
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey),
|
| + TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, Remove) {
|
| - NotifyRemoveAccount("user@example.com");
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryTokenAvailableAndRevokedThenLogin) {
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| EXPECT_TRUE(observer()->CheckEvents());
|
| +
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey),
|
| + TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, AvailableRemoveFetchCancelAvailable) {
|
| - NotifyTokenAvailable("user@example.com");
|
| - NotifyRemoveAccount("user@example.com");
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenLogout) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + observer()->Clear();
|
| +
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey)));
|
| +
|
| + NotifyLogout();
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(REMOVED, kPrimaryAccountKey)));
|
| +}
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenLogin) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + observer()->Clear();
|
| +
|
| + NotifyLogin(kPrimaryAccountKey);
|
| EXPECT_TRUE(observer()->CheckEvents());
|
| +}
|
|
|
| - NotifyTokenAvailable("user@example.com");
|
| - ReturnOAuthUrlFetchSuccess("user@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "user@example.com"),
|
| - TrackingEvent(SIGN_IN, "user@example.com")));
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenTokenAvailable) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + observer()->Clear();
|
| +
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, AvailableRemoveAvailable) {
|
| - NotifyTokenAvailable("user@example.com");
|
| - ReturnOAuthUrlFetchSuccess("user@example.com");
|
| - NotifyRemoveAccount("user@example.com");
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryLogoutThenRevoke) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + observer()->Clear();
|
| +
|
| + NotifyLogout();
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey),
|
| + TrackingEvent(REMOVED, kPrimaryAccountKey)));
|
| +
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +}
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, PrimaryLogoutFetchCancelAvailable) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + // TokenAvailable kicks off a fetch. Logout without satisfying it.
|
| + NotifyLogout();
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "user@example.com"),
|
| - TrackingEvent(SIGN_IN, "user@example.com"),
|
| - TrackingEvent(SIGN_OUT, "user@example.com"),
|
| - TrackingEvent(REMOVED, "user@example.com")));
|
| + TrackingEvent(ADDED, kPrimaryAccountKey),
|
| + TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| +}
|
| +
|
| +// Non-primary accounts
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, Available) {
|
| + SetupPrimaryLogin();
|
|
|
| NotifyTokenAvailable("user@example.com");
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +
|
| ReturnOAuthUrlFetchSuccess("user@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| TrackingEvent(ADDED, "user@example.com"),
|
| TrackingEvent(SIGN_IN, "user@example.com")));
|
| }
|
|
|
| +TEST_F(IdentityAccountTrackerTest, Revoke) {
|
| + SetupPrimaryLogin();
|
| +
|
| + account_tracker()->OnRefreshTokenRevoked("user@example.com");
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +}
|
| +
|
| TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailable) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("user@example.com");
|
| ReturnOAuthUrlFetchSuccess("user@example.com");
|
| NotifyTokenRevoked("user@example.com");
|
| @@ -473,6 +529,8 @@ TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailable) {
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailableWithPendingFetch) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("user@example.com");
|
| NotifyTokenRevoked("user@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents());
|
| @@ -484,21 +542,9 @@ TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailableWithPendingFetch) {
|
| TrackingEvent(SIGN_IN, "user@example.com")));
|
| }
|
|
|
| -TEST_F(IdentityAccountTrackerTest, AvailableRevokeRemove) {
|
| - NotifyTokenAvailable("user@example.com");
|
| - ReturnOAuthUrlFetchSuccess("user@example.com");
|
| - NotifyTokenRevoked("user@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "user@example.com"),
|
| - TrackingEvent(SIGN_IN, "user@example.com"),
|
| - TrackingEvent(SIGN_OUT, "user@example.com")));
|
| -
|
| - NotifyRemoveAccount("user@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(REMOVED, "user@example.com")));
|
| -}
|
| -
|
| TEST_F(IdentityAccountTrackerTest, AvailableRevokeRevoke) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("user@example.com");
|
| ReturnOAuthUrlFetchSuccess("user@example.com");
|
| NotifyTokenRevoked("user@example.com");
|
| @@ -512,6 +558,8 @@ TEST_F(IdentityAccountTrackerTest, AvailableRevokeRevoke) {
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, AvailableAvailable) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("user@example.com");
|
| ReturnOAuthUrlFetchSuccess("user@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| @@ -523,72 +571,34 @@ TEST_F(IdentityAccountTrackerTest, AvailableAvailable) {
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, TwoAccounts) {
|
| - NotifyTokenAvailable("alpha@example.com");
|
| - ReturnOAuthUrlFetchSuccess("alpha@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "alpha@example.com"),
|
| - TrackingEvent(SIGN_IN, "alpha@example.com")));
|
| -
|
| - NotifyTokenAvailable("beta@example.com");
|
| - ReturnOAuthUrlFetchSuccess("beta@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, "beta@example.com"),
|
| - TrackingEvent(SIGN_IN, "beta@example.com")));
|
| -
|
| - NotifyRemoveAccount("alpha@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(SIGN_OUT, "alpha@example.com"),
|
| - TrackingEvent(REMOVED, "alpha@example.com")));
|
| -
|
| - NotifyRemoveAccount("beta@example.com");
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(SIGN_OUT, "beta@example.com"),
|
| - TrackingEvent(REMOVED, "beta@example.com")));
|
| -}
|
| + SetupPrimaryLogin();
|
|
|
| -TEST_F(IdentityAccountTrackerTest, GlobalErrors) {
|
| NotifyTokenAvailable("alpha@example.com");
|
| ReturnOAuthUrlFetchSuccess("alpha@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| TrackingEvent(ADDED, "alpha@example.com"),
|
| TrackingEvent(SIGN_IN, "alpha@example.com")));
|
| +
|
| NotifyTokenAvailable("beta@example.com");
|
| ReturnOAuthUrlFetchSuccess("beta@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| TrackingEvent(ADDED, "beta@example.com"),
|
| TrackingEvent(SIGN_IN, "beta@example.com")));
|
|
|
| - EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(),
|
| - account_tracker()->GetAuthStatus());
|
| + NotifyTokenRevoked("alpha@example.com");
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_OUT, "alpha@example.com")));
|
|
|
| - account_tracker()->ReportAuthError(
|
| - "beta@example.com",
|
| - GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED));
|
| + NotifyTokenRevoked("beta@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| TrackingEvent(SIGN_OUT, "beta@example.com")));
|
| - EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED),
|
| - account_tracker()->GetAuthStatus());
|
| -
|
| - account_tracker()->ReportAuthError(
|
| - "alpha@example.com",
|
| - GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED));
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(SIGN_OUT, "alpha@example.com")));
|
| - EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED),
|
| - account_tracker()->GetAuthStatus());
|
| -
|
| - NotifyRemoveAccount("alpha@example.com");
|
| - EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED),
|
| - account_tracker()->GetAuthStatus());
|
| -
|
| - NotifyTokenAvailable("beta@example.com");
|
| - EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(),
|
| - account_tracker()->GetAuthStatus());
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, AvailableTokenFetchFailAvailable) {
|
| - NotifyTokenAvailable("alpha@example.com");
|
| - ReturnOAuthUrlFetchFailure("alpha@example.com");
|
| + SetupPrimaryLogin();
|
| +
|
| + NotifyTokenAvailable("user@example.com");
|
| + ReturnOAuthUrlFetchFailure("user@example.com");
|
| EXPECT_TRUE(observer()->CheckEvents());
|
|
|
| NotifyTokenAvailable("user@example.com");
|
| @@ -598,23 +608,9 @@ TEST_F(IdentityAccountTrackerTest, AvailableTokenFetchFailAvailable) {
|
| TrackingEvent(SIGN_IN, "user@example.com")));
|
| }
|
|
|
| -// The Chrome OS fake sign-in manager doesn't do sign-in or sign-out.
|
| -#if !defined(OS_CHROMEOS)
|
| -
|
| -TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignIn) {
|
| - NotifyRemoveAccount(kPrimaryAccountKey);
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(SIGN_OUT, kPrimaryAccountKey),
|
| - TrackingEvent(REMOVED, kPrimaryAccountKey)));
|
| +TEST_F(IdentityAccountTrackerTest, MultiSignOutSignIn) {
|
| + SetupPrimaryLogin();
|
|
|
| - NotifyTokenAvailable(kPrimaryAccountKey);
|
| - ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| - EXPECT_TRUE(observer()->CheckEvents(
|
| - TrackingEvent(ADDED, kPrimaryAccountKey),
|
| - TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| -}
|
| -
|
| -TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignInTwoAccounts) {
|
| NotifyTokenAvailable("alpha@example.com");
|
| ReturnOAuthUrlFetchSuccess("alpha@example.com");
|
| NotifyTokenAvailable("beta@example.com");
|
| @@ -627,7 +623,7 @@ TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignInTwoAccounts) {
|
| TrackingEvent(ADDED, "beta@example.com"),
|
| TrackingEvent(SIGN_IN, "beta@example.com")));
|
|
|
| - NotifyRemoveAccount(kPrimaryAccountKey);
|
| + NotifyLogout();
|
| observer()->SortEventsByUser();
|
| EXPECT_TRUE(observer()->CheckEvents(
|
| TrackingEvent(SIGN_OUT, "alpha@example.com"),
|
| @@ -643,6 +639,7 @@ TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignInTwoAccounts) {
|
| EXPECT_TRUE(observer()->CheckEvents());
|
|
|
| // Signing the profile in again will resume tracking all accounts.
|
| + NotifyLogin(kPrimaryAccountKey);
|
| NotifyTokenAvailable(kPrimaryAccountKey);
|
| ReturnOAuthUrlFetchSuccess("beta@example.com");
|
| ReturnOAuthUrlFetchSuccess("gamma@example.com");
|
| @@ -666,9 +663,51 @@ TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignInTwoAccounts) {
|
| TrackingEvent(SIGN_IN, kPrimaryAccountKey)));
|
| }
|
|
|
| -#endif // !defined(OS_CHROMEOS)
|
| +// Primary/non-primary interactions
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, MultiNoEventsBeforeLogin) {
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + NotifyTokenAvailable("user@example.com");
|
| + NotifyTokenRevoked("user@example.com");
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + NotifyLogout();
|
| + EXPECT_TRUE(observer()->CheckEvents());
|
| +}
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, MultiLogoutRemovesAllAccounts) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + NotifyTokenAvailable("user@example.com");
|
| + ReturnOAuthUrlFetchSuccess("user@example.com");
|
| + observer()->Clear();
|
| +
|
| + NotifyLogout();
|
| + observer()->SortEventsByUser();
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey),
|
| + TrackingEvent(REMOVED, kPrimaryAccountKey),
|
| + TrackingEvent(SIGN_OUT, "user@example.com"),
|
| + TrackingEvent(REMOVED, "user@example.com")));
|
| +}
|
| +
|
| +TEST_F(IdentityAccountTrackerTest, MultiRevokePrimaryDoesNotRemoveAllAccounts) {
|
| + NotifyLogin(kPrimaryAccountKey);
|
| + NotifyTokenAvailable(kPrimaryAccountKey);
|
| + ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey);
|
| + NotifyTokenAvailable("user@example.com");
|
| + ReturnOAuthUrlFetchSuccess("user@example.com");
|
| + observer()->Clear();
|
| +
|
| + NotifyTokenRevoked(kPrimaryAccountKey);
|
| + observer()->SortEventsByUser();
|
| + EXPECT_TRUE(
|
| + observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey)));
|
| +}
|
|
|
| TEST_F(IdentityAccountTrackerTest, GetAccountsPrimary) {
|
| + SetupPrimaryLogin();
|
| +
|
| std::vector<AccountIds> ids = account_tracker()->GetAccounts();
|
| EXPECT_EQ(1ul, ids.size());
|
| EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key);
|
| @@ -676,13 +715,13 @@ TEST_F(IdentityAccountTrackerTest, GetAccountsPrimary) {
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, GetAccountsSignedOut) {
|
| - NotifyTokenRevoked(kPrimaryAccountKey);
|
| -
|
| std::vector<AccountIds> ids = account_tracker()->GetAccounts();
|
| EXPECT_EQ(0ul, ids.size());
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, GetAccountsOnlyReturnAccountsWithTokens) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("alpha@example.com");
|
| NotifyTokenAvailable("beta@example.com");
|
| ReturnOAuthUrlFetchSuccess("beta@example.com");
|
| @@ -696,6 +735,8 @@ TEST_F(IdentityAccountTrackerTest, GetAccountsOnlyReturnAccountsWithTokens) {
|
| }
|
|
|
| TEST_F(IdentityAccountTrackerTest, GetAccountsSortOrder) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("zeta@example.com");
|
| ReturnOAuthUrlFetchSuccess("zeta@example.com");
|
| NotifyTokenAvailable("alpha@example.com");
|
| @@ -715,6 +756,8 @@ TEST_F(IdentityAccountTrackerTest, GetAccountsSortOrder) {
|
|
|
| TEST_F(IdentityAccountTrackerTest,
|
| GetAccountsReturnNothingWhenPrimarySignedOut) {
|
| + SetupPrimaryLogin();
|
| +
|
| NotifyTokenAvailable("zeta@example.com");
|
| ReturnOAuthUrlFetchSuccess("zeta@example.com");
|
| NotifyTokenAvailable("alpha@example.com");
|
| @@ -726,4 +769,4 @@ TEST_F(IdentityAccountTrackerTest,
|
| EXPECT_EQ(0ul, ids.size());
|
| }
|
|
|
| -} // namespace extensions
|
| +} // namespace gaia
|
|
|