| Index: chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc
|
| ===================================================================
|
| --- chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc (revision 88668)
|
| +++ chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc (working copy)
|
| @@ -5,13 +5,14 @@
|
| // A complete set of unit tests for GaiaAuthFetcher.
|
| // Originally ported from GoogleAuthenticator tests.
|
|
|
| +#include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h"
|
| +
|
| #include <string>
|
|
|
| #include "base/message_loop.h"
|
| #include "base/stringprintf.h"
|
| #include "chrome/common/net/gaia/gaia_auth_consumer.h"
|
| #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
|
| -#include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h"
|
| #include "chrome/common/net/gaia/google_service_auth_error.h"
|
| #include "chrome/common/net/http_return.h"
|
| #include "chrome/test/testing_profile.h"
|
| @@ -62,7 +63,8 @@
|
| public:
|
| GaiaAuthFetcherTest()
|
| : client_login_source_(GaiaAuthFetcher::kClientLoginUrl),
|
| - issue_auth_token_source_(GaiaAuthFetcher::kIssueAuthTokenUrl) {}
|
| + issue_auth_token_source_(GaiaAuthFetcher::kIssueAuthTokenUrl),
|
| + token_auth_source_(GaiaAuthFetcher::kTokenAuthUrl) {}
|
|
|
| void RunParsingTest(const std::string& data,
|
| const std::string& sid,
|
| @@ -105,6 +107,7 @@
|
| net::ResponseCookies cookies_;
|
| GURL client_login_source_;
|
| GURL issue_auth_token_source_;
|
| + GURL token_auth_source_;
|
| TestingProfile profile_;
|
| protected:
|
| MessageLoop message_loop_;
|
| @@ -118,10 +121,12 @@
|
| MOCK_METHOD1(OnClientLoginSuccess, void(const ClientLoginResult& result));
|
| MOCK_METHOD2(OnIssueAuthTokenSuccess, void(const std::string& service,
|
| const std::string& token));
|
| + MOCK_METHOD1(OnTokenAuthSuccess, void(const std::string& data));
|
| MOCK_METHOD1(OnClientLoginFailure,
|
| void(const GoogleServiceAuthError& error));
|
| MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service,
|
| const GoogleServiceAuthError& error));
|
| + MOCK_METHOD1(OnTokenAuthFailure, void(const GoogleServiceAuthError& error));
|
| };
|
|
|
| TEST_F(GaiaAuthFetcherTest, ErrorComparator) {
|
| @@ -495,3 +500,78 @@
|
| "");
|
| EXPECT_FALSE(auth.HasPendingFetch());
|
| }
|
| +
|
| +TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) {
|
| + MockGaiaConsumer consumer;
|
| + EXPECT_CALL(consumer, OnTokenAuthSuccess("<html></html>"))
|
| + .Times(1);
|
| +
|
| + TestingProfile profile;
|
| + TestURLFetcherFactory factory;
|
| + URLFetcher::set_factory(&factory);
|
| +
|
| + GaiaAuthFetcher auth(&consumer, std::string(),
|
| + profile_.GetRequestContext());
|
| + auth.StartTokenAuth("myubertoken");
|
| +
|
| + URLFetcher::set_factory(NULL);
|
| + EXPECT_TRUE(auth.HasPendingFetch());
|
| + auth.OnURLFetchComplete(
|
| + NULL,
|
| + token_auth_source_,
|
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
|
| + RC_REQUEST_OK,
|
| + cookies_,
|
| + "<html></html>");
|
| + EXPECT_FALSE(auth.HasPendingFetch());
|
| +}
|
| +
|
| +TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) {
|
| + MockGaiaConsumer consumer;
|
| + EXPECT_CALL(consumer, OnTokenAuthFailure(_))
|
| + .Times(1);
|
| +
|
| + TestingProfile profile;
|
| + TestURLFetcherFactory factory;
|
| + URLFetcher::set_factory(&factory);
|
| +
|
| + GaiaAuthFetcher auth(&consumer, std::string(),
|
| + profile_.GetRequestContext());
|
| + auth.StartTokenAuth("badubertoken");
|
| +
|
| + URLFetcher::set_factory(NULL);
|
| + EXPECT_TRUE(auth.HasPendingFetch());
|
| + auth.OnURLFetchComplete(
|
| + NULL,
|
| + token_auth_source_,
|
| + net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
|
| + RC_UNAUTHORIZED,
|
| + cookies_,
|
| + "");
|
| + EXPECT_FALSE(auth.HasPendingFetch());
|
| +}
|
| +
|
| +TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) {
|
| + MockGaiaConsumer consumer;
|
| + EXPECT_CALL(consumer, OnTokenAuthFailure(_))
|
| + .Times(1);
|
| +
|
| + TestingProfile profile;
|
| + TestURLFetcherFactory factory;
|
| + URLFetcher::set_factory(&factory);
|
| +
|
| + GaiaAuthFetcher auth(&consumer, std::string(),
|
| + profile_.GetRequestContext());
|
| + auth.StartTokenAuth("badubertoken");
|
| +
|
| + URLFetcher::set_factory(NULL);
|
| + EXPECT_TRUE(auth.HasPendingFetch());
|
| + auth.OnURLFetchComplete(
|
| + NULL,
|
| + token_auth_source_,
|
| + net::URLRequestStatus(net::URLRequestStatus::FAILED, 0),
|
| + RC_REQUEST_OK,
|
| + cookies_,
|
| + "");
|
| + EXPECT_FALSE(auth.HasPendingFetch());
|
| +}
|
|
|