Chromium Code Reviews| Index: chrome/browser/signin/signin_manager_unittest.cc |
| =================================================================== |
| --- chrome/browser/signin/signin_manager_unittest.cc (revision 123466) |
| +++ chrome/browser/signin/signin_manager_unittest.cc (working copy) |
| @@ -7,12 +7,14 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/compiler_specific.h" |
| +#include "base/stringprintf.h" |
| #include "chrome/browser/password_manager/encryptor.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/signin/token_service.h" |
| #include "chrome/browser/signin/token_service_unittest.h" |
| #include "chrome/browser/webdata/web_data_service.h" |
| #include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/net/gaia/gaia_constants.h" |
| #include "chrome/common/net/gaia/gaia_urls.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/testing_profile.h" |
| @@ -23,6 +25,22 @@ |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +namespace { |
| + |
| +const char kGetTokenPairValidResponse[] = |
| + "{" |
| + " \"refresh_token\": \"rt1\"," |
| + " \"access_token\": \"at1\"," |
| + " \"expires_in\": 3600," |
| + " \"token_type\": \"Bearer\"" |
| + "}"; |
| + |
| +const char kUberAuthTokenURLFormat[] = |
| + "%s?source=%s&issueuberauth=1"; |
| + |
| +} // namespace |
| + |
| + |
| class SigninManagerTest : public TokenServiceTestHarness { |
| public: |
| virtual void SetUp() OVERRIDE { |
| @@ -35,6 +53,72 @@ |
| content::Source<Profile>(profile_.get())); |
| } |
| + void SimulateValidResponseSignInWithCredentials() { |
| + // Simulate the correct StartOAuthLoginTokenFetch response. This involves |
| + // two separate fetches. |
| + TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| + DCHECK(fetcher); |
| + DCHECK(fetcher->delegate()); |
| + |
| + fetcher->set_url( |
| + GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url())); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + fetcher->SetResponseString(kGetTokenPairValidResponse); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + |
| + fetcher = factory_.GetFetcherByID(0); |
| + DCHECK(fetcher); |
| + DCHECK(fetcher->delegate()); |
| + |
| + fetcher->set_url( |
| + GURL(GaiaUrls::GetInstance()->oauth2_token_url())); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + fetcher->SetResponseString(kGetTokenPairValidResponse); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + |
| + // Simulate the correct StartUberAuthTokenFetch response. |
| + GURL url(base::StringPrintf( |
| + kUberAuthTokenURLFormat, |
| + GaiaUrls::GetInstance()->oauth1_login_url().c_str(), |
| + GaiaConstants::kChromeSource)); |
| + fetcher = factory_.GetFetcherByID(0); |
| + DCHECK(fetcher); |
| + DCHECK(fetcher->delegate()); |
| + fetcher->set_url(url); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + fetcher->SetResponseString("token"); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + |
| + // Simulate the correct StartTokenAuth response. |
| + fetcher = factory_.GetFetcherByID(0); |
| + DCHECK(fetcher); |
| + DCHECK(fetcher->delegate()); |
| + |
| + fetcher->set_url( |
| + GURL(GaiaUrls::GetInstance()->token_auth_url())); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + net::ResponseCookies cookies; |
| + cookies.push_back("SID=sid"); |
| + cookies.push_back("LSID=lsid"); |
| + fetcher->set_cookies(cookies); |
| + fetcher->SetResponseString("data"); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + |
| + // Simulate the correct GetUserInfo response. |
| + fetcher = factory_.GetFetcherByID(0); |
| + DCHECK(fetcher); |
| + DCHECK(fetcher->delegate()); |
| + fetcher->set_url(GURL(GaiaUrls::GetInstance()->get_user_info_url())); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + fetcher->SetResponseString("email=user@gmail.com\nallServices="); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + } |
| + |
| void SimulateValidResponseClientLogin(bool isGPlusUser) { |
| // Simulate the correct ClientLogin response. |
| std::string respons_string = isGPlusUser ? |
| @@ -91,6 +175,26 @@ |
| EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); |
| } |
| +TEST_F(SigninManagerTest, SignInWithCredentials) { |
| + manager_->Initialize(profile_.get()); |
| + EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); |
| + |
| + manager_->StartSignInWithCredentials("username", "password"); |
| + EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); |
| + |
| + SimulateValidResponseSignInWithCredentials(); |
| + EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); |
| + |
| + // Should go into token service and stop. |
| + EXPECT_EQ(1U, google_login_success_.size()); |
|
Andrew T Wilson (Slow)
2012/02/27 19:00:10
Is it difficult to validate that the correct passw
Roger Tawa OOO till Jul 10th
2012/02/29 21:02:54
The password is cleared, so not sure what you mean
Andrew T Wilson (Slow)
2012/03/02 19:22:33
I meant that all we're doing is detecting that LOG
Roger Tawa OOO till Jul 10th
2012/03/02 20:10:58
Its not easy, probably why it was not done for the
|
| + EXPECT_EQ(0U, google_login_failure_.size()); |
| + |
| + // Should persist across resets. |
| + manager_.reset(new SigninManager()); |
| + manager_->Initialize(profile_.get()); |
| + EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); |
|
Andrew T Wilson (Slow)
2012/02/27 19:00:10
Why does the authenticated username not match the
Roger Tawa OOO till Jul 10th
2012/02/29 21:02:54
The test passed because SimulateValidResponseSignI
|
| +} |
| + |
| TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) { |
| manager_->Initialize(profile_.get()); |
| EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); |