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

Side by Side Diff: ios/chrome/browser/ui/alert_coordinator/alert_coordinator_unittest.mm

Issue 2514843002: [ObjC ARC] Converts ios/chrome/browser/ui/alert_coordinator:unit_tests to ARC.Automatically gener… (Closed)
Patch Set: removed scoped_nsobject Created 4 years 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 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/chrome/browser/ui/alert_coordinator/alert_coordinator.h" 5 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #import "base/mac/scoped_nsobject.h"
11 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
12 #import "third_party/ocmock/OCMock/OCMock.h" 11 #import "third_party/ocmock/OCMock/OCMock.h"
13 #include "third_party/ocmock/gtest_support.h" 12 #include "third_party/ocmock/gtest_support.h"
14 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/strings/grit/ui_strings.h" 14 #include "ui/strings/grit/ui_strings.h"
16 15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
17 #pragma mark - Fixture. 20 #pragma mark - Fixture.
18 21
19 // Fixture to test AlertCoordinator. 22 // Fixture to test AlertCoordinator.
20 class AlertCoordinatorTest : public PlatformTest { 23 class AlertCoordinatorTest : public PlatformTest {
21 protected: 24 protected:
22 AlertCoordinatorTest() { 25 AlertCoordinatorTest() {
23 window_.reset( 26 window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
24 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
25 [window_ makeKeyAndVisible]; 27 [window_ makeKeyAndVisible];
26 view_controller_.reset([[UIViewController alloc] init]); 28 view_controller_ = [[UIViewController alloc] init];
27 [window_ setRootViewController:view_controller_]; 29 [window_ setRootViewController:view_controller_];
28 } 30 }
29 31
30 void startAlertCoordinator() { [alert_coordinator_ start]; } 32 void startAlertCoordinator() { [alert_coordinator_ start]; }
31 33
32 UIViewController* getViewController() { return view_controller_; } 34 UIViewController* getViewController() { return view_controller_; }
33 35
34 AlertCoordinator* getAlertCoordinator(UIViewController* viewController) { 36 AlertCoordinator* getAlertCoordinator(UIViewController* viewController) {
35 return getAlertCoordinator(viewController, @"Test title", nil); 37 return getAlertCoordinator(viewController, @"Test title", nil);
36 } 38 }
37 39
38 AlertCoordinator* getAlertCoordinator(UIViewController* viewController, 40 AlertCoordinator* getAlertCoordinator(UIViewController* viewController,
39 NSString* title, 41 NSString* title,
40 NSString* message) { 42 NSString* message) {
41 alert_coordinator_.reset([[AlertCoordinator alloc] 43 alert_coordinator_ =
42 initWithBaseViewController:viewController 44 [[AlertCoordinator alloc] initWithBaseViewController:viewController
43 title:title 45 title:title
44 message:message]); 46 message:message];
45 return alert_coordinator_; 47 return alert_coordinator_;
46 } 48 }
47 49
48 private: 50 private:
49 base::scoped_nsobject<AlertCoordinator> alert_coordinator_; 51 AlertCoordinator* alert_coordinator_;
50 base::scoped_nsobject<UIWindow> window_; 52 UIWindow* window_;
51 base::scoped_nsobject<UIViewController> view_controller_; 53 UIViewController* view_controller_;
52 }; 54 };
53 55
54 #pragma mark - Tests. 56 #pragma mark - Tests.
55 57
56 // Tests the alert coordinator reports as visible after presenting and at least 58 // Tests the alert coordinator reports as visible after presenting and at least
57 // on button is created. 59 // on button is created.
58 TEST_F(AlertCoordinatorTest, ValidateIsVisible) { 60 TEST_F(AlertCoordinatorTest, ValidateIsVisible) {
59 // Setup. 61 // Setup.
60 UIViewController* viewController = getViewController(); 62 UIViewController* viewController = getViewController();
61 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); 63 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
(...skipping 11 matching lines...) Expand all
73 UIAlertController* alertController = 75 UIAlertController* alertController =
74 base::mac::ObjCCastStrict<UIAlertController>( 76 base::mac::ObjCCastStrict<UIAlertController>(
75 viewController.presentedViewController); 77 viewController.presentedViewController);
76 EXPECT_EQ(1LU, alertController.actions.count); 78 EXPECT_EQ(1LU, alertController.actions.count);
77 } 79 }
78 80
79 // Tests the alert coordinator reports as not visible after presenting on a non 81 // Tests the alert coordinator reports as not visible after presenting on a non
80 // visible view. 82 // visible view.
81 TEST_F(AlertCoordinatorTest, ValidateIsNotVisible) { 83 TEST_F(AlertCoordinatorTest, ValidateIsNotVisible) {
82 // Setup. 84 // Setup.
83 base::scoped_nsobject<UIWindow> window( 85 UIWindow* window =
84 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); 86 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
85 base::scoped_nsobject<UIViewController> viewController( 87 UIViewController* viewController = [[UIViewController alloc] init];
86 [[UIViewController alloc] init]);
87 [window setRootViewController:viewController]; 88 [window setRootViewController:viewController];
88 89
89 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); 90 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
90 91
91 // Action. 92 // Action.
92 startAlertCoordinator(); 93 startAlertCoordinator();
93 94
94 // Test. 95 // Test.
95 EXPECT_FALSE(alertCoordinator.isVisible); 96 EXPECT_FALSE(alertCoordinator.isVisible);
96 EXPECT_EQ(nil, [viewController presentedViewController]); 97 EXPECT_EQ(nil, [viewController presentedViewController]);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); 155 AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
155 156
156 NSDictionary* actions = @{ 157 NSDictionary* actions = @{
157 @"foo" : @(UIAlertActionStyleDestructive), 158 @"foo" : @(UIAlertActionStyleDestructive),
158 @"foo2" : @(UIAlertActionStyleDestructive), 159 @"foo2" : @(UIAlertActionStyleDestructive),
159 @"bar" : @(UIAlertActionStyleDefault), 160 @"bar" : @(UIAlertActionStyleDefault),
160 @"bar2" : @(UIAlertActionStyleDefault), 161 @"bar2" : @(UIAlertActionStyleDefault),
161 @"testCancel" : @(UIAlertActionStyleCancel), 162 @"testCancel" : @(UIAlertActionStyleCancel),
162 }; 163 };
163 164
164 base::scoped_nsobject<NSMutableDictionary> remainingActions( 165 NSMutableDictionary* remainingActions = [actions mutableCopy];
165 [actions mutableCopy]);
166 166
167 // Action. 167 // Action.
168 for (id key in actions) { 168 for (id key in actions) {
169 UIAlertActionStyle style = 169 UIAlertActionStyle style =
170 static_cast<UIAlertActionStyle>([actions[key] integerValue]); 170 static_cast<UIAlertActionStyle>([actions[key] integerValue]);
171 [alertCoordinator addItemWithTitle:key action:nil style:style]; 171 [alertCoordinator addItemWithTitle:key action:nil style:style];
172 } 172 }
173 173
174 // Test. 174 // Test.
175 // Present the alert. 175 // Present the alert.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 startAlertCoordinator(); 263 startAlertCoordinator();
264 264
265 // Action. 265 // Action.
266 [alertCoordinator executeCancelHandler]; 266 [alertCoordinator executeCancelHandler];
267 [alertCoordinator stop]; 267 [alertCoordinator stop];
268 268
269 // Test. 269 // Test.
270 EXPECT_FALSE(blockCalled); 270 EXPECT_FALSE(blockCalled);
271 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698