| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 GaiaOAuthFetcher. | 5 // A complete set of unit tests for GaiaOAuthFetcher. |
| 6 // Originally ported from GaiaAuthFetcher tests. | 6 // Originally ported from GaiaAuthFetcher tests. |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 MOCK_METHOD1(OnGetOAuthTokenSuccess, void(const std::string& oauth_token)); | 59 MOCK_METHOD1(OnGetOAuthTokenSuccess, void(const std::string& oauth_token)); |
| 60 MOCK_METHOD0(OnGetOAuthTokenFailure, void()); | 60 MOCK_METHOD0(OnGetOAuthTokenFailure, void()); |
| 61 | 61 |
| 62 MOCK_METHOD2(OnOAuthGetAccessTokenSuccess, void(const std::string& token, | 62 MOCK_METHOD2(OnOAuthGetAccessTokenSuccess, void(const std::string& token, |
| 63 const std::string& secret)); | 63 const std::string& secret)); |
| 64 MOCK_METHOD1(OnOAuthGetAccessTokenFailure, | 64 MOCK_METHOD1(OnOAuthGetAccessTokenFailure, |
| 65 void(const GoogleServiceAuthError& error)); | 65 void(const GoogleServiceAuthError& error)); |
| 66 | 66 |
| 67 MOCK_METHOD3(OnOAuthWrapBridgeSuccess, | 67 MOCK_METHOD3(OnOAuthWrapBridgeSuccess, |
| 68 void(const std::string& service_name, | 68 void(const std::string& service_scope, |
| 69 const std::string& token, | 69 const std::string& token, |
| 70 const std::string& expires_in)); | 70 const std::string& expires_in)); |
| 71 MOCK_METHOD1(OnOAuthWrapBridgeFailure, | 71 MOCK_METHOD1(OnOAuthWrapBridgeFailure, |
| 72 void(const GoogleServiceAuthError& error)); | 72 void(const GoogleServiceAuthError& error)); |
| 73 | 73 |
| 74 MOCK_METHOD1(OnUserInfoSuccess, void(const std::string& email)); | 74 MOCK_METHOD1(OnUserInfoSuccess, void(const std::string& email)); |
| 75 MOCK_METHOD1(OnUserInfoFailure, void(const GoogleServiceAuthError& error)); | 75 MOCK_METHOD1(OnUserInfoFailure, void(const GoogleServiceAuthError& error)); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { | 78 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { |
| 79 public: | 79 public: |
| 80 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, | 80 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, |
| 81 net::URLRequestContextGetter* getter, | 81 net::URLRequestContextGetter* getter, |
| 82 Profile* profile, | 82 Profile* profile, |
| 83 const std::string& service_name, | |
| 84 const std::string& service_scope) | 83 const std::string& service_scope) |
| 85 : GaiaOAuthFetcher( | 84 : GaiaOAuthFetcher( |
| 86 consumer, getter, profile, service_name, service_scope) {} | 85 consumer, getter, profile, service_scope) {} |
| 87 | 86 |
| 88 ~MockGaiaOAuthFetcher() {} | 87 ~MockGaiaOAuthFetcher() {} |
| 89 | 88 |
| 90 MOCK_METHOD1(StartOAuthGetAccessToken, | 89 MOCK_METHOD1(StartOAuthGetAccessToken, |
| 91 void(const std::string& oauth1_request_token)); | 90 void(const std::string& oauth1_request_token)); |
| 92 | 91 |
| 93 MOCK_METHOD5(StartOAuthWrapBridge, | 92 MOCK_METHOD4(StartOAuthWrapBridge, |
| 94 void(const std::string& oauth1_access_token, | 93 void(const std::string& oauth1_access_token, |
| 95 const std::string& oauth1_access_token_secret, | 94 const std::string& oauth1_access_token_secret, |
| 96 const std::string& wrap_token_duration, | 95 const std::string& wrap_token_duration, |
| 97 const std::string& service_name, | |
| 98 const std::string& oauth2_scope)); | 96 const std::string& oauth2_scope)); |
| 99 | 97 |
| 100 MOCK_METHOD1(StartUserInfo, void(const std::string& oauth2_access_token)); | 98 MOCK_METHOD1(StartUserInfo, void(const std::string& oauth2_access_token)); |
| 101 }; | 99 }; |
| 102 | 100 |
| 103 #if 0 // Suppressing for now | 101 #if 0 // Suppressing for now |
| 104 TEST(GaiaOAuthFetcherTest, GetOAuthToken) { | 102 TEST(GaiaOAuthFetcherTest, GetOAuthToken) { |
| 105 const std::string oauth_token = "4/OAuth1-Request_Token-1234567"; | 103 const std::string oauth_token = "4/OAuth1-Request_Token-1234567"; |
| 106 base::Time creation = base::Time::Now(); | 104 base::Time creation = base::Time::Now(); |
| 107 base::Time expiration = base::Time::Time(); | 105 base::Time expiration = base::Time::Time(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 oauth_fetcher.Observe( | 142 oauth_fetcher.Observe( |
| 145 chrome::NOTIFICATION_COOKIE_CHANGED, | 143 chrome::NOTIFICATION_COOKIE_CHANGED, |
| 146 Source<Profile>(&profile), | 144 Source<Profile>(&profile), |
| 147 Details<ChromeCookieDetails>(cookie_details.get())); | 145 Details<ChromeCookieDetails>(cookie_details.get())); |
| 148 } | 146 } |
| 149 #endif // 0 // Suppressing for now | 147 #endif // 0 // Suppressing for now |
| 150 | 148 |
| 151 typedef TestingBrowserProcessTest GaiaOAuthFetcherTest; | 149 typedef TestingBrowserProcessTest GaiaOAuthFetcherTest; |
| 152 | 150 |
| 153 TEST_F(GaiaOAuthFetcherTest, OAuthGetAccessToken) { | 151 TEST_F(GaiaOAuthFetcherTest, OAuthGetAccessToken) { |
| 154 const std::string oauth_token="1/OAuth1-Access_Token-1234567890abcdefghijklm"; | 152 const std::string oauth_token = |
| 155 const std::string oauth_token_secret="Dont_tell_the_secret-123"; | 153 "1/OAuth1-Access_Token-1234567890abcdefghijklm"; |
| 154 const std::string oauth_token_secret = "Dont_tell_the_secret-123"; |
| 156 const std::string data("oauth_token=" | 155 const std::string data("oauth_token=" |
| 157 "1%2FOAuth1-Access_Token-1234567890abcdefghijklm" | 156 "1%2FOAuth1-Access_Token-1234567890abcdefghijklm" |
| 158 "&oauth_token_secret=Dont_tell_the_secret-123"); | 157 "&oauth_token_secret=Dont_tell_the_secret-123"); |
| 159 | 158 |
| 160 MockGaiaOAuthConsumer consumer; | 159 MockGaiaOAuthConsumer consumer; |
| 161 EXPECT_CALL(consumer, | 160 EXPECT_CALL(consumer, |
| 162 OnOAuthGetAccessTokenSuccess(oauth_token, | 161 OnOAuthGetAccessTokenSuccess(oauth_token, |
| 163 oauth_token_secret)).Times(1); | 162 oauth_token_secret)).Times(1); |
| 164 | 163 |
| 165 TestingProfile profile; | 164 TestingProfile profile; |
| 166 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 165 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 167 profile.GetRequestContext(), | 166 profile.GetRequestContext(), |
| 168 &profile, | 167 &profile, |
| 169 "service_name-eKARPyky", | |
| 170 "service_scope-JnG18MEE"); | 168 "service_scope-JnG18MEE"); |
| 171 EXPECT_CALL(oauth_fetcher, | 169 EXPECT_CALL(oauth_fetcher, |
| 172 StartOAuthWrapBridge(oauth_token, | 170 StartOAuthWrapBridge(oauth_token, |
| 173 oauth_token_secret, | 171 oauth_token_secret, |
| 174 "3600", | 172 "3600", |
| 175 "service_name-eKARPyky", | |
| 176 "service_scope-JnG18MEE")).Times(1); | 173 "service_scope-JnG18MEE")).Times(1); |
| 177 | 174 |
| 178 net::ResponseCookies cookies; | 175 net::ResponseCookies cookies; |
| 179 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 176 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 180 oauth_fetcher.OnURLFetchComplete(NULL, | 177 oauth_fetcher.OnURLFetchComplete(NULL, |
| 181 GURL(kOAuthGetAccessTokenUrl), | 178 GURL(kOAuthGetAccessTokenUrl), |
| 182 status, | 179 status, |
| 183 RC_REQUEST_OK, | 180 RC_REQUEST_OK, |
| 184 cookies, | 181 cookies, |
| 185 data); | 182 data); |
| 186 } | 183 } |
| 187 | 184 |
| 188 TEST_F(GaiaOAuthFetcherTest, OAuthWrapBridge) { | 185 TEST_F(GaiaOAuthFetcherTest, OAuthWrapBridge) { |
| 189 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 186 const std::string wrap_token = |
| 190 const std::string expires_in="3600"; | 187 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 188 const std::string expires_in = "3600"; |
| 191 | 189 |
| 192 const std::string data("wrap_access_token=" | 190 const std::string data("wrap_access_token=" |
| 193 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" | 191 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" |
| 194 "&wrap_access_token_expires_in=3600"); | 192 "&wrap_access_token_expires_in=3600"); |
| 195 | 193 |
| 196 MockGaiaOAuthConsumer consumer; | 194 MockGaiaOAuthConsumer consumer; |
| 197 EXPECT_CALL(consumer, | 195 EXPECT_CALL(consumer, |
| 198 OnOAuthWrapBridgeSuccess("service_name-62Ykg3K1", | 196 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", |
| 199 wrap_token, | 197 wrap_token, |
| 200 expires_in)).Times(1); | 198 expires_in)).Times(1); |
| 201 | 199 |
| 202 TestingProfile profile; | 200 TestingProfile profile; |
| 203 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 201 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 204 profile .GetRequestContext(), | 202 profile .GetRequestContext(), |
| 205 &profile, | 203 &profile, |
| 206 "service_name-62Ykg3K1", | |
| 207 "service_scope-0fL85iOi"); | 204 "service_scope-0fL85iOi"); |
| 208 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); | 205 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); |
| 209 | 206 |
| 210 net::ResponseCookies cookies; | 207 net::ResponseCookies cookies; |
| 211 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 208 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 212 oauth_fetcher.OnURLFetchComplete(NULL, | 209 oauth_fetcher.OnURLFetchComplete(NULL, |
| 213 GURL(kOAuthWrapBridgeUrl), | 210 GURL(kOAuthWrapBridgeUrl), |
| 214 status, | 211 status, |
| 215 RC_REQUEST_OK, | 212 RC_REQUEST_OK, |
| 216 cookies, | 213 cookies, |
| 217 data); | 214 data); |
| 218 } | 215 } |
| 219 | 216 |
| 220 TEST_F(GaiaOAuthFetcherTest, UserInfo) { | 217 TEST_F(GaiaOAuthFetcherTest, UserInfo) { |
| 221 const std::string email_address="someone@somewhere.net"; | 218 const std::string email_address = "someone@somewhere.net"; |
| 222 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 219 const std::string wrap_token = |
| 223 const std::string expires_in="3600"; | 220 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 221 const std::string expires_in = "3600"; |
| 224 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" | 222 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" |
| 225 " \"verified_email\": true\n}\n"); | 223 " \"verified_email\": true\n}\n"); |
| 226 MockGaiaOAuthConsumer consumer; | 224 MockGaiaOAuthConsumer consumer; |
| 227 EXPECT_CALL(consumer, | 225 EXPECT_CALL(consumer, |
| 228 OnUserInfoSuccess(email_address)).Times(1); | 226 OnUserInfoSuccess(email_address)).Times(1); |
| 229 | 227 |
| 230 TestingProfile profile; | 228 TestingProfile profile; |
| 231 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 229 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 232 profile .GetRequestContext(), | 230 profile .GetRequestContext(), |
| 233 &profile, | 231 &profile, |
| 234 "service_name-S2igVNUm", | |
| 235 "service_scope-Nrj4LmgU"); | 232 "service_scope-Nrj4LmgU"); |
| 236 | 233 |
| 237 net::ResponseCookies cookies; | 234 net::ResponseCookies cookies; |
| 238 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 235 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 239 oauth_fetcher.OnURLFetchComplete(NULL, | 236 oauth_fetcher.OnURLFetchComplete(NULL, |
| 240 GURL(kUserInfoUrl), | 237 GURL(kUserInfoUrl), |
| 241 status, | 238 status, |
| 242 RC_REQUEST_OK, | 239 RC_REQUEST_OK, |
| 243 cookies, | 240 cookies, |
| 244 data); | 241 data); |
| 245 } | 242 } |
| OLD | NEW |