OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 5 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/mac/scoped_block.h" | 9 #include "base/mac/scoped_block.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "google_apis/gaia/gaia_auth_util.h" | 11 #include "google_apis/gaia/gaia_auth_util.h" |
12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
13 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 13 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
14 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interact
ion_manager.h" | 14 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_interact
ion_manager.h" |
15 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" | 15 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" |
16 | 16 |
17 using ::testing::_; | 17 using ::testing::_; |
18 using ::testing::Invoke; | 18 using ::testing::Invoke; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 void FakeGetAccessToken(ChromeIdentity*, | 22 void FakeGetAccessToken(ChromeIdentity*, |
23 const std::string&, | 23 const std::string&, |
24 const std::string&, | 24 const std::string&, |
25 const std::set<std::string>&, | 25 const std::set<std::string>&, |
26 const ios::AccessTokenCallback& callback) { | 26 const ios::AccessTokenCallback& callback) { |
27 base::mac::ScopedBlock<ios::AccessTokenCallback> safe_callback( | 27 ios::AccessTokenCallback safe_callback = [callback copy]; |
28 [callback copy]); | |
29 | 28 |
30 // |GetAccessToken| is normally an asynchronous operation (that requires some | 29 // |GetAccessToken| is normally an asynchronous operation (that requires some |
31 // network calls), this is replicated here by dispatching it. | 30 // network calls), this is replicated here by dispatching it. |
32 dispatch_async(dispatch_get_main_queue(), ^{ | 31 dispatch_async(dispatch_get_main_queue(), ^{ |
33 // Token and expiration date. It should be larger than typical test | 32 // Token and expiration date. It should be larger than typical test |
34 // execution because tests usually setup mock to expect one token request | 33 // execution because tests usually setup mock to expect one token request |
35 // and then rely on access token being served from cache. | 34 // and then rely on access token being served from cache. |
36 NSTimeInterval expiration = 60.0; | 35 NSTimeInterval expiration = 60.0; |
37 NSDate* expiresDate = [NSDate dateWithTimeIntervalSinceNow:expiration]; | 36 NSDate* expiresDate = [NSDate dateWithTimeIntervalSinceNow:expiration]; |
38 NSString* token = [expiresDate description]; | 37 NSString* token = [expiresDate description]; |
39 | 38 |
40 safe_callback.get()(token, expiresDate, nil); | 39 safe_callback(token, expiresDate, nil); |
41 }); | 40 }); |
42 } | 41 } |
43 | 42 |
44 UIImage* FakeGetCachedAvatarForIdentity(ChromeIdentity*) { | 43 UIImage* FakeGetCachedAvatarForIdentity(ChromeIdentity*) { |
45 ios::SigninResourcesProvider* provider = | 44 ios::SigninResourcesProvider* provider = |
46 ios::GetChromeBrowserProvider()->GetSigninResourcesProvider(); | 45 ios::GetChromeBrowserProvider()->GetSigninResourcesProvider(); |
47 return provider ? provider->GetDefaultAvatar() : nil; | 46 return provider ? provider->GetDefaultAvatar() : nil; |
48 } | 47 } |
49 | 48 |
50 void FakeGetAvatarForIdentity(ChromeIdentity* identity, | 49 void FakeGetAvatarForIdentity(ChromeIdentity* identity, |
(...skipping 13 matching lines...) Expand all Loading... |
64 // |GetHostedDomainForIdentity| is normally an asynchronous operation , this | 63 // |GetHostedDomainForIdentity| is normally an asynchronous operation , this |
65 // is replicated here by dispatching it. | 64 // is replicated here by dispatching it. |
66 dispatch_async(dispatch_get_main_queue(), ^{ | 65 dispatch_async(dispatch_get_main_queue(), ^{ |
67 callback(domain, nil); | 66 callback(domain, nil); |
68 }); | 67 }); |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 @interface FakeAccountDetailsViewController : UIViewController { | 71 @interface FakeAccountDetailsViewController : UIViewController { |
73 ChromeIdentity* _identity; // Weak. | 72 ChromeIdentity* _identity; // Weak. |
74 base::scoped_nsobject<UIButton> _removeAccountButton; | 73 UIButton* _removeAccountButton; |
75 } | 74 } |
76 @end | 75 @end |
77 | 76 |
78 @implementation FakeAccountDetailsViewController | 77 @implementation FakeAccountDetailsViewController |
79 | 78 |
80 - (instancetype)initWithIdentity:(ChromeIdentity*)identity { | 79 - (instancetype)initWithIdentity:(ChromeIdentity*)identity { |
81 self = [super initWithNibName:nil bundle:nil]; | 80 self = [super initWithNibName:nil bundle:nil]; |
82 if (self) { | 81 if (self) { |
83 _identity = identity; | 82 _identity = identity; |
84 } | 83 } |
85 return self; | 84 return self; |
86 } | 85 } |
87 | 86 |
88 - (void)dealloc { | 87 - (void)dealloc { |
89 [_removeAccountButton removeTarget:self | 88 [_removeAccountButton removeTarget:self |
90 action:@selector(didTapRemoveAccount:) | 89 action:@selector(didTapRemoveAccount:) |
91 forControlEvents:UIControlEventTouchUpInside]; | 90 forControlEvents:UIControlEventTouchUpInside]; |
92 [super dealloc]; | 91 [super dealloc]; |
93 } | 92 } |
94 | 93 |
95 - (void)viewDidLoad { | 94 - (void)viewDidLoad { |
96 [super viewDidLoad]; | 95 [super viewDidLoad]; |
97 | 96 |
98 // Obnoxious color, this is a test screen. | 97 // Obnoxious color, this is a test screen. |
99 self.view.backgroundColor = [UIColor orangeColor]; | 98 self.view.backgroundColor = [UIColor orangeColor]; |
100 | 99 |
101 _removeAccountButton.reset( | 100 _removeAccountButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; |
102 [[UIButton buttonWithType:UIButtonTypeCustom] retain]); | |
103 [_removeAccountButton setTitle:@"Remove account" | 101 [_removeAccountButton setTitle:@"Remove account" |
104 forState:UIControlStateNormal]; | 102 forState:UIControlStateNormal]; |
105 [_removeAccountButton addTarget:self | 103 [_removeAccountButton addTarget:self |
106 action:@selector(didTapRemoveAccount:) | 104 action:@selector(didTapRemoveAccount:) |
107 forControlEvents:UIControlEventTouchUpInside]; | 105 forControlEvents:UIControlEventTouchUpInside]; |
108 [self.view addSubview:_removeAccountButton]; | 106 [self.view addSubview:_removeAccountButton]; |
109 } | 107 } |
110 | 108 |
111 - (void)viewWillLayoutSubviews { | 109 - (void)viewWillLayoutSubviews { |
112 [super viewWillLayoutSubviews]; | 110 [super viewWillLayoutSubviews]; |
(...skipping 26 matching lines...) Expand all Loading... |
139 FakeChromeIdentityService* | 137 FakeChromeIdentityService* |
140 FakeChromeIdentityService::GetInstanceFromChromeProvider() { | 138 FakeChromeIdentityService::GetInstanceFromChromeProvider() { |
141 return static_cast<ios::FakeChromeIdentityService*>( | 139 return static_cast<ios::FakeChromeIdentityService*>( |
142 ios::GetChromeBrowserProvider()->GetChromeIdentityService()); | 140 ios::GetChromeBrowserProvider()->GetChromeIdentityService()); |
143 } | 141 } |
144 | 142 |
145 base::scoped_nsobject<UINavigationController> | 143 base::scoped_nsobject<UINavigationController> |
146 FakeChromeIdentityService::NewAccountDetails( | 144 FakeChromeIdentityService::NewAccountDetails( |
147 ChromeIdentity* identity, | 145 ChromeIdentity* identity, |
148 id<ChromeIdentityBrowserOpener> browser_opener) { | 146 id<ChromeIdentityBrowserOpener> browser_opener) { |
149 base::scoped_nsobject<UIViewController> accountDetailsViewController( | 147 UIViewController* accountDetailsViewController = |
150 [[FakeAccountDetailsViewController alloc] initWithIdentity:identity]); | 148 [[FakeAccountDetailsViewController alloc] initWithIdentity:identity]; |
151 base::scoped_nsobject<UINavigationController> navigationController( | 149 base::scoped_nsobject<UINavigationController> navigationController( |
152 [[UINavigationController alloc] | 150 [[UINavigationController alloc] |
153 initWithRootViewController:accountDetailsViewController]); | 151 initWithRootViewController:accountDetailsViewController]); |
154 return navigationController; | 152 return navigationController; |
155 } | 153 } |
156 | 154 |
157 base::scoped_nsobject<ChromeIdentityInteractionManager> | 155 base::scoped_nsobject<ChromeIdentityInteractionManager> |
158 FakeChromeIdentityService::NewChromeIdentityInteractionManager( | 156 FakeChromeIdentityService::NewChromeIdentityInteractionManager( |
159 ios::ChromeBrowserState* browser_state, | 157 ios::ChromeBrowserState* browser_state, |
160 id<ChromeIdentityInteractionManagerDelegate> delegate) const { | 158 id<ChromeIdentityInteractionManagerDelegate> delegate) const { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 252 } |
255 | 253 |
256 void FakeChromeIdentityService::RemoveIdentity(ChromeIdentity* identity) { | 254 void FakeChromeIdentityService::RemoveIdentity(ChromeIdentity* identity) { |
257 if ([identities_ indexOfObject:identity] != NSNotFound) { | 255 if ([identities_ indexOfObject:identity] != NSNotFound) { |
258 [identities_ removeObject:identity]; | 256 [identities_ removeObject:identity]; |
259 FireIdentityListChanged(); | 257 FireIdentityListChanged(); |
260 } | 258 } |
261 } | 259 } |
262 | 260 |
263 } // namespace ios | 261 } // namespace ios |
OLD | NEW |