Chromium Code Reviews| Index: ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator_unittest.mm |
| diff --git a/ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator_unittest.mm b/ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cf73b94e37182279c786799f57b982ef1a84262 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator_unittest.mm |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
| + |
| +#import <UIKit/UIKit.h> |
| + |
| +#import "base/mac/foundation_util.h" |
| +#include "testing/platform_test.h" |
| + |
| +// Tests that if there is a popover, it uses the CGRect passed in init. |
| +TEST(ActionSheetCoordinatorTest, CGRectUsage) { |
| + // Setup. |
| + UIWindow* window = [[[UIWindow alloc] |
| + initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; |
| + [window makeKeyAndVisible]; |
| + UIViewController* viewController = |
| + [[[UIViewController alloc] init] autorelease]; |
| + [window setRootViewController:viewController]; |
| + |
| + UIView* view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] |
|
lpromero
2016/07/21 21:47:50
Optional nit: I'd use viewController.view.bounds i
gambard
2016/07/22 13:51:19
Done.
|
| + autorelease]; |
| + |
| + [viewController.view addSubview:view]; |
| + CGRect rect = CGRectMake(124, 432, 126, 63); |
| + AlertCoordinator* alertCoordinator = [[[ActionSheetCoordinator alloc] |
| + initWithBaseViewController:viewController |
| + title:@"title" |
| + message:nil |
| + rect:rect |
| + view:view] autorelease]; |
| + |
| + // Action. |
| + [alertCoordinator start]; |
| + |
| + // Test. |
| + // Get the alert. |
| + EXPECT_TRUE([viewController.presentedViewController |
| + isKindOfClass:[UIAlertController class]]); |
| + UIAlertController* alertController = |
| + base::mac::ObjCCastStrict<UIAlertController>( |
| + viewController.presentedViewController); |
| + |
| + // Test the results. |
| + EXPECT_EQ(UIAlertControllerStyleActionSheet, alertController.preferredStyle); |
| + |
| + if (alertController.popoverPresentationController) { |
| + UIPopoverPresentationController* popover = |
| + alertController.popoverPresentationController; |
| + EXPECT_TRUE(CGRectEqualToRect(rect, popover.sourceRect)); |
| + EXPECT_EQ(view, popover.sourceView); |
| + } |
| +} |