| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void(const GoogleServiceAuthError& error)); | 181 void(const GoogleServiceAuthError& error)); |
| 182 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service, | 182 MOCK_METHOD2(OnIssueAuthTokenFailure, void(const std::string& service, |
| 183 const GoogleServiceAuthError& error)); | 183 const GoogleServiceAuthError& error)); |
| 184 MOCK_METHOD1(OnClientOAuthFailure, | 184 MOCK_METHOD1(OnClientOAuthFailure, |
| 185 void(const GoogleServiceAuthError& error)); | 185 void(const GoogleServiceAuthError& error)); |
| 186 MOCK_METHOD1(OnMergeSessionFailure, void( | 186 MOCK_METHOD1(OnMergeSessionFailure, void( |
| 187 const GoogleServiceAuthError& error)); | 187 const GoogleServiceAuthError& error)); |
| 188 MOCK_METHOD1(OnUberAuthTokenFailure, void( | 188 MOCK_METHOD1(OnUberAuthTokenFailure, void( |
| 189 const GoogleServiceAuthError& error)); | 189 const GoogleServiceAuthError& error)); |
| 190 MOCK_METHOD1(OnListAccountsSuccess, void(const std::string& data)); | 190 MOCK_METHOD1(OnListAccountsSuccess, void(const std::string& data)); |
| 191 MOCK_METHOD1(OnGetCheckConnectionInfoSuccess, void(const std::string& data)); |
| 191 }; | 192 }; |
| 192 | 193 |
| 193 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
| 194 #define MAYBE_ErrorComparator DISABLED_ErrorComparator | 195 #define MAYBE_ErrorComparator DISABLED_ErrorComparator |
| 195 #else | 196 #else |
| 196 #define MAYBE_ErrorComparator ErrorComparator | 197 #define MAYBE_ErrorComparator ErrorComparator |
| 197 #endif | 198 #endif |
| 198 | 199 |
| 199 TEST_F(GaiaAuthFetcherTest, MAYBE_ErrorComparator) { | 200 TEST_F(GaiaAuthFetcherTest, MAYBE_ErrorComparator) { |
| 200 GoogleServiceAuthError expected_error = | 201 GoogleServiceAuthError expected_error = |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 } | 649 } |
| 649 | 650 |
| 650 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { | 651 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { |
| 651 MockGaiaConsumer consumer; | 652 MockGaiaConsumer consumer; |
| 652 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 653 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
| 653 .Times(1); | 654 .Times(1); |
| 654 | 655 |
| 655 net::TestURLFetcherFactory factory; | 656 net::TestURLFetcherFactory factory; |
| 656 | 657 |
| 657 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 658 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 658 auth.StartMergeSession("myubertoken"); | 659 auth.StartMergeSession("myubertoken", std::string()); |
| 659 | 660 |
| 660 EXPECT_TRUE(auth.HasPendingFetch()); | 661 EXPECT_TRUE(auth.HasPendingFetch()); |
| 661 MockFetcher mock_fetcher( | 662 MockFetcher mock_fetcher( |
| 662 merge_session_source_, | 663 merge_session_source_, |
| 663 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 664 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
| 664 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET, | 665 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET, |
| 665 &auth); | 666 &auth); |
| 666 auth.OnURLFetchComplete(&mock_fetcher); | 667 auth.OnURLFetchComplete(&mock_fetcher); |
| 667 EXPECT_FALSE(auth.HasPendingFetch()); | 668 EXPECT_FALSE(auth.HasPendingFetch()); |
| 668 } | 669 } |
| 669 | 670 |
| 670 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { | 671 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { |
| 671 MockGaiaConsumer consumer; | 672 MockGaiaConsumer consumer; |
| 672 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 673 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
| 673 .Times(1); | 674 .Times(1); |
| 674 | 675 |
| 675 net::TestURLFetcherFactory factory; | 676 net::TestURLFetcherFactory factory; |
| 676 | 677 |
| 677 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 678 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 678 auth.StartMergeSession("myubertoken"); | 679 auth.StartMergeSession("myubertoken", std::string()); |
| 679 | 680 |
| 680 // Make sure the fetcher created has the expected flags. Set its url() | 681 // Make sure the fetcher created has the expected flags. Set its url() |
| 681 // properties to reflect a redirect. | 682 // properties to reflect a redirect. |
| 682 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); | 683 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); |
| 683 EXPECT_TRUE(test_fetcher != NULL); | 684 EXPECT_TRUE(test_fetcher != NULL); |
| 684 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); | 685 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); |
| 685 EXPECT_TRUE(auth.HasPendingFetch()); | 686 EXPECT_TRUE(auth.HasPendingFetch()); |
| 686 | 687 |
| 687 GURL final_url("http://www.google.com/CheckCookie"); | 688 GURL final_url("http://www.google.com/CheckCookie"); |
| 688 test_fetcher->set_url(final_url); | 689 test_fetcher->set_url(final_url); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); | 785 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); |
| 785 MockGaiaConsumer consumer; | 786 MockGaiaConsumer consumer; |
| 786 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); | 787 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); |
| 787 | 788 |
| 788 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 789 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 789 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 790 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 790 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->list_accounts_url(), | 791 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->list_accounts_url(), |
| 791 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | 792 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| 792 auth.OnURLFetchComplete(&mock_fetcher); | 793 auth.OnURLFetchComplete(&mock_fetcher); |
| 793 } | 794 } |
| 795 |
| 796 TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) { |
| 797 std::string data( |
| 798 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); |
| 799 MockGaiaConsumer consumer; |
| 800 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); |
| 801 |
| 802 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 803 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 804 MockFetcher mock_fetcher( |
| 805 GaiaUrls::GetInstance()->get_check_connection_info_url(), |
| 806 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
| 807 auth.OnURLFetchComplete(&mock_fetcher); |
| 808 } |
| OLD | NEW |