OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h" |
| 6 |
| 7 #include <Foundation/Foundation.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/sys_string_conversions.h" |
| 11 |
| 12 namespace ios { |
| 13 |
| 14 FakeProfileOAuth2TokenServiceIOSProvider:: |
| 15 FakeProfileOAuth2TokenServiceIOSProvider() |
| 16 : is_using_shared_authentication_(true) {} |
| 17 |
| 18 FakeProfileOAuth2TokenServiceIOSProvider:: |
| 19 ~FakeProfileOAuth2TokenServiceIOSProvider() {} |
| 20 |
| 21 void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken( |
| 22 const std::string& account_id, |
| 23 const std::string& client_id, |
| 24 const std::string& client_secret, |
| 25 const std::set<std::string>& scopes, |
| 26 const AccessTokenCallback& callback) { |
| 27 DCHECK(is_using_shared_authentication_); |
| 28 requests_.push_back(AccessTokenRequest(account_id, callback)); |
| 29 } |
| 30 |
| 31 std::vector<std::string> |
| 32 FakeProfileOAuth2TokenServiceIOSProvider::GetAllAccountIds() { |
| 33 return accounts_; |
| 34 } |
| 35 |
| 36 void FakeProfileOAuth2TokenServiceIOSProvider::AddAccount( |
| 37 const std::string& account_id) { |
| 38 accounts_.push_back(account_id); |
| 39 } |
| 40 |
| 41 void FakeProfileOAuth2TokenServiceIOSProvider::SetAccounts( |
| 42 const std::vector<std::string>& accounts) { |
| 43 accounts_ = accounts; |
| 44 } |
| 45 |
| 46 void FakeProfileOAuth2TokenServiceIOSProvider::ClearAccounts() { |
| 47 accounts_.clear(); |
| 48 } |
| 49 |
| 50 void |
| 51 FakeProfileOAuth2TokenServiceIOSProvider::IssueAccessTokenForAllRequests() { |
| 52 for (auto i = requests_.begin(); i != requests_.end(); ++i) { |
| 53 std::string account_id = i->first; |
| 54 AccessTokenCallback callback = i->second; |
| 55 NSString* access_token = [NSString |
| 56 stringWithFormat:@"fake_access_token [account=%s]", account_id.c_str()]; |
| 57 NSDate* one_hour_from_now = [NSDate dateWithTimeIntervalSinceNow:3600]; |
| 58 callback.Run(access_token, one_hour_from_now, nil); |
| 59 } |
| 60 requests_.clear(); |
| 61 } |
| 62 |
| 63 void FakeProfileOAuth2TokenServiceIOSProvider:: |
| 64 IssueAccessTokenErrorForAllRequests() { |
| 65 for (auto i = requests_.begin(); i != requests_.end(); ++i) { |
| 66 std::string account_id = i->first; |
| 67 AccessTokenCallback callback = i->second; |
| 68 NSError* error = [[[NSError alloc] initWithDomain:@"fake_access_token_error" |
| 69 code:-1 |
| 70 userInfo:nil] autorelease]; |
| 71 callback.Run(nil, nil, error); |
| 72 } |
| 73 requests_.clear(); |
| 74 } |
| 75 |
| 76 bool FakeProfileOAuth2TokenServiceIOSProvider::IsUsingSharedAuthentication() |
| 77 const { |
| 78 return is_using_shared_authentication_; |
| 79 } |
| 80 |
| 81 void |
| 82 FakeProfileOAuth2TokenServiceIOSProvider::InitializeSharedAuthentication() {} |
| 83 |
| 84 AuthenticationErrorCategory |
| 85 FakeProfileOAuth2TokenServiceIOSProvider::GetAuthenticationErrorCategory( |
| 86 NSError* error) const { |
| 87 DCHECK(error); |
| 88 return ios::kAuthenticationErrorCategoryAuthorizationErrors; |
| 89 } |
| 90 |
| 91 } // namespace ios |
OLD | NEW |