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 {
[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) {
return getAlertCoordinator(viewController, @"Test title", nil);
AlertCoordinator* GetAlertCoordinator(UIViewController* view_controller) {
return GetAlertCoordinator(view_controller, @"Test title", nil);
}
AlertCoordinator* getAlertCoordinator(UIViewController* viewController,
AlertCoordinator* GetAlertCoordinator(UIViewController* view_controller,
NSString* title,
NSString* message) {
alert_coordinator_ =
[[AlertCoordinator alloc] initWithBaseViewController:viewController
[[AlertCoordinator alloc] initWithBaseViewController:view_controller
title:title
message:message];
return alert_coordinator_;
......@@ -58,23 +58,23 @@ class AlertCoordinatorTest : public PlatformTest {
// on button is created.
TEST_F(AlertCoordinatorTest, ValidateIsVisible) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
ASSERT_FALSE(alertCoordinator.isVisible);
ASSERT_EQ(nil, viewController.presentedViewController);
ASSERT_FALSE(alert_coordinator.visible);
ASSERT_EQ(nil, view_controller.presentedViewController);
// Action.
startAlertCoordinator();
StartAlertCoordinator();
// Test.
EXPECT_TRUE(alertCoordinator.isVisible);
EXPECT_TRUE([viewController.presentedViewController
EXPECT_TRUE(alert_coordinator.visible);
EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController =
UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController);
EXPECT_EQ(1LU, alertController.actions.count);
view_controller.presentedViewController);
EXPECT_EQ(1LU, alert_controller.actions.count);
}
// Tests the alert coordinator reports as not visible after presenting on a non
......@@ -83,75 +83,75 @@ TEST_F(AlertCoordinatorTest, ValidateIsNotVisible) {
// Setup.
UIWindow* window =
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* viewController = [[UIViewController alloc] init];
[window setRootViewController:viewController];
UIViewController* view_controller = [[UIViewController alloc] init];
[window setRootViewController:view_controller];
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
// Action.
startAlertCoordinator();
StartAlertCoordinator();
// Test.
EXPECT_FALSE(alertCoordinator.isVisible);
EXPECT_EQ(nil, [viewController presentedViewController]);
EXPECT_FALSE(alert_coordinator.visible);
EXPECT_EQ(nil, [view_controller presentedViewController]);
}
// Tests the alert coordinator has a correct title and message.
TEST_F(AlertCoordinatorTest, TitleAndMessage) {
// Setup.
UIViewController* viewController = getViewController();
UIViewController* view_controller = GetViewController();
NSString* title = @"Foo test title!";
NSString* message = @"Foo bar message.";
getAlertCoordinator(viewController, title, message);
GetAlertCoordinator(view_controller, title, message);
// Action.
startAlertCoordinator();
StartAlertCoordinator();
// Test.
// Get the alert.
EXPECT_TRUE([viewController.presentedViewController
EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController =
UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController);
view_controller.presentedViewController);
// Test the results.
EXPECT_EQ(title, alertController.title);
EXPECT_EQ(message, alertController.message);
EXPECT_EQ(title, alert_controller.title);
EXPECT_EQ(message, alert_controller.message);
}
// Tests the alert coordinator dismissal.
TEST_F(AlertCoordinatorTest, ValidateDismissalOnStop) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
startAlertCoordinator();
StartAlertCoordinator();
ASSERT_TRUE(alertCoordinator.isVisible);
ASSERT_NE(nil, viewController.presentedViewController);
ASSERT_TRUE([viewController.presentedViewController
ASSERT_TRUE(alert_coordinator.visible);
ASSERT_NE(nil, view_controller.presentedViewController);
ASSERT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]);
id viewControllerMock = [OCMockObject partialMockForObject:viewController];
id viewControllerMock = [OCMockObject partialMockForObject:view_controller];
[[[viewControllerMock expect] andForwardToRealObject]
dismissViewControllerAnimated:NO
completion:nil];
// Action.
[alertCoordinator stop];
[alert_coordinator stop];
// Test.
EXPECT_FALSE(alertCoordinator.isVisible);
EXPECT_FALSE(alert_coordinator.visible);
EXPECT_OCMOCK_VERIFY(viewControllerMock);
}
// Tests that only the expected actions are present on the alert.
TEST_F(AlertCoordinatorTest, ValidateActions) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
NSDictionary* actions = @{
@"foo" : @(UIAlertActionStyleDestructive),
......@@ -167,22 +167,22 @@ TEST_F(AlertCoordinatorTest, ValidateActions) {
for (id key in actions) {
UIAlertActionStyle style =
static_cast<UIAlertActionStyle>([actions[key] integerValue]);
[alertCoordinator addItemWithTitle:key action:nil style:style];
[alert_coordinator addItemWithTitle:key action:nil style:style];
}
// Test.
// Present the alert.
startAlertCoordinator();
StartAlertCoordinator();
// Get the alert.
EXPECT_TRUE([viewController.presentedViewController
EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController =
UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController);
view_controller.presentedViewController);
// Test the results.
for (UIAlertAction* action in alertController.actions) {
for (UIAlertAction* action in alert_controller.actions) {
EXPECT_TRUE([remainingActions objectForKey:action.title]);
UIAlertActionStyle style =
static_cast<UIAlertActionStyle>([actions[action.title] integerValue]);
......@@ -196,34 +196,34 @@ TEST_F(AlertCoordinatorTest, ValidateActions) {
// Tests that only the first cancel action is added.
TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
NSString* firstButtonTitle = @"Cancel1";
// Action.
[alertCoordinator addItemWithTitle:firstButtonTitle
action:nil
style:UIAlertActionStyleCancel];
[alertCoordinator addItemWithTitle:@"Cancel2"
action:nil
style:UIAlertActionStyleCancel];
[alert_coordinator addItemWithTitle:firstButtonTitle
action:nil
style:UIAlertActionStyleCancel];
[alert_coordinator addItemWithTitle:@"Cancel2"
action:nil
style:UIAlertActionStyleCancel];
// Test.
// Present the alert.
startAlertCoordinator();
StartAlertCoordinator();
// Get the alert.
EXPECT_TRUE([viewController.presentedViewController
EXPECT_TRUE([view_controller.presentedViewController
isKindOfClass:[UIAlertController class]]);
UIAlertController* alertController =
UIAlertController* alert_controller =
base::mac::ObjCCastStrict<UIAlertController>(
viewController.presentedViewController);
view_controller.presentedViewController);
// 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(UIAlertActionStyleCancel, action.style);
}
......@@ -232,66 +232,66 @@ TEST_F(AlertCoordinatorTest, OnlyOneCancelAction) {
// which is stopped before the user has interacted with it.
TEST_F(AlertCoordinatorTest, NoInteractionActionTest) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
__block BOOL blockCalled = NO;
__block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{
blockCalled = YES;
alert_coordinator.noInteractionAction = ^{
block_called = YES;
};
startAlertCoordinator();
StartAlertCoordinator();
// Action.
[alertCoordinator stop];
[alert_coordinator stop];
// Test.
EXPECT_TRUE(blockCalled);
EXPECT_TRUE(block_called);
}
// Tests that the |noInteractionAction| block is not called for an alert
// coordinator which is dismissed with the cancel button.
TEST_F(AlertCoordinatorTest, NoInteractionActionWithCancelTest) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
__block BOOL blockCalled = NO;
__block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{
blockCalled = YES;
alert_coordinator.noInteractionAction = ^{
block_called = YES;
};
startAlertCoordinator();
StartAlertCoordinator();
// Action.
[alertCoordinator executeCancelHandler];
[alertCoordinator stop];
[alert_coordinator executeCancelHandler];
[alert_coordinator stop];
// Test.
EXPECT_FALSE(blockCalled);
EXPECT_FALSE(block_called);
}
// Tests that the alert coordinator is dismissed if destroyed without being
// stopped.
TEST_F(AlertCoordinatorTest, AlertDismissedOnDestroy) {
// Setup.
UIViewController* viewController = getViewController();
AlertCoordinator* alertCoordinator = getAlertCoordinator(viewController);
UIViewController* view_controller = GetViewController();
AlertCoordinator* alert_coordinator = GetAlertCoordinator(view_controller);
ASSERT_FALSE(alertCoordinator.isVisible);
ASSERT_EQ(nil, viewController.presentedViewController);
ASSERT_FALSE(alert_coordinator.visible);
ASSERT_EQ(nil, view_controller.presentedViewController);
__block BOOL blockCalled = NO;
__block BOOL block_called = NO;
alertCoordinator.noInteractionAction = ^{
blockCalled = YES;
alert_coordinator.noInteractionAction = ^{
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