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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 12 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
13 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 13 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
14 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | 14 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/net/gaia/google_service_auth_error.h" | 16 #include "chrome/common/net/gaia/google_service_auth_error.h" |
17 #include "chrome/common/net/http_return.h" | 17 #include "chrome/common/net/http_return.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "chrome/test/testing_browser_process_test.h" |
19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
20 #include "content/common/url_fetcher.h" | 21 #include "content/common/url_fetcher.h" |
21 #include "content/test/test_url_fetcher_factory.h" | 22 #include "content/test/test_url_fetcher_factory.h" |
22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 using ::testing::_; | 29 using ::testing::_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 std::string()); | 136 std::string()); |
136 EXPECT_CALL(auth, StartOAuthGetAccessToken(oauth_token)).Times(1); | 137 EXPECT_CALL(auth, StartOAuthGetAccessToken(oauth_token)).Times(1); |
137 | 138 |
138 auth.Observe( | 139 auth.Observe( |
139 chrome::NOTIFICATION_COOKIE_CHANGED, | 140 chrome::NOTIFICATION_COOKIE_CHANGED, |
140 Source<Profile>(&profile), | 141 Source<Profile>(&profile), |
141 Details<ChromeCookieDetails>(cookie_details.get())); | 142 Details<ChromeCookieDetails>(cookie_details.get())); |
142 } | 143 } |
143 #endif // 0 // Suppressing for now | 144 #endif // 0 // Suppressing for now |
144 | 145 |
| 146 typedef TestingBrowserProcessTest GaiaOAuthFetcherTest; |
145 | 147 |
146 TEST(GaiaOAuthFetcherTest, OAuthGetAccessToken) { | 148 TEST_F(GaiaOAuthFetcherTest, OAuthGetAccessToken) { |
147 const std::string oauth_token="1/OAuth1-Access_Token-1234567890abcdefghijklm"; | 149 const std::string oauth_token="1/OAuth1-Access_Token-1234567890abcdefghijklm"; |
148 const std::string oauth_token_secret="Dont_tell_the_secret-123"; | 150 const std::string oauth_token_secret="Dont_tell_the_secret-123"; |
149 const std::string data("oauth_token=" | 151 const std::string data("oauth_token=" |
150 "1%2FOAuth1-Access_Token-1234567890abcdefghijklm" | 152 "1%2FOAuth1-Access_Token-1234567890abcdefghijklm" |
151 "&oauth_token_secret=Dont_tell_the_secret-123"); | 153 "&oauth_token_secret=Dont_tell_the_secret-123"); |
152 | 154 |
153 MockGaiaOAuthConsumer consumer; | 155 MockGaiaOAuthConsumer consumer; |
154 EXPECT_CALL(consumer, | 156 EXPECT_CALL(consumer, |
155 OnOAuthGetAccessTokenSuccess(oauth_token, | 157 OnOAuthGetAccessTokenSuccess(oauth_token, |
156 oauth_token_secret)).Times(1); | 158 oauth_token_secret)).Times(1); |
(...skipping 11 matching lines...) Expand all Loading... |
168 net::ResponseCookies cookies; | 170 net::ResponseCookies cookies; |
169 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 171 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
170 auth.OnURLFetchComplete(NULL, | 172 auth.OnURLFetchComplete(NULL, |
171 GURL(kOAuthGetAccessTokenUrl), | 173 GURL(kOAuthGetAccessTokenUrl), |
172 status, | 174 status, |
173 RC_REQUEST_OK, | 175 RC_REQUEST_OK, |
174 cookies, | 176 cookies, |
175 data); | 177 data); |
176 } | 178 } |
177 | 179 |
178 TEST(GaiaOAuthFetcherTest, OAuthWrapBridge) { | 180 TEST_F(GaiaOAuthFetcherTest, OAuthWrapBridge) { |
179 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 181 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
180 const std::string expires_in="3600"; | 182 const std::string expires_in="3600"; |
181 | 183 |
182 const std::string data("wrap_access_token=" | 184 const std::string data("wrap_access_token=" |
183 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" | 185 "1%2FOAuth2-Access_Token-nopqrstuvwxyz1234567890" |
184 "&wrap_access_token_expires_in=3600"); | 186 "&wrap_access_token_expires_in=3600"); |
185 | 187 |
186 MockGaiaOAuthConsumer consumer; | 188 MockGaiaOAuthConsumer consumer; |
187 EXPECT_CALL(consumer, | 189 EXPECT_CALL(consumer, |
188 OnOAuthWrapBridgeSuccess(wrap_token, | 190 OnOAuthWrapBridgeSuccess(wrap_token, |
189 expires_in)).Times(1); | 191 expires_in)).Times(1); |
190 | 192 |
191 TestingProfile profile; | 193 TestingProfile profile; |
192 MockGaiaOAuthFetcher auth(&consumer, | 194 MockGaiaOAuthFetcher auth(&consumer, |
193 profile .GetRequestContext(), | 195 profile .GetRequestContext(), |
194 &profile, | 196 &profile, |
195 std::string()); | 197 std::string()); |
196 EXPECT_CALL(auth, StartUserInfo(wrap_token)).Times(1); | 198 EXPECT_CALL(auth, StartUserInfo(wrap_token)).Times(1); |
197 | 199 |
198 net::ResponseCookies cookies; | 200 net::ResponseCookies cookies; |
199 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 201 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
200 auth.OnURLFetchComplete(NULL, | 202 auth.OnURLFetchComplete(NULL, |
201 GURL(kOAuthWrapBridgeUrl), | 203 GURL(kOAuthWrapBridgeUrl), |
202 status, | 204 status, |
203 RC_REQUEST_OK, | 205 RC_REQUEST_OK, |
204 cookies, | 206 cookies, |
205 data); | 207 data); |
206 } | 208 } |
207 | 209 |
208 TEST(GaiaOAuthFetcherTest, UserInfo) { | 210 TEST_F(GaiaOAuthFetcherTest, UserInfo) { |
209 const std::string email_address="someone@somewhere.net"; | 211 const std::string email_address="someone@somewhere.net"; |
210 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 212 const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
211 const std::string expires_in="3600"; | 213 const std::string expires_in="3600"; |
212 | 214 |
213 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" | 215 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" |
214 " \"verified_email\": true\n}\n"); | 216 " \"verified_email\": true\n}\n"); |
215 MockGaiaOAuthConsumer consumer; | 217 MockGaiaOAuthConsumer consumer; |
216 EXPECT_CALL(consumer, | 218 EXPECT_CALL(consumer, |
217 OnUserInfoSuccess(email_address)).Times(1); | 219 OnUserInfoSuccess(email_address)).Times(1); |
218 | 220 |
219 TestingProfile profile; | 221 TestingProfile profile; |
220 MockGaiaOAuthFetcher auth(&consumer, | 222 MockGaiaOAuthFetcher auth(&consumer, |
221 profile .GetRequestContext(), | 223 profile .GetRequestContext(), |
222 &profile, | 224 &profile, |
223 std::string()); | 225 std::string()); |
224 | 226 |
225 net::ResponseCookies cookies; | 227 net::ResponseCookies cookies; |
226 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 228 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
227 auth.OnURLFetchComplete(NULL, | 229 auth.OnURLFetchComplete(NULL, |
228 GURL(kUserInfoUrl), | 230 GURL(kUserInfoUrl), |
229 status, | 231 status, |
230 RC_REQUEST_OK, | 232 RC_REQUEST_OK, |
231 cookies, | 233 cookies, |
232 data); | 234 data); |
233 } | 235 } |
OLD | NEW |