| Index: chrome/browser/chromeos/login/oauth2_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/login/oauth2_browsertest.cc b/chrome/browser/chromeos/login/oauth2_browsertest.cc
|
| index d2121122d572121fdfbc484551cc88d3d70888cb..683aeaade5354495a8591c9ed8fdaf0e25f98a59 100644
|
| --- a/chrome/browser/chromeos/login/oauth2_browsertest.cc
|
| +++ b/chrome/browser/chromeos/login/oauth2_browsertest.cc
|
| @@ -49,6 +49,59 @@ const char kTestAuthLoginToken[] = "fake-oauthlogin-token";
|
|
|
| } // namespace
|
|
|
| +class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer {
|
| + public:
|
| + explicit OAuth2LoginManagerStateWaiter(Profile* profile)
|
| + : profile_(profile),
|
| + waiting_for_state_(false),
|
| + final_state_(OAuth2LoginManager::SESSION_RESTORE_NOT_STARTED) {
|
| + }
|
| +
|
| + void WaitForStates(
|
| + const std::set<OAuth2LoginManager::SessionRestoreState>& states) {
|
| + DCHECK(!waiting_for_state_);
|
| + OAuth2LoginManager* login_manager =
|
| + OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile_);
|
| + states_ = states;
|
| + if (states_.find(login_manager->state()) != states_.end()) {
|
| + final_state_ = login_manager->state();
|
| + return;
|
| + }
|
| +
|
| + waiting_for_state_ = true;
|
| + login_manager->AddObserver(this);
|
| + runner_ = new content::MessageLoopRunner;
|
| + runner_->Run();
|
| + login_manager->RemoveObserver(this);
|
| + }
|
| +
|
| + OAuth2LoginManager::SessionRestoreState final_state() { return final_state_; }
|
| +
|
| + private:
|
| + // OAuth2LoginManager::Observer overrides.
|
| + virtual void OnSessionRestoreStateChanged(
|
| + Profile* user_profile,
|
| + OAuth2LoginManager::SessionRestoreState state) OVERRIDE {
|
| + if (!waiting_for_state_)
|
| + return;
|
| +
|
| + if (states_.find(state) == states_.end())
|
| + return;
|
| +
|
| + final_state_ = state;
|
| + waiting_for_state_ = false;
|
| + runner_->Quit();
|
| + }
|
| +
|
| + Profile* profile_;
|
| + std::set<OAuth2LoginManager::SessionRestoreState> states_;
|
| + bool waiting_for_state_;
|
| + OAuth2LoginManager::SessionRestoreState final_state_;
|
| + scoped_refptr<content::MessageLoopRunner> runner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter);
|
| +};
|
| +
|
| class OAuth2Test : public OobeBaseTest {
|
| protected:
|
| OAuth2Test() {}
|
| @@ -71,7 +124,14 @@ class OAuth2Test : public OobeBaseTest {
|
| SetupGaiaServerWithAccessTokens();
|
| }
|
|
|
| - void SetupGaiaServerForExistingAccount() {
|
| + void SetupGaiaServerForUnexpiredAccount() {
|
| + FakeGaia::MergeSessionParams params;
|
| + params.email = kTestAccountId;
|
| + fake_gaia_.SetMergeSessionParams(params);
|
| + SetupGaiaServerWithAccessTokens();
|
| + }
|
| +
|
| + void SetupGaiaServerForExpiredAccount() {
|
| FakeGaia::MergeSessionParams params;
|
| params.gaia_uber_token = kTestGaiaUberToken;
|
| params.session_sid_cookie = kTestSession2SIDCookie;
|
| @@ -80,9 +140,44 @@ class OAuth2Test : public OobeBaseTest {
|
| SetupGaiaServerWithAccessTokens();
|
| }
|
|
|
| + void LoginAsExistingUser(Profile** user_profile) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
|
| + content::NotificationService::AllSources()).Wait();
|
| +
|
| + JsExpect("!!document.querySelector('#account-picker')");
|
| + JsExpect("!!document.querySelector('#pod-row')");
|
| +
|
| + EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId),
|
| + User::OAUTH2_TOKEN_STATUS_VALID);
|
| +
|
| + EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword));
|
| + Profile* profile = ProfileManager::GetPrimaryUserProfile();
|
| +
|
| + // Wait for the session merge to finish.
|
| + std::set<OAuth2LoginManager::SessionRestoreState> states;
|
| + states.insert(OAuth2LoginManager::SESSION_RESTORE_DONE);
|
| + states.insert(OAuth2LoginManager::SESSION_RESTORE_FAILED);
|
| + states.insert(OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED);
|
| + OAuth2LoginManagerStateWaiter merge_session_waiter(profile);
|
| + merge_session_waiter.WaitForStates(states);
|
| + EXPECT_EQ(merge_session_waiter.final_state(),
|
| + OAuth2LoginManager::SESSION_RESTORE_DONE);
|
| +
|
| + // Check for existance of refresh token.
|
| + ProfileOAuth2TokenService* token_service =
|
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
|
| + EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId));
|
| +
|
| + EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId),
|
| + User::OAUTH2_TOKEN_STATUS_VALID);
|
| +
|
| + *user_profile = profile;
|
| + }
|
| +
|
| bool TryToLogin(const std::string& username,
|
| const std::string& password) {
|
| - if (!AddUserTosession(username, password))
|
| + if (!AddUserToSession(username, password))
|
| return false;
|
|
|
| if (const User* active_user = UserManager::Get()->GetActiveUser())
|
| @@ -108,7 +203,7 @@ class OAuth2Test : public OobeBaseTest {
|
| }
|
|
|
| private:
|
| - bool AddUserTosession(const std::string& username,
|
| + bool AddUserToSession(const std::string& username,
|
| const std::string& password) {
|
| ExistingUserController* controller =
|
| ExistingUserController::current_controller();
|
| @@ -235,61 +330,8 @@ class CookieReader : public base::RefCountedThreadSafe<CookieReader> {
|
| DISALLOW_COPY_AND_ASSIGN(CookieReader);
|
| };
|
|
|
| -class OAuth2LoginManagerStateWaiter : public OAuth2LoginManager::Observer {
|
| - public:
|
| - explicit OAuth2LoginManagerStateWaiter(Profile* profile)
|
| - : profile_(profile),
|
| - waiting_for_state_(false),
|
| - final_state_(OAuth2LoginManager::SESSION_RESTORE_NOT_STARTED) {
|
| - }
|
| -
|
| - void WaitForStates(
|
| - const std::set<OAuth2LoginManager::SessionRestoreState>& states) {
|
| - DCHECK(!waiting_for_state_);
|
| - OAuth2LoginManager* login_manager =
|
| - OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile_);
|
| - states_ = states;
|
| - if (states_.find(login_manager->state()) != states_.end()) {
|
| - final_state_ = login_manager->state();
|
| - return;
|
| - }
|
| -
|
| - waiting_for_state_ = true;
|
| - login_manager->AddObserver(this);
|
| - runner_ = new content::MessageLoopRunner;
|
| - runner_->Run();
|
| - login_manager->RemoveObserver(this);
|
| - }
|
| -
|
| - OAuth2LoginManager::SessionRestoreState final_state() { return final_state_; }
|
| -
|
| - private:
|
| - // OAuth2LoginManager::Observer overrides.
|
| - virtual void OnSessionRestoreStateChanged(
|
| - Profile* user_profile,
|
| - OAuth2LoginManager::SessionRestoreState state) OVERRIDE {
|
| - if (!waiting_for_state_)
|
| - return;
|
| -
|
| - if (states_.find(state) == states_.end())
|
| - return;
|
| -
|
| - final_state_ = state;
|
| - waiting_for_state_ = false;
|
| - runner_->Quit();
|
| - }
|
| -
|
| - Profile* profile_;
|
| - std::set<OAuth2LoginManager::SessionRestoreState> states_;
|
| - bool waiting_for_state_;
|
| - OAuth2LoginManager::SessionRestoreState final_state_;
|
| - scoped_refptr<content::MessageLoopRunner> runner_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter);
|
| -};
|
| -
|
| // PRE_MergeSession is testing merge session for a new profile.
|
| -IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) {
|
| +IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) {
|
| SetupGaiaServerForNewAccount();
|
| SimulateNetworkOnline();
|
| chromeos::WizardController::SkipPostLoginScreensForTesting();
|
| @@ -341,44 +383,38 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) {
|
| }
|
|
|
| // MergeSession test is running merge session process for an existing profile
|
| -// that was generated in PRE_PRE_MergeSession test.
|
| -IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_MergeSession) {
|
| - SetupGaiaServerForExistingAccount();
|
| +// that was generated in PRE_PRE_PRE_MergeSession test. In this test, we
|
| +// are not running /MergeSession process since the /ListAccounts call confirms
|
| +// that the session is not stale.
|
| +IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_MergeSession) {
|
| + SetupGaiaServerForUnexpiredAccount();
|
| SimulateNetworkOnline();
|
|
|
| - content::WindowedNotificationObserver(
|
| - chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
|
| - content::NotificationService::AllSources()).Wait();
|
| -
|
| - JsExpect("!!document.querySelector('#account-picker')");
|
| - JsExpect("!!document.querySelector('#pod-row')");
|
| -
|
| - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId),
|
| - User::OAUTH2_TOKEN_STATUS_VALID);
|
| -
|
| - EXPECT_TRUE(TryToLogin(kTestAccountId, kTestAccountPassword));
|
| - Profile* profile = ProfileManager::GetPrimaryUserProfile();
|
| + Profile* profile = NULL;
|
| + LoginAsExistingUser(&profile);
|
|
|
| - // Wait for the session merge to finish.
|
| - std::set<OAuth2LoginManager::SessionRestoreState> states;
|
| - states.insert(OAuth2LoginManager::SESSION_RESTORE_DONE);
|
| - states.insert(OAuth2LoginManager::SESSION_RESTORE_FAILED);
|
| - states.insert(OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED);
|
| - OAuth2LoginManagerStateWaiter merge_session_waiter(profile);
|
| - merge_session_waiter.WaitForStates(states);
|
| - EXPECT_EQ(merge_session_waiter.final_state(),
|
| - OAuth2LoginManager::SESSION_RESTORE_DONE);
|
| + scoped_refptr<CookieReader> cookie_reader(new CookieReader());
|
| + cookie_reader->ReadCookies(profile);
|
| + // These are still cookie values form the initial session since
|
| + // /ListAccounts
|
| + EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSessionSIDCookie);
|
| + EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSessionLSIDCookie);
|
| +}
|
|
|
| - // Check for existance of refresh token.
|
| - ProfileOAuth2TokenService* token_service =
|
| - ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
|
| - EXPECT_TRUE(token_service->RefreshTokenIsAvailable(kTestAccountId));
|
| +// MergeSession test is running merge session process for an existing profile
|
| +// that was generated in PRE_PRE_MergeSession test.
|
| +IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_MergeSession) {
|
| + SetupGaiaServerForExpiredAccount();
|
| + SimulateNetworkOnline();
|
|
|
| - EXPECT_EQ(GetOAuthStatusFromLocalState(kTestAccountId),
|
| - User::OAUTH2_TOKEN_STATUS_VALID);
|
| + Profile* profile = NULL;
|
| + LoginAsExistingUser(&profile);
|
|
|
| scoped_refptr<CookieReader> cookie_reader(new CookieReader());
|
| cookie_reader->ReadCookies(profile);
|
| + // These should be cookie values that we generated by calling /MergeSession,
|
| + // since /ListAccounts should have tell us that the initial session cookies
|
| + // are stale.
|
| EXPECT_EQ(cookie_reader->GetCookieValue("SID"), kTestSession2SIDCookie);
|
| EXPECT_EQ(cookie_reader->GetCookieValue("LSID"), kTestSession2LSIDCookie);
|
| }
|
|
|