Commit bf04d632 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Update AlertCoordinator unit tests style

Those tests should follow the style guide.

Bug: 1023877
Change-Id: I81ba3f106426fd04d0ad256cc90b7c2dc8325d35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1916859
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715244}
parent f161b990
...@@ -28,19 +28,19 @@ class AlertCoordinatorTest : public PlatformTest { ...@@ -28,19 +28,19 @@ class AlertCoordinatorTest : public PlatformTest {
[scoped_key_window_.Get() setRootViewController:view_controller_]; [scoped_key_window_.Get() setRootViewController:view_controller_];
} }
void startAlertCoordinator() { [alert_coordinator_ start]; } void StartAlertCoordinator() { [alert_coordinator_ start]; }
UIViewController* getViewController() { return view_controller_; } UIViewController* GetViewController() { return view_controller_; }
AlertCoordinator* getAlertCoordinator(UIViewController* viewController) { AlertCoordinator* GetAlertCoordinator(UIViewController* view_controller) {
return getAlertCoordinator(viewController, @"Test title", nil); return GetAlertCoordinator(view_controller, @"Test title", nil);
} }
AlertCoordinator* getAlertCoordinator(UIViewController* viewController, AlertCoordinator* GetAlertCoordinator(UIViewController* view_controller,
NSString* title, NSString* title,
NSString* message) { NSString* message) {
alert_coordinator_ = alert_coordinator_ =
[[AlertCoordinator alloc] initWithBaseViewController:viewController [[AlertCoordinator alloc] initWithBaseViewController:view_controller
title:title title:title
message:message]; message:message];
return alert_coordinator_; return alert_coordinator_;
...@@ -58,23 +58,23 @@ class AlertCoordinatorTest : public PlatformTest { ...@@ -58,23 +58,23 @@ class AlertCoordinatorTest : public PlatformTest {
// on button is created. // on button is created.
TEST_F(AlertCoordinatorTest, ValidateIsVisible) { TEST_F(AlertCoordinatorTest, ValidateIsVisible) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
ASSERT_FALSE(alertCoordinator.isVisible); ASSERT_FALSE(alert_coordinator.visible);
ASSERT_EQ(nil, viewController.presentedViewController); ASSERT_EQ(nil, view_controller.presentedViewController);
// Action. // Action.
startAlertCoordinator(); StartAlertCoordinator();
// Test. // Test.
EXPECT_TRUE(alertCoordinator.isVisible); EXPECT_TRUE(alert_coordinator.visible);
EXPECT_TRUE([viewController.presentedViewController EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]); isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController = UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>( base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController); view_controller.presentedViewController);
EXPECT_EQ(1LU, alertController.actions.count); EXPECT_EQ(1LU, alert_controller.actions.count);
} }
// Tests the alert coordinator reports as not visible after presenting on a non // Tests the alert coordinator reports as not visible after presenting on a non
...@@ -83,75 +83,75 @@ TEST_F(AlertCoordinatorTest, ValidateIsNotVisible) { ...@@ -83,75 +83,75 @@ TEST_F(AlertCoordinatorTest, ValidateIsNotVisible) {
// Setup. // Setup.
UIWindow* window = UIWindow* window =
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* viewController = [[UIViewController alloc] init]; UIViewController* view_controller = [[UIViewController alloc] init];
[window setRootViewController:viewController]; [window setRootViewController:view_controller];
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
// Action. // Action.
startAlertCoordinator(); StartAlertCoordinator();
// Test. // Test.
EXPECT_FALSE(alertCoordinator.isVisible); EXPECT_FALSE(alert_coordinator.visible);
EXPECT_EQ(nil, [viewController presentedViewController]); EXPECT_EQ(nil, [view_controller presentedViewController]);
} }
// Tests the alert coordinator has a correct title and message. // Tests the alert coordinator has a correct title and message.
TEST_F(AlertCoordinatorTest, TitleAndMessage) { TEST_F(AlertCoordinatorTest, TitleAndMessage) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
NSString* title = @"Foo test title!"; NSString* title = @"Foo test title!";
NSString* message = @"Foo bar message."; NSString* message = @"Foo bar message.";
getAlertCoordinator(viewController, title, message); GetAlertCoordinator(view_controller, title, message);
// Action. // Action.
startAlertCoordinator(); StartAlertCoordinator();
// Test. // Test.
// Get the alert. // Get the alert.
EXPECT_TRUE([viewController.presentedViewController EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]); isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController = UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>( base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController); view_controller.presentedViewController);
// Test the results. // Test the results.
EXPECT_EQ(title, alertController.title); EXPECT_EQ(title, alert_controller.title);
EXPECT_EQ(message, alertController.message); EXPECT_EQ(message, alert_controller.message);
} }
// Tests the alert coordinator dismissal. // Tests the alert coordinator dismissal.
TEST_F(AlertCoordinatorTest, ValidateDismissalOnStop) { TEST_F(AlertCoordinatorTest, ValidateDismissalOnStop) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
startAlertCoordinator(); StartAlertCoordinator();
ASSERT_TRUE(alertCoordinator.isVisible); ASSERT_TRUE(alert_coordinator.visible);
ASSERT_NE(nil, viewController.presentedViewController); ASSERT_NE(nil, view_controller.presentedViewController);
ASSERT_TRUE([viewController.presentedViewController ASSERT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]); isKindOfClass:[UIAlertController class]]);
id viewControllerMock = [OCMockObject partialMockForObject:viewController]; id viewControllerMock = [OCMockObject partialMockForObject:view_controller];
[[[viewControllerMock expect] andForwardToRealObject] [[[viewControllerMock expect] andForwardToRealObject]
dismissViewControllerAnimated:NO dismissViewControllerAnimated:NO
completion:nil]; completion:nil];
// Action. // Action.
[alertCoordinator stop]; [alert_coordinator stop];
// Test. // Test.
EXPECT_FALSE(alertCoordinator.isVisible); EXPECT_FALSE(alert_coordinator.visible);
EXPECT_OCMOCK_VERIFY(viewControllerMock); EXPECT_OCMOCK_VERIFY(viewControllerMock);
} }
// Tests that only the expected actions are present on the alert. // Tests that only the expected actions are present on the alert.
TEST_F(AlertCoordinatorTest, ValidateActions) { TEST_F(AlertCoordinatorTest, ValidateActions) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
NSDictionary* actions = @{ NSDictionary* actions = @{
@"foo" : @(UIAlertActionStyleDestructive), @"foo" : @(UIAlertActionStyleDestructive),
...@@ -167,22 +167,22 @@ TEST_F(AlertCoordinatorTest, ValidateActions) { ...@@ -167,22 +167,22 @@ TEST_F(AlertCoordinatorTest, ValidateActions) {
for (id key in actions) { for (id key in actions) {
UIAlertActionStyle style = UIAlertActionStyle style =
static_cast<UIAlertActionStyle>([actions[key] integerValue]); static_cast<UIAlertActionStyle>([actions[key] integerValue]);
[alertCoordinator addItemWithTitle:key action:nil style:style]; [alert_coordinator addItemWithTitle:key action:nil style:style];
} }
// Test. // Test.
// Present the alert. // Present the alert.
startAlertCoordinator(); StartAlertCoordinator();
// Get the alert. // Get the alert.
EXPECT_TRUE([viewController.presentedViewController EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]); isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController = UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>( base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController); view_controller.presentedViewController);
// Test the results. // Test the results.
for (UIAlertAction* action in alertController.actions) { for (UIAlertAction* action in alert_controller.actions) {
EXPECT_TRUE([remainingActions objectForKey:action.title]); EXPECT_TRUE([remainingActions objectForKey:action.title]);
UIAlertActionStyle style = UIAlertActionStyle style =
static_cast<UIAlertActionStyle>([actions[action.title] integerValue]); static_cast<UIAlertActionStyle>([actions[action.title] integerValue]);
...@@ -196,34 +196,34 @@ TEST_F(AlertCoordinatorTest, ValidateActions) { ...@@ -196,34 +196,34 @@ TEST_F(AlertCoordinatorTest, ValidateActions) {
// Tests that only the first cancel action is added. // Tests that only the first cancel action is added.
TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) { TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
NSString* firstButtonTitle = @"Cancel1"; NSString* firstButtonTitle = @"Cancel1";
// Action. // Action.
[alertCoordinator addItemWithTitle:firstButtonTitle [alert_coordinator addItemWithTitle:firstButtonTitle
action:nil action:nil
style:UIAlertActionStyleCancel]; style:UIAlertActionStyleCancel];
[alertCoordinator addItemWithTitle:@"Cancel2" [alert_coordinator addItemWithTitle:@"Cancel2"
action:nil action:nil
style:UIAlertActionStyleCancel]; style:UIAlertActionStyleCancel];
// Test. // Test.
// Present the alert. // Present the alert.
startAlertCoordinator(); StartAlertCoordinator();
// Get the alert. // Get the alert.
EXPECT_TRUE([viewController.presentedViewController EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]); isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController = UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>( base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController); view_controller.presentedViewController);
// Test the results. // Test the results.
EXPECT_EQ(1LU, alertController.actions.count); EXPECT_EQ(1LU, alert_controller.actions.count);
UIAlertAction* action = [alertController.actions objectAtIndex:0]; UIAlertAction* action = [alert_controller.actions objectAtIndex:0];
EXPECT_EQ(firstButtonTitle, action.title); EXPECT_EQ(firstButtonTitle, action.title);
EXPECT_EQ(UIAlertActionStyleCancel, action.style); EXPECT_EQ(UIAlertActionStyleCancel, action.style);
} }
...@@ -232,66 +232,66 @@ TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) { ...@@ -232,66 +232,66 @@ TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) {
// which is stopped before the user has interacted with it. // which is stopped before the user has interacted with it.
TEST_F(AlertCoordinatorTest, NoInteractionActionTest) { TEST_F(AlertCoordinatorTest, NoInteractionActionTest) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
__block BOOL blockCalled = NO; __block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{ alert_coordinator.noInteractionAction = ^{
blockCalled = YES; block_called = YES;
}; };
startAlertCoordinator(); StartAlertCoordinator();
// Action. // Action.
[alertCoordinator stop]; [alert_coordinator stop];
// Test. // Test.
EXPECT_TRUE(blockCalled); EXPECT_TRUE(block_called);
} }
// Tests that the |noInteractionAction| block is not called for an alert // Tests that the |noInteractionAction| block is not called for an alert
// coordinator which is dismissed with the cancel button. // coordinator which is dismissed with the cancel button.
TEST_F(AlertCoordinatorTest, NoInteractionActionWithCancelTest) { TEST_F(AlertCoordinatorTest, NoInteractionActionWithCancelTest) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
__block BOOL blockCalled = NO; __block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{ alert_coordinator.noInteractionAction = ^{
blockCalled = YES; block_called = YES;
}; };
startAlertCoordinator(); StartAlertCoordinator();
// Action. // Action.
[alertCoordinator executeCancelHandler]; [alert_coordinator executeCancelHandler];
[alertCoordinator stop]; [alert_coordinator stop];
// Test. // Test.
EXPECT_FALSE(blockCalled); EXPECT_FALSE(block_called);
} }
// Tests that the alert coordinator is dismissed if destroyed without being // Tests that the alert coordinator is dismissed if destroyed without being
// stopped. // stopped.
TEST_F(AlertCoordinatorTest, AlertDismissedOnDestroy) { TEST_F(AlertCoordinatorTest, AlertDismissedOnDestroy) {
// Setup. // Setup.
UIViewController* viewController = getViewController(); UIViewController* view_controller = GetViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController); AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
ASSERT_FALSE(alertCoordinator.isVisible); ASSERT_FALSE(alert_coordinator.visible);
ASSERT_EQ(nil, viewController.presentedViewController); ASSERT_EQ(nil, view_controller.presentedViewController);
__block BOOL blockCalled = NO; __block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{ alert_coordinator.noInteractionAction = ^{
blockCalled = YES; block_called = YES;
}; };
startAlertCoordinator(); StartAlertCoordinator();
alertCoordinator = nil; alert_coordinator = nil;
EXPECT_FALSE(blockCalled); EXPECT_FALSE(block_called);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment