Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2004)

Unified Diff: chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc

Issue 7121014: When a user logs into sync, the appropriate cookies are retrieved so that (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixing merge issue that caused previous trybots to fail Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}
« chrome/browser/sync/signin_manager.h ('K') | « chrome/common/net/gaia/gaia_auth_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698