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