OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "google_apis/gaia/account_tracker.h" | 5 #include "google_apis/gaia/account_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 const char kPrimaryAccountKey[] = "primary_account@example.com"; | 23 const char kPrimaryAccountKey[] = "primary_account@example.com"; |
24 | 24 |
25 enum TrackingEventType { | 25 enum TrackingEventType { |
26 ADDED, | 26 ADDED, |
27 REMOVED, | 27 REMOVED, |
28 SIGN_IN, | 28 SIGN_IN, |
29 SIGN_OUT | 29 SIGN_OUT |
30 }; | 30 }; |
31 | 31 |
32 std::string AccountKeyToObfuscatedId(const std::string email) { | 32 std::string AccountKeyToObfuscatedId(const std::string& email) { |
33 return "obfid-" + email; | 33 return "obfid-" + email; |
34 } | 34 } |
35 | 35 |
36 class TrackingEvent { | 36 class TrackingEvent { |
37 public: | 37 public: |
38 TrackingEvent(TrackingEventType type, | 38 TrackingEvent(TrackingEventType type, |
39 const std::string& account_key, | 39 const std::string& account_key, |
40 const std::string& gaia_id) | 40 const std::string& gaia_id) |
41 : type_(type), | 41 : type_(type), |
42 account_key_(account_key), | 42 account_key_(account_key), |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 AccountTrackerObserver* observer() { | 287 AccountTrackerObserver* observer() { |
288 return &observer_; | 288 return &observer_; |
289 } | 289 } |
290 | 290 |
291 AccountTracker* account_tracker() { | 291 AccountTracker* account_tracker() { |
292 return account_tracker_.get(); | 292 return account_tracker_.get(); |
293 } | 293 } |
294 | 294 |
295 // Helpers to pass fake events to the tracker. | 295 // Helpers to pass fake events to the tracker. |
296 | 296 |
297 void NotifyLogin(const std::string account_key) { | 297 void NotifyLogin(const std::string& account_key) { |
298 identity_provider()->LogIn(account_key); | 298 identity_provider()->LogIn(account_key); |
299 } | 299 } |
300 | 300 |
301 void NotifyLogout() { identity_provider()->LogOut(); } | 301 void NotifyLogout() { identity_provider()->LogOut(); } |
302 | 302 |
303 void NotifyTokenAvailable(const std::string& username) { | 303 void NotifyTokenAvailable(const std::string& username) { |
304 fake_oauth2_token_service_->AddAccount(username); | 304 fake_oauth2_token_service_->AddAccount(username); |
305 } | 305 } |
306 | 306 |
307 void NotifyTokenRevoked(const std::string& username) { | 307 void NotifyTokenRevoked(const std::string& username) { |
308 fake_oauth2_token_service_->RemoveAccount(username); | 308 fake_oauth2_token_service_->RemoveAccount(username); |
309 } | 309 } |
310 | 310 |
311 // Helpers to fake access token and user info fetching | 311 // Helpers to fake access token and user info fetching |
312 void IssueAccessToken(const std::string& username) { | 312 void IssueAccessToken(const std::string& username) { |
313 fake_oauth2_token_service_->IssueAllTokensForAccount( | 313 fake_oauth2_token_service_->IssueAllTokensForAccount( |
314 username, "access_token-" + username, base::Time::Max()); | 314 username, "access_token-" + username, base::Time::Max()); |
315 } | 315 } |
316 | 316 |
317 std::string GetValidTokenInfoResponse(const std::string account_key) { | 317 std::string GetValidTokenInfoResponse(const std::string& account_key) { |
318 return std::string("{ \"id\": \"") + AccountKeyToObfuscatedId(account_key) + | 318 return std::string("{ \"id\": \"") + AccountKeyToObfuscatedId(account_key) + |
319 "\" }"; | 319 "\" }"; |
320 } | 320 } |
321 | 321 |
322 void ReturnOAuthUrlFetchResults(int fetcher_id, | 322 void ReturnOAuthUrlFetchResults(int fetcher_id, |
323 net::HttpStatusCode response_code, | 323 net::HttpStatusCode response_code, |
324 const std::string& response_string); | 324 const std::string& response_string); |
325 | 325 |
326 void ReturnOAuthUrlFetchSuccess(const std::string& account_key); | 326 void ReturnOAuthUrlFetchSuccess(const std::string& account_key); |
327 void ReturnOAuthUrlFetchFailure(const std::string& account_key); | 327 void ReturnOAuthUrlFetchFailure(const std::string& account_key); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 EXPECT_TRUE(ids.email.empty()); | 806 EXPECT_TRUE(ids.email.empty()); |
807 EXPECT_TRUE(ids.gaia.empty()); | 807 EXPECT_TRUE(ids.gaia.empty()); |
808 | 808 |
809 ids = account_tracker()->FindAccountIdsByGaiaId("alpha@example.com"); | 809 ids = account_tracker()->FindAccountIdsByGaiaId("alpha@example.com"); |
810 EXPECT_TRUE(ids.account_key.empty()); | 810 EXPECT_TRUE(ids.account_key.empty()); |
811 EXPECT_TRUE(ids.email.empty()); | 811 EXPECT_TRUE(ids.email.empty()); |
812 EXPECT_TRUE(ids.gaia.empty()); | 812 EXPECT_TRUE(ids.gaia.empty()); |
813 } | 813 } |
814 | 814 |
815 } // namespace gaia | 815 } // namespace gaia |
OLD | NEW |