Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ios / public / test / fake_profile_oauth2_token_service_ios_provider.mm
blob492877319f382da37d8d665d03d79ad0028b6ef1
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.
5 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
7 #include <Foundation/Foundation.h>
9 #include "base/logging.h"
10 #include "base/strings/sys_string_conversions.h"
12 namespace ios {
14 FakeProfileOAuth2TokenServiceIOSProvider::
15     FakeProfileOAuth2TokenServiceIOSProvider() {}
17 FakeProfileOAuth2TokenServiceIOSProvider::
18     ~FakeProfileOAuth2TokenServiceIOSProvider() {}
20 void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken(
21     const std::string& account_id,
22     const std::string& client_id,
23     const std::string& client_secret,
24     const std::set<std::string>& scopes,
25     const AccessTokenCallback& callback) {
26   requests_.push_back(AccessTokenRequest(account_id, callback));
29 std::vector<std::string>
30 FakeProfileOAuth2TokenServiceIOSProvider::GetAllAccountIds() {
31   return accounts_;
34 void FakeProfileOAuth2TokenServiceIOSProvider::AddAccount(
35     const std::string& account_id) {
36   accounts_.push_back(account_id);
39 void FakeProfileOAuth2TokenServiceIOSProvider::SetAccounts(
40     const std::vector<std::string>& accounts) {
41   accounts_ = accounts;
44 void FakeProfileOAuth2TokenServiceIOSProvider::ClearAccounts() {
45   accounts_.clear();
48 void
49 FakeProfileOAuth2TokenServiceIOSProvider::IssueAccessTokenForAllRequests() {
50   for (auto i = requests_.begin(); i != requests_.end(); ++i) {
51     std::string account_id = i->first;
52     AccessTokenCallback callback = i->second;
53     NSString* access_token = [NSString
54         stringWithFormat:@"fake_access_token [account=%s]", account_id.c_str()];
55     NSDate* one_hour_from_now = [NSDate dateWithTimeIntervalSinceNow:3600];
56     callback.Run(access_token, one_hour_from_now, nil);
57   }
58   requests_.clear();
61 void FakeProfileOAuth2TokenServiceIOSProvider::
62     IssueAccessTokenErrorForAllRequests() {
63   for (auto i = requests_.begin(); i != requests_.end(); ++i) {
64     std::string account_id = i->first;
65     AccessTokenCallback callback = i->second;
66     NSError* error = [[[NSError alloc] initWithDomain:@"fake_access_token_error"
67                                                  code:-1
68                                              userInfo:nil] autorelease];
69     callback.Run(nil, nil, error);
70   }
71   requests_.clear();
74 void
75 FakeProfileOAuth2TokenServiceIOSProvider::InitializeSharedAuthentication() {}
77 AuthenticationErrorCategory
78 FakeProfileOAuth2TokenServiceIOSProvider::GetAuthenticationErrorCategory(
79     NSError* error) const {
80   DCHECK(error);
81   return ios::kAuthenticationErrorCategoryAuthorizationErrors;
84 }  // namespace ios