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

Side by Side Diff: chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc

Issue 9465018: Changes to the GAIA auth fetching to support one-click login. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Removed DCHECKS, fixed typo Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/net/gaia/gaia_auth_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A complete set of unit tests for GaiaAuthFetcher. 5 // A complete set of unit tests for GaiaAuthFetcher.
6 // Originally ported from GoogleAuthenticator tests. 6 // Originally ported from GoogleAuthenticator tests.
7 7
8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" 8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h"
9 9
10 #include <string> 10 #include <string>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 void RunParsingTest(const std::string& data, 124 void RunParsingTest(const std::string& data,
125 const std::string& sid, 125 const std::string& sid,
126 const std::string& lsid, 126 const std::string& lsid,
127 const std::string& token) { 127 const std::string& token) {
128 std::string out_sid; 128 std::string out_sid;
129 std::string out_lsid; 129 std::string out_lsid;
130 std::string out_token; 130 std::string out_token;
131 131
132 GaiaAuthFetcher::ParseClientLoginResponse(data, 132 GaiaAuthFetcher::ParseClientLoginResponse(data,
133 &out_sid, 133 &out_sid,
134 &out_lsid, 134 &out_lsid,
135 &out_token); 135 &out_token);
136 EXPECT_EQ(lsid, out_lsid); 136 EXPECT_EQ(lsid, out_lsid);
137 EXPECT_EQ(sid, out_sid); 137 EXPECT_EQ(sid, out_sid);
138 EXPECT_EQ(token, out_token); 138 EXPECT_EQ(token, out_token);
139 } 139 }
140 140
141 void RunErrorParsingTest(const std::string& data, 141 void RunErrorParsingTest(const std::string& data,
142 const std::string& error, 142 const std::string& error,
143 const std::string& error_url, 143 const std::string& error_url,
144 const std::string& captcha_url, 144 const std::string& captcha_url,
145 const std::string& captcha_token) { 145 const std::string& captcha_token) {
146 std::string out_error; 146 std::string out_error;
147 std::string out_error_url; 147 std::string out_error_url;
148 std::string out_captcha_url; 148 std::string out_captcha_url;
149 std::string out_captcha_token; 149 std::string out_captcha_token;
150 150
151 GaiaAuthFetcher::ParseClientLoginFailure(data, 151 GaiaAuthFetcher::ParseClientLoginFailure(data,
152 &out_error, 152 &out_error,
153 &out_error_url, 153 &out_error_url,
154 &out_captcha_url, 154 &out_captcha_url,
155 &out_captcha_token); 155 &out_captcha_token);
156 EXPECT_EQ(error, out_error); 156 EXPECT_EQ(error, out_error);
157 EXPECT_EQ(error_url, out_error_url); 157 EXPECT_EQ(error_url, out_error_url);
158 EXPECT_EQ(captcha_url, out_captcha_url); 158 EXPECT_EQ(captcha_url, out_captcha_url);
159 EXPECT_EQ(captcha_token, out_captcha_token); 159 EXPECT_EQ(captcha_token, out_captcha_token);
160 } 160 }
161 161
162 net::ResponseCookies cookies_; 162 net::ResponseCookies cookies_;
163 GURL client_login_source_; 163 GURL client_login_source_;
164 GURL issue_auth_token_source_; 164 GURL issue_auth_token_source_;
165 GURL client_login_to_oauth2_source_; 165 GURL client_login_to_oauth2_source_;
(...skipping 11 matching lines...) Expand all
177 MockGaiaConsumer() {} 177 MockGaiaConsumer() {}
178 ~MockGaiaConsumer() {} 178 ~MockGaiaConsumer() {}
179 179
180 MOCK_METHOD1(OnClientLoginSuccess, void(const ClientLoginResult& result)); 180 MOCK_METHOD1(OnClientLoginSuccess, void(const ClientLoginResult& result));
181 MOCK_METHOD2(OnIssueAuthTokenSuccess, void(const std::string& service, 181 MOCK_METHOD2(OnIssueAuthTokenSuccess, void(const std::string& service,
182 const std::string& token)); 182 const std::string& token));
183 MOCK_METHOD3(OnOAuthLoginTokenSuccess, 183 MOCK_METHOD3(OnOAuthLoginTokenSuccess,
184 void(const std::string& refresh_token, 184 void(const std::string& refresh_token,
185 const std::string& access_token, 185 const std::string& access_token,
186 int expires_in_secs)); 186 int expires_in_secs));
187 MOCK_METHOD1(OnTokenAuthSuccess, void(const std::string& data)); 187 MOCK_METHOD2(OnTokenAuthSuccess,
188 void(const net::ResponseCookies&, const std::string& data));
188 MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& data)); 189 MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& data));
189 MOCK_METHOD1(OnUberAuthTokenSuccess, void(const std::string& data)); 190 MOCK_METHOD1(OnUberAuthTokenSuccess, void(const std::string& data));
190 MOCK_METHOD1(OnClientLoginFailure, 191 MOCK_METHOD1(OnClientLoginFailure,
191 void(const GoogleServiceAuthError& error)); 192 void(const GoogleServiceAuthError& error));
192 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service, 193 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service,
193 const GoogleServiceAuthError& error)); 194 const GoogleServiceAuthError& error));
194 MOCK_METHOD1(OnOAuthLoginTokenFailure, 195 MOCK_METHOD1(OnOAuthLoginTokenFailure,
195 void(const GoogleServiceAuthError& error)); 196 void(const GoogleServiceAuthError& error));
196 MOCK_METHOD1(OnTokenAuthFailure, void(const GoogleServiceAuthError& error)); 197 MOCK_METHOD1(OnTokenAuthFailure, void(const GoogleServiceAuthError& error));
197 MOCK_METHOD1(OnMergeSessionFailure, void( 198 MOCK_METHOD1(OnMergeSessionFailure, void(
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 MockGaiaConsumer consumer; 588 MockGaiaConsumer consumer;
588 EXPECT_CALL(consumer, OnOAuthLoginTokenSuccess("rt1", "at1", 3600)) 589 EXPECT_CALL(consumer, OnOAuthLoginTokenSuccess("rt1", "at1", 3600))
589 .Times(1); 590 .Times(1);
590 591
591 TestingProfile profile; 592 TestingProfile profile;
592 593
593 TestURLFetcherFactory factory; 594 TestURLFetcherFactory factory;
594 GaiaAuthFetcher auth(&consumer, std::string(), 595 GaiaAuthFetcher auth(&consumer, std::string(),
595 profile_.GetRequestContext()); 596 profile_.GetRequestContext());
596 auth.StartOAuthLoginTokenFetch("lso_token"); 597 auth.StartOAuthLoginTokenFetch("lso_token");
598 TestURLFetcher* fetcher = factory.GetFetcherByID(0);
599 EXPECT_TRUE(NULL != fetcher);
600 EXPECT_EQ(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES,
601 fetcher->GetLoadFlags());
597 602
598 net::ResponseCookies cookies; 603 net::ResponseCookies cookies;
599 cookies.push_back(kGetAuthCodeValidCookie); 604 cookies.push_back(kGetAuthCodeValidCookie);
600 EXPECT_TRUE(auth.HasPendingFetch()); 605 EXPECT_TRUE(auth.HasPendingFetch());
601 MockFetcher mock_fetcher1( 606 MockFetcher mock_fetcher1(
602 client_login_to_oauth2_source_, 607 client_login_to_oauth2_source_,
603 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 608 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
604 net::HTTP_OK, cookies, "", 609 net::HTTP_OK, cookies, "",
605 content::URLFetcher::POST, &auth); 610 content::URLFetcher::POST, &auth);
606 auth.OnURLFetchComplete(&mock_fetcher1); 611 auth.OnURLFetchComplete(&mock_fetcher1);
607 EXPECT_TRUE(auth.HasPendingFetch()); 612 EXPECT_TRUE(auth.HasPendingFetch());
608 MockFetcher mock_fetcher2( 613 MockFetcher mock_fetcher2(
609 oauth2_token_source_, 614 oauth2_token_source_,
610 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 615 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
611 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, 616 net::HTTP_OK, cookies_, kGetTokenPairValidResponse,
612 content::URLFetcher::POST, &auth); 617 content::URLFetcher::POST, &auth);
613 auth.OnURLFetchComplete(&mock_fetcher2); 618 auth.OnURLFetchComplete(&mock_fetcher2);
614 EXPECT_FALSE(auth.HasPendingFetch()); 619 EXPECT_FALSE(auth.HasPendingFetch());
615 } 620 }
616 621
622 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithEmptyToken) {
623 MockGaiaConsumer consumer;
624 TestingProfile profile;
625 TestURLFetcherFactory factory;
626 GaiaAuthFetcher auth(&consumer, std::string(),
627 profile_.GetRequestContext());
628 auth.StartOAuthLoginTokenFetch("");
629 TestURLFetcher* fetcher = factory.GetFetcherByID(0);
630 EXPECT_TRUE(NULL != fetcher);
631 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags());
632 }
633
617 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { 634 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) {
618 MockGaiaConsumer consumer; 635 MockGaiaConsumer consumer;
619 EXPECT_CALL(consumer, OnOAuthLoginTokenFailure(_)) 636 EXPECT_CALL(consumer, OnOAuthLoginTokenFailure(_))
620 .Times(1); 637 .Times(1);
621 638
622 TestingProfile profile; 639 TestingProfile profile;
623 640
624 TestURLFetcherFactory factory; 641 TestURLFetcherFactory factory;
625 GaiaAuthFetcher auth(&consumer, std::string(), 642 GaiaAuthFetcher auth(&consumer, std::string(),
626 profile_.GetRequestContext()); 643 profile_.GetRequestContext());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 oauth2_token_source_, 680 oauth2_token_source_,
664 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 681 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
665 net::HTTP_FORBIDDEN, cookies_, "", 682 net::HTTP_FORBIDDEN, cookies_, "",
666 content::URLFetcher::POST, &auth); 683 content::URLFetcher::POST, &auth);
667 auth.OnURLFetchComplete(&mock_fetcher2); 684 auth.OnURLFetchComplete(&mock_fetcher2);
668 EXPECT_FALSE(auth.HasPendingFetch()); 685 EXPECT_FALSE(auth.HasPendingFetch());
669 } 686 }
670 687
671 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) { 688 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) {
672 MockGaiaConsumer consumer; 689 MockGaiaConsumer consumer;
673 EXPECT_CALL(consumer, OnTokenAuthSuccess("<html></html>")) 690 net::ResponseCookies cookies;
691 EXPECT_CALL(consumer, OnTokenAuthSuccess(cookies, "<html></html>"))
674 .Times(1); 692 .Times(1);
675 693
676 TestingProfile profile; 694 TestingProfile profile;
677 TestURLFetcherFactory factory; 695 TestURLFetcherFactory factory;
678 696
679 GaiaAuthFetcher auth(&consumer, std::string(), 697 GaiaAuthFetcher auth(&consumer, std::string(),
680 profile_.GetRequestContext()); 698 profile_.GetRequestContext());
681 auth.StartTokenAuth("myubertoken"); 699 auth.StartTokenAuth("myubertoken");
682 700
683 EXPECT_TRUE(auth.HasPendingFetch()); 701 EXPECT_TRUE(auth.HasPendingFetch());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 std::string rt; 909 std::string rt;
892 std::string at; 910 std::string at;
893 int exp = -1; 911 int exp = -1;
894 EXPECT_TRUE(GaiaAuthFetcher::ParseOAuth2TokenPairResponse( 912 EXPECT_TRUE(GaiaAuthFetcher::ParseOAuth2TokenPairResponse(
895 kGetTokenPairValidResponse, &rt, &at, &exp)); 913 kGetTokenPairValidResponse, &rt, &at, &exp));
896 EXPECT_EQ("rt1", rt); 914 EXPECT_EQ("rt1", rt);
897 EXPECT_EQ("at1", at); 915 EXPECT_EQ("at1", at);
898 EXPECT_EQ(3600, exp); 916 EXPECT_EQ(3600, exp);
899 } 917 }
900 } 918 }
OLDNEW
« no previous file with comments | « 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