| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 "service_scope-JnG18MEE"); | 153 "service_scope-JnG18MEE"); |
| 154 EXPECT_CALL(oauth_fetcher, | 154 EXPECT_CALL(oauth_fetcher, |
| 155 StartOAuthWrapBridge(oauth_token, | 155 StartOAuthWrapBridge(oauth_token, |
| 156 oauth_token_secret, | 156 oauth_token_secret, |
| 157 "3600", | 157 "3600", |
| 158 "service_scope-JnG18MEE")).Times(1); | 158 "service_scope-JnG18MEE")).Times(1); |
| 159 | 159 |
| 160 net::ResponseCookies cookies; | 160 net::ResponseCookies cookies; |
| 161 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 161 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 162 GURL url(GaiaUrls::GetInstance()->oauth_get_access_token_url()); | 162 GURL url(GaiaUrls::GetInstance()->oauth_get_access_token_url()); |
| 163 oauth_fetcher.OnURLFetchComplete(NULL, url, status, RC_REQUEST_OK, | 163 |
| 164 cookies, data); | 164 TestURLFetcher test_fetcher(0, GURL(), URLFetcher::GET, &oauth_fetcher); |
| 165 test_fetcher.set_url(url); |
| 166 test_fetcher.set_status(status); |
| 167 test_fetcher.set_response_code(RC_REQUEST_OK); |
| 168 test_fetcher.set_cookies(cookies); |
| 169 test_fetcher.SetResponseString(data); |
| 170 oauth_fetcher.OnURLFetchComplete(&test_fetcher); |
| 165 } | 171 } |
| 166 | 172 |
| 167 TEST_F(GaiaOAuthFetcherTest, OAuthWrapBridge) { | 173 TEST_F(GaiaOAuthFetcherTest, OAuthWrapBridge) { |
| 168 const std::string wrap_token = | 174 const std::string wrap_token = |
| 169 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 175 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 170 const std::string expires_in = "3600"; | 176 const std::string expires_in = "3600"; |
| 171 | 177 |
| 172 const std::string data("wrap_access_token=" | 178 const std::string data("wrap_access_token=" |
| 173 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" | 179 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" |
| 174 "&wrap_access_token_expires_in=3600"); | 180 "&wrap_access_token_expires_in=3600"); |
| 175 | 181 |
| 176 MockGaiaOAuthConsumer consumer; | 182 MockGaiaOAuthConsumer consumer; |
| 177 EXPECT_CALL(consumer, | 183 EXPECT_CALL(consumer, |
| 178 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", | 184 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", |
| 179 wrap_token, | 185 wrap_token, |
| 180 expires_in)).Times(1); | 186 expires_in)).Times(1); |
| 181 | 187 |
| 182 TestingProfile profile; | 188 TestingProfile profile; |
| 183 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 189 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 184 profile.GetRequestContext(), | 190 profile.GetRequestContext(), |
| 185 &profile, | 191 &profile, |
| 186 "service_scope-0fL85iOi"); | 192 "service_scope-0fL85iOi"); |
| 187 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); | 193 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); |
| 188 | 194 |
| 189 net::ResponseCookies cookies; | 195 net::ResponseCookies cookies; |
| 190 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 196 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 191 GURL url(GaiaUrls::GetInstance()->oauth_wrap_bridge_url()); | 197 GURL url(GaiaUrls::GetInstance()->oauth_wrap_bridge_url()); |
| 192 oauth_fetcher.OnURLFetchComplete(NULL, url, status, RC_REQUEST_OK, | 198 |
| 193 cookies, data); | 199 TestURLFetcher test_fetcher(0, GURL(), URLFetcher::GET, &oauth_fetcher); |
| 200 test_fetcher.set_url(url); |
| 201 test_fetcher.set_status(status); |
| 202 test_fetcher.set_response_code(RC_REQUEST_OK); |
| 203 test_fetcher.set_cookies(cookies); |
| 204 test_fetcher.SetResponseString(data); |
| 205 oauth_fetcher.OnURLFetchComplete(&test_fetcher); |
| 194 } | 206 } |
| 195 | 207 |
| 196 TEST_F(GaiaOAuthFetcherTest, UserInfo) { | 208 TEST_F(GaiaOAuthFetcherTest, UserInfo) { |
| 197 const std::string email_address = "someone@somewhere.net"; | 209 const std::string email_address = "someone@somewhere.net"; |
| 198 const std::string wrap_token = | 210 const std::string wrap_token = |
| 199 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 211 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 200 const std::string expires_in = "3600"; | 212 const std::string expires_in = "3600"; |
| 201 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" | 213 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" |
| 202 " \"verified_email\": true\n}\n"); | 214 " \"verified_email\": true\n}\n"); |
| 203 MockGaiaOAuthConsumer consumer; | 215 MockGaiaOAuthConsumer consumer; |
| 204 EXPECT_CALL(consumer, | 216 EXPECT_CALL(consumer, |
| 205 OnUserInfoSuccess(email_address)).Times(1); | 217 OnUserInfoSuccess(email_address)).Times(1); |
| 206 | 218 |
| 207 TestingProfile profile; | 219 TestingProfile profile; |
| 208 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 220 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 209 profile.GetRequestContext(), | 221 profile.GetRequestContext(), |
| 210 &profile, | 222 &profile, |
| 211 "service_scope-Nrj4LmgU"); | 223 "service_scope-Nrj4LmgU"); |
| 212 | 224 |
| 213 net::ResponseCookies cookies; | 225 net::ResponseCookies cookies; |
| 214 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 226 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 215 GURL url(GaiaUrls::GetInstance()->oauth_user_info_url()); | 227 GURL url(GaiaUrls::GetInstance()->oauth_user_info_url()); |
| 216 oauth_fetcher.OnURLFetchComplete(NULL, url, status, | 228 |
| 217 RC_REQUEST_OK, cookies, data); | 229 TestURLFetcher test_fetcher(0, GURL(), URLFetcher::GET, &oauth_fetcher); |
| 230 test_fetcher.set_url(url); |
| 231 test_fetcher.set_status(status); |
| 232 test_fetcher.set_response_code(RC_REQUEST_OK); |
| 233 test_fetcher.set_cookies(cookies); |
| 234 test_fetcher.SetResponseString(data); |
| 235 oauth_fetcher.OnURLFetchComplete(&test_fetcher); |
| 218 } | 236 } |
| 219 | 237 |
| 220 TEST_F(GaiaOAuthFetcherTest, OAuthRevokeToken) { | 238 TEST_F(GaiaOAuthFetcherTest, OAuthRevokeToken) { |
| 221 const std::string token = "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 239 const std::string token = "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 222 MockGaiaOAuthConsumer consumer; | 240 MockGaiaOAuthConsumer consumer; |
| 223 EXPECT_CALL(consumer, | 241 EXPECT_CALL(consumer, |
| 224 OnOAuthRevokeTokenSuccess()).Times(1); | 242 OnOAuthRevokeTokenSuccess()).Times(1); |
| 225 | 243 |
| 226 TestingProfile profile; | 244 TestingProfile profile; |
| 227 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 245 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 228 profile.GetRequestContext(), | 246 profile.GetRequestContext(), |
| 229 &profile, | 247 &profile, |
| 230 "service_scope-Nrj4LmgU"); | 248 "service_scope-Nrj4LmgU"); |
| 231 | 249 |
| 232 net::ResponseCookies cookies; | 250 net::ResponseCookies cookies; |
| 233 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 251 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 234 GURL url(GaiaUrls::GetInstance()->oauth_revoke_token_url()); | 252 GURL url(GaiaUrls::GetInstance()->oauth_revoke_token_url()); |
| 235 oauth_fetcher.OnURLFetchComplete(NULL, url, status, | 253 |
| 236 RC_REQUEST_OK, cookies, std::string()); | 254 TestURLFetcher test_fetcher(0, GURL(), URLFetcher::GET, &oauth_fetcher); |
| 255 test_fetcher.set_url(url); |
| 256 test_fetcher.set_status(status); |
| 257 test_fetcher.set_response_code(RC_REQUEST_OK); |
| 258 test_fetcher.set_cookies(cookies); |
| 259 oauth_fetcher.OnURLFetchComplete(&test_fetcher); |
| 237 } | 260 } |
| OLD | NEW |