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/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" | 5 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_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 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
12 // Tests that if there is a popover, it uses the CGRect passed in init. | 16 // Tests that if there is a popover, it uses the CGRect passed in init. |
13 TEST(ActionSheetCoordinatorTest, CGRectUsage) { | 17 TEST(ActionSheetCoordinatorTest, CGRectUsage) { |
14 // Setup. | 18 // Setup. |
15 UIWindow* window = [[[UIWindow alloc] | 19 UIWindow* window = |
16 initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; | 20 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
17 [window makeKeyAndVisible]; | 21 [window makeKeyAndVisible]; |
18 UIViewController* viewController = | 22 UIViewController* viewController = [[UIViewController alloc] init]; |
19 [[[UIViewController alloc] init] autorelease]; | |
20 [window setRootViewController:viewController]; | 23 [window setRootViewController:viewController]; |
21 | 24 |
22 UIView* view = | 25 UIView* view = [[UIView alloc] initWithFrame:viewController.view.bounds]; |
23 [[[UIView alloc] initWithFrame:viewController.view.bounds] autorelease]; | |
24 | 26 |
25 [viewController.view addSubview:view]; | 27 [viewController.view addSubview:view]; |
26 CGRect rect = CGRectMake(124, 432, 126, 63); | 28 CGRect rect = CGRectMake(124, 432, 126, 63); |
27 AlertCoordinator* alertCoordinator = [[[ActionSheetCoordinator alloc] | 29 AlertCoordinator* alertCoordinator = |
28 initWithBaseViewController:viewController | 30 [[ActionSheetCoordinator alloc] initWithBaseViewController:viewController |
29 title:@"title" | 31 title:@"title" |
30 message:nil | 32 message:nil |
31 rect:rect | 33 rect:rect |
32 view:view] autorelease]; | 34 view:view]; |
33 | 35 |
34 // Action. | 36 // Action. |
35 [alertCoordinator start]; | 37 [alertCoordinator start]; |
36 | 38 |
37 // Test. | 39 // Test. |
38 // Get the alert. | 40 // Get the alert. |
39 EXPECT_TRUE([viewController.presentedViewController | 41 EXPECT_TRUE([viewController.presentedViewController |
40 isKindOfClass:[UIAlertController class]]); | 42 isKindOfClass:[UIAlertController class]]); |
41 UIAlertController* alertController = | 43 UIAlertController* alertController = |
42 base::mac::ObjCCastStrict<UIAlertController>( | 44 base::mac::ObjCCastStrict<UIAlertController>( |
43 viewController.presentedViewController); | 45 viewController.presentedViewController); |
44 | 46 |
45 // Test the results. | 47 // Test the results. |
46 EXPECT_EQ(UIAlertControllerStyleActionSheet, alertController.preferredStyle); | 48 EXPECT_EQ(UIAlertControllerStyleActionSheet, alertController.preferredStyle); |
47 | 49 |
48 if (alertController.popoverPresentationController) { | 50 if (alertController.popoverPresentationController) { |
49 UIPopoverPresentationController* popover = | 51 UIPopoverPresentationController* popover = |
50 alertController.popoverPresentationController; | 52 alertController.popoverPresentationController; |
51 EXPECT_TRUE(CGRectEqualToRect(rect, popover.sourceRect)); | 53 EXPECT_TRUE(CGRectEqualToRect(rect, popover.sourceRect)); |
52 EXPECT_EQ(view, popover.sourceView); | 54 EXPECT_EQ(view, popover.sourceView); |
53 } | 55 } |
54 | 56 |
55 [alertCoordinator stop]; | 57 [alertCoordinator stop]; |
56 } | 58 } |
OLD | NEW |