| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 class MockGaiaConsumer : public GaiaAuthConsumer { | 168 class MockGaiaConsumer : public GaiaAuthConsumer { |
| 169 public: | 169 public: |
| 170 MockGaiaConsumer() {} | 170 MockGaiaConsumer() {} |
| 171 ~MockGaiaConsumer() {} | 171 ~MockGaiaConsumer() {} |
| 172 | 172 |
| 173 MOCK_METHOD1(OnClientLoginSuccess, void(const ClientLoginResult& result)); | 173 MOCK_METHOD1(OnClientLoginSuccess, void(const ClientLoginResult& result)); |
| 174 MOCK_METHOD2(OnIssueAuthTokenSuccess, void(const std::string& service, | 174 MOCK_METHOD2(OnIssueAuthTokenSuccess, void(const std::string& service, |
| 175 const std::string& token)); | 175 const std::string& token)); |
| 176 MOCK_METHOD1(OnClientOAuthSuccess, | 176 MOCK_METHOD1(OnClientOAuthSuccess, |
| 177 void(const GaiaAuthConsumer::ClientOAuthResult& result)); | 177 void(const GaiaAuthConsumer::ClientOAuthResult& result)); |
| 178 MOCK_METHOD1(OnClientOAuthCodeSuccess, | |
| 179 void(const std::string& result)); | |
| 180 MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& data)); | 178 MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& data)); |
| 181 MOCK_METHOD1(OnUberAuthTokenSuccess, void(const std::string& data)); | 179 MOCK_METHOD1(OnUberAuthTokenSuccess, void(const std::string& data)); |
| 182 MOCK_METHOD1(OnClientLoginFailure, | 180 MOCK_METHOD1(OnClientLoginFailure, |
| 183 void(const GoogleServiceAuthError& error)); | 181 void(const GoogleServiceAuthError& error)); |
| 184 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service, | 182 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service, |
| 185 const GoogleServiceAuthError& error)); | 183 const GoogleServiceAuthError& error)); |
| 186 MOCK_METHOD1(OnClientOAuthFailure, | 184 MOCK_METHOD1(OnClientOAuthFailure, |
| 187 void(const GoogleServiceAuthError& error)); | 185 void(const GoogleServiceAuthError& error)); |
| 188 MOCK_METHOD1(OnClientOAuthCodeFailure, | |
| 189 void(const GoogleServiceAuthError& error)); | |
| 190 MOCK_METHOD1(OnMergeSessionFailure, void( | 186 MOCK_METHOD1(OnMergeSessionFailure, void( |
| 191 const GoogleServiceAuthError& error)); | 187 const GoogleServiceAuthError& error)); |
| 192 MOCK_METHOD1(OnUberAuthTokenFailure, void( | 188 MOCK_METHOD1(OnUberAuthTokenFailure, void( |
| 193 const GoogleServiceAuthError& error)); | 189 const GoogleServiceAuthError& error)); |
| 194 MOCK_METHOD1(OnListAccountsSuccess, void(const std::string& data)); | 190 MOCK_METHOD1(OnListAccountsSuccess, void(const std::string& data)); |
| 195 }; | 191 }; |
| 196 | 192 |
| 197 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
| 198 #define MAYBE_ErrorComparator DISABLED_ErrorComparator | 194 #define MAYBE_ErrorComparator DISABLED_ErrorComparator |
| 199 #else | 195 #else |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 621 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 626 net::HTTP_FORBIDDEN, | 622 net::HTTP_FORBIDDEN, |
| 627 cookies_, | 623 cookies_, |
| 628 std::string(), | 624 std::string(), |
| 629 net::URLFetcher::POST, | 625 net::URLFetcher::POST, |
| 630 &auth); | 626 &auth); |
| 631 auth.OnURLFetchComplete(&mock_fetcher2); | 627 auth.OnURLFetchComplete(&mock_fetcher2); |
| 632 EXPECT_FALSE(auth.HasPendingFetch()); | 628 EXPECT_FALSE(auth.HasPendingFetch()); |
| 633 } | 629 } |
| 634 | 630 |
| 635 TEST_F(GaiaAuthFetcherTest, OAuthCodeWithCookiesSuccess) { | |
| 636 MockGaiaConsumer consumer; | |
| 637 EXPECT_CALL(consumer, OnClientOAuthCodeSuccess("test-code")).Times(1); | |
| 638 | |
| 639 net::TestURLFetcherFactory factory; | |
| 640 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 641 auth.StartCookieForOAuthCodeExchange(""); | |
| 642 | |
| 643 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 644 EXPECT_TRUE(NULL != fetcher); | |
| 645 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); | |
| 646 EXPECT_TRUE(auth.HasPendingFetch()); | |
| 647 | |
| 648 net::ResponseCookies cookies; | |
| 649 cookies.push_back(kGetAuthCodeValidCookie); | |
| 650 MockFetcher mock_fetcher( | |
| 651 client_login_to_oauth2_source_, | |
| 652 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | |
| 653 net::HTTP_OK, | |
| 654 cookies, | |
| 655 std::string(), | |
| 656 net::URLFetcher::POST, | |
| 657 &auth); | |
| 658 auth.OnURLFetchComplete(&mock_fetcher); | |
| 659 EXPECT_FALSE(auth.HasPendingFetch()); | |
| 660 } | |
| 661 | |
| 662 TEST_F(GaiaAuthFetcherTest, OAuthCodeWithCookiesFailure) { | |
| 663 MockGaiaConsumer consumer; | |
| 664 EXPECT_CALL(consumer, OnClientOAuthCodeFailure(_)).Times(1); | |
| 665 | |
| 666 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 667 auth.StartCookieForOAuthCodeExchange(""); | |
| 668 | |
| 669 EXPECT_TRUE(auth.HasPendingFetch()); | |
| 670 net::ResponseCookies cookies; | |
| 671 MockFetcher mock_fetcher( | |
| 672 client_login_to_oauth2_source_, | |
| 673 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | |
| 674 net::HTTP_FORBIDDEN, | |
| 675 cookies, | |
| 676 std::string(), | |
| 677 net::URLFetcher::POST, | |
| 678 &auth); | |
| 679 auth.OnURLFetchComplete(&mock_fetcher); | |
| 680 EXPECT_FALSE(auth.HasPendingFetch()); | |
| 681 } | |
| 682 | |
| 683 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { | 631 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { |
| 684 MockGaiaConsumer consumer; | 632 MockGaiaConsumer consumer; |
| 685 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 633 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
| 686 .Times(1); | 634 .Times(1); |
| 687 | 635 |
| 688 net::TestURLFetcherFactory factory; | 636 net::TestURLFetcherFactory factory; |
| 689 | 637 |
| 690 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 638 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 691 auth.StartMergeSession("myubertoken"); | 639 auth.StartMergeSession("myubertoken"); |
| 692 | 640 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); | 765 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); |
| 818 MockGaiaConsumer consumer; | 766 MockGaiaConsumer consumer; |
| 819 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); | 767 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); |
| 820 | 768 |
| 821 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 769 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 822 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 770 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 823 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->list_accounts_url(), | 771 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->list_accounts_url(), |
| 824 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | 772 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| 825 auth.OnURLFetchComplete(&mock_fetcher); | 773 auth.OnURLFetchComplete(&mock_fetcher); |
| 826 } | 774 } |
| OLD | NEW |