Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: ios/chrome/browser/ui/authentication/re_signin_infobar_delegate_unittest.mm

Issue 2675243003: [ObjC ARC] Converts ios/chrome/browser/ui/authentication:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ios/chrome/browser/ui/authentication/re_signin_infobar_delegate.h" 5 #include "ios/chrome/browser/ui/authentication/re_signin_infobar_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/mac/objc_property_releaser.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
12 #include "components/sync_preferences/testing_pref_service_syncable.h" 10 #include "components/sync_preferences/testing_pref_service_syncable.h"
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
14 #include "ios/chrome/browser/infobars/confirm_infobar_controller.h" 12 #include "ios/chrome/browser/infobars/confirm_infobar_controller.h"
15 #include "ios/chrome/browser/infobars/infobar.h" 13 #include "ios/chrome/browser/infobars/infobar.h"
16 #include "ios/chrome/browser/infobars/infobar_utils.h" 14 #include "ios/chrome/browser/infobars/infobar_utils.h"
17 #include "ios/chrome/browser/signin/authentication_service.h" 15 #include "ios/chrome/browser/signin/authentication_service.h"
18 #include "ios/chrome/browser/signin/authentication_service_factory.h" 16 #include "ios/chrome/browser/signin/authentication_service_factory.h"
19 #include "ios/chrome/browser/signin/authentication_service_fake.h" 17 #include "ios/chrome/browser/signin/authentication_service_fake.h"
20 #include "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 18 #include "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
21 #import "ios/chrome/browser/ui/commands/show_signin_command.h" 19 #import "ios/chrome/browser/ui/commands/show_signin_command.h"
22 #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" 20 #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
23 #include "ios/web/public/test/test_web_thread_bundle.h" 21 #include "ios/web/public/test/test_web_thread_bundle.h"
24 #include "testing/gtest_mac.h" 22 #include "testing/gtest_mac.h"
25 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
26 24
25 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support."
27 #endif
28
27 // View that intercepts and stores chrome commands sent up the responder chain. 29 // View that intercepts and stores chrome commands sent up the responder chain.
28 @interface CatchExecuteCommandView : UIView { 30 @interface CatchExecuteCommandView : UIView {
29 base::mac::ObjCPropertyReleaser propertyReleaser_CatchExecuteCommandView_;
30 } 31 }
31 // Command sent up the responder chain and intercepted by this view. 32 // Command sent up the responder chain and intercepted by this view.
32 @property(nonatomic, retain) id command; 33 @property(nonatomic, strong) id command;
33 @end 34 @end
34 35
35 @implementation CatchExecuteCommandView 36 @implementation CatchExecuteCommandView
36 37
37 @synthesize command = _command; 38 @synthesize command = _command;
38 39
39 - (instancetype)initWithFrame:(CGRect)frame { 40 - (instancetype)initWithFrame:(CGRect)frame {
40 self = [super initWithFrame:frame]; 41 self = [super initWithFrame:frame];
41 if (self) { 42 if (self) {
42 propertyReleaser_CatchExecuteCommandView_.Init(
43 self, [CatchExecuteCommandView class]);
44 } 43 }
45 return self; 44 return self;
46 } 45 }
47 46
48 - (void)chromeExecuteCommand:(id)command { 47 - (void)chromeExecuteCommand:(id)command {
49 DCHECK(command); 48 DCHECK(command);
50 DCHECK(!self.command); 49 DCHECK(!self.command);
51 self.command = command; 50 self.command = command;
52 } 51 }
53 52
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 SetUpMainChromeBrowserStateNotSignedIn(); 171 SetUpMainChromeBrowserStateNotSignedIn();
173 AuthenticationService* authService = 172 AuthenticationService* authService =
174 AuthenticationServiceFactory::GetForBrowserState( 173 AuthenticationServiceFactory::GetForBrowserState(
175 chrome_browser_state_.get()); 174 chrome_browser_state_.get());
176 authService->SetPromptForSignIn(true); 175 authService->SetPromptForSignIn(true);
177 std::unique_ptr<infobars::InfoBar> infobar( 176 std::unique_ptr<infobars::InfoBar> infobar(
178 CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate( 177 CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate(
179 chrome_browser_state_.get()))); 178 chrome_browser_state_.get())));
180 InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get()); 179 InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get());
181 infobarIOS->Layout(CGRectZero); 180 infobarIOS->Layout(CGRectZero);
182 base::scoped_nsobject<CatchExecuteCommandView> view( 181 CatchExecuteCommandView* view =
183 [[CatchExecuteCommandView alloc] initWithFrame:CGRectZero]); 182 [[CatchExecuteCommandView alloc] initWithFrame:CGRectZero];
184 [view.get() addSubview:infobarIOS->view()]; 183 [view addSubview:infobarIOS->view()];
185 184
186 ReSignInInfoBarDelegate* delegate = 185 ReSignInInfoBarDelegate* delegate =
187 static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate()); 186 static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate());
188 EXPECT_TRUE(delegate->Accept()); 187 EXPECT_TRUE(delegate->Accept());
189 EXPECT_FALSE(authService->ShouldPromptForSignIn()); 188 EXPECT_FALSE(authService->ShouldPromptForSignIn());
190 EXPECT_TRUE([view command]); 189 EXPECT_TRUE([view command]);
191 EXPECT_TRUE([[view command] isKindOfClass:[ShowSigninCommand class]]); 190 EXPECT_TRUE([[view command] isKindOfClass:[ShowSigninCommand class]]);
192 EXPECT_EQ(AUTHENTICATION_OPERATION_REAUTHENTICATE, 191 EXPECT_EQ(AUTHENTICATION_OPERATION_REAUTHENTICATE,
193 static_cast<ShowSigninCommand*>([view command]).operation); 192 static_cast<ShowSigninCommand*>([view command]).operation);
194 } 193 }
195 194
196 TEST_F(ReSignInInfoBarDelegateTest, TestInfoBarDismissed) { 195 TEST_F(ReSignInInfoBarDelegateTest, TestInfoBarDismissed) {
197 SetUpMainChromeBrowserStateNotSignedIn(); 196 SetUpMainChromeBrowserStateNotSignedIn();
198 AuthenticationService* authService = 197 AuthenticationService* authService =
199 AuthenticationServiceFactory::GetForBrowserState( 198 AuthenticationServiceFactory::GetForBrowserState(
200 chrome_browser_state_.get()); 199 chrome_browser_state_.get());
201 authService->SetPromptForSignIn(true); 200 authService->SetPromptForSignIn(true);
202 std::unique_ptr<infobars::InfoBar> infobar( 201 std::unique_ptr<infobars::InfoBar> infobar(
203 CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate( 202 CreateConfirmInfoBar(ReSignInInfoBarDelegate::CreateInfoBarDelegate(
204 chrome_browser_state_.get()))); 203 chrome_browser_state_.get())));
205 InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get()); 204 InfoBarIOS* infobarIOS = static_cast<InfoBarIOS*>(infobar.get());
206 infobarIOS->Layout(CGRectZero); 205 infobarIOS->Layout(CGRectZero);
207 base::scoped_nsobject<CatchExecuteCommandView> view( 206 CatchExecuteCommandView* view =
208 [[CatchExecuteCommandView alloc] initWithFrame:CGRectZero]); 207 [[CatchExecuteCommandView alloc] initWithFrame:CGRectZero];
209 [view.get() addSubview:infobarIOS->view()]; 208 [view addSubview:infobarIOS->view()];
210 209
211 ReSignInInfoBarDelegate* delegate = 210 ReSignInInfoBarDelegate* delegate =
212 static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate()); 211 static_cast<ReSignInInfoBarDelegate*>(infobarIOS->delegate());
213 delegate->InfoBarDismissed(); 212 delegate->InfoBarDismissed();
214 EXPECT_FALSE(authService->ShouldPromptForSignIn()); 213 EXPECT_FALSE(authService->ShouldPromptForSignIn());
215 EXPECT_FALSE([view command]); 214 EXPECT_FALSE([view command]);
216 } 215 }
217 216
218 } // namespace 217 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698