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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 MOCK_METHOD1(OnGetCheckConnectionInfoSuccess, void(const std::string& data)); |
192 MOCK_METHOD1(OnListIdpSessionsSuccess, void(const std::string& data)); | |
193 MOCK_METHOD1(OnGetTokenResponseSuccess, | |
194 void(const GaiaAuthConsumer::ClientOAuthResult& result)); | |
192 }; | 195 }; |
193 | 196 |
194 #if defined(OS_WIN) | 197 #if defined(OS_WIN) |
195 #define MAYBE_ErrorComparator DISABLED_ErrorComparator | 198 #define MAYBE_ErrorComparator DISABLED_ErrorComparator |
196 #else | 199 #else |
197 #define MAYBE_ErrorComparator ErrorComparator | 200 #define MAYBE_ErrorComparator ErrorComparator |
198 #endif | 201 #endif |
199 | 202 |
200 TEST_F(GaiaAuthFetcherTest, MAYBE_ErrorComparator) { | 203 TEST_F(GaiaAuthFetcherTest, MAYBE_ErrorComparator) { |
201 GoogleServiceAuthError expected_error = | 204 GoogleServiceAuthError expected_error = |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); | 823 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); |
821 | 824 |
822 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 825 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
823 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 826 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
824 MockFetcher mock_fetcher( | 827 MockFetcher mock_fetcher( |
825 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( | 828 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
826 std::string()), | 829 std::string()), |
827 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | 830 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); |
828 auth.OnURLFetchComplete(&mock_fetcher); | 831 auth.OnURLFetchComplete(&mock_fetcher); |
829 } | 832 } |
833 | |
834 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { | |
835 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}"); | |
836 MockGaiaConsumer consumer; | |
837 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1); | |
838 | |
839 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
840 auth.StartListIDPSessions(std::string(), std::string()); | |
841 | |
842 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | |
843 MockFetcher mock_fetcher( | |
844 GaiaUrls::GetInstance()->oauth2_iframe_url(), | |
845 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); | |
846 auth.OnURLFetchComplete(&mock_fetcher); | |
847 } | |
848 | |
849 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { | |
850 MockGaiaConsumer consumer; | |
851 EXPECT_CALL(consumer, | |
852 OnGetTokenResponseSuccess( | |
853 GaiaAuthConsumer::ClientOAuthResult(std::string(), | |
854 "at1", | |
855 3600))) | |
856 .Times(1); | |
Roger Tawa OOO till Jul 10th
2015/03/09 14:41:57
Nit: does this fit on line 855?
Mike Lerman
2015/03/09 18:59:56
Yes!
| |
857 | |
858 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
859 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); | |
860 | |
861 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | |
862 MockFetcher mock_fetcher( | |
863 GaiaUrls::GetInstance()->oauth2_iframe_url(), | |
864 status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, | |
865 net::URLFetcher::GET, &auth); | |
866 auth.OnURLFetchComplete(&mock_fetcher); | |
867 } | |
OLD | NEW |