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

Unified Diff: ios/chrome/browser/ui/alert_coordinator/action_sheet_unittest.mm

Issue 2156913002: Creates alertCoordinatorDelegate for alerts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@alertCoordinator
Patch Set: Created 4 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/alert_coordinator/action_sheet_unittest.mm
diff --git a/ios/chrome/browser/ui/alert_coordinator/action_sheet_unittest.mm b/ios/chrome/browser/ui/alert_coordinator/action_sheet_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..2cbb15018af3c92f05dce892e354108391f3da9b
--- /dev/null
+++ b/ios/chrome/browser/ui/alert_coordinator/action_sheet_unittest.mm
@@ -0,0 +1,108 @@
+// 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.h"
+
+#import <UIKit/UIKit.h>
+
+#import "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
+#import "ios/web/public/web_state/context_menu_params.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+#include "third_party/ocmock/gtest_support.h"
+
+// Tests that ActionSheet ask for a default cancel button.
+TEST(ActionSheetTest, ShouldAddCancelButton) {
+ // Setup.
+ base::scoped_nsobject<ActionSheet> actionSheet([[ActionSheet alloc] init]);
+
+ // Test.
+ EXPECT_TRUE([actionSheet alertCoordinatorShouldAddCancelButton:nil]);
+}
+
+// Tests that the ActionSheet let the Alert start.
+TEST(ActionSheetTest, AlertCoordinatorShouldStart) {
+ // Setup.
+ base::scoped_nsobject<UIWindow> window(
+ [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
+ [window makeKeyAndVisible];
+ base::scoped_nsobject<UIViewController> viewController(
+ [[UIViewController alloc] init]);
+ [window setRootViewController:viewController];
+
+ web::ContextMenuParams params;
+ params.location = CGPointMake(0, 0);
+ ;
lpromero 2016/07/18 12:11:36 Remove.
+ params.view.reset([[viewController view] retain]);
+ base::scoped_nsobject<ActionSheet> actionSheet(
+ [[ActionSheet alloc] initWithParams:params]);
+
+ // Test.
+ ASSERT_TRUE([actionSheet alertCoordinatorShouldStart:nil]);
lpromero 2016/07/18 12:11:35 s/ASSERT/EXPECT ASSERT stops the test execution,
marq (ping after 24h) 2016/07/18 13:02:41 ASSERT should generally only be used in cases wher
+}
+
+// Tests that the ActionSheet do not let the Alert start if the window is not
+// visible.
+TEST(ActionSheetTest, AlertCoordinatorShouldNotStart) {
+ // Setup.
+ base::scoped_nsobject<UIWindow> window(
+ [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
+ base::scoped_nsobject<UIViewController> viewController(
+ [[UIViewController alloc] init]);
+ [window setRootViewController:viewController];
+
+ web::ContextMenuParams params;
+ params.location = CGPointMake(0, 0);
+ ;
lpromero 2016/07/18 12:11:35 Remove.
+ params.view.reset([[viewController view] retain]);
+ base::scoped_nsobject<ActionSheet> actionSheet(
+ [[ActionSheet alloc] initWithParams:params]);
+
+ // Test.
+ ASSERT_FALSE([actionSheet alertCoordinatorShouldStart:nil]);
lpromero 2016/07/18 12:11:36 s/ASSERT/EXPECT
+}
+
+// Tests that the ActionController created by ActionSheet is used to display
+// context menu.
+TEST(ActionSheetTest, ValidateContextMenuParams) {
+ // Setup.
+ base::scoped_nsobject<UIWindow> window(
+ [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
+ base::scoped_nsobject<UIViewController> viewController(
+ [[UIViewController alloc] init]);
+ [window setRootViewController:viewController];
+
+ CGPoint location = CGPointMake(100.0, 125.0);
+ NSString* title = @"Context Menu Title";
+
+ web::ContextMenuParams params;
+ params.location = location;
+ params.menu_title.reset(title);
+ params.view.reset([[viewController view] retain]);
+ base::scoped_nsobject<ActionSheet> actionSheet(
+ [[ActionSheet alloc] initWithParams:params]);
+
+ NSString* message = @"Test message";
+
+ id alertCoordinator = [OCMockObject mockForClass:[AlertCoordinator class]];
+ [[[alertCoordinator stub] andReturn:message] message];
+ [[[alertCoordinator stub] andReturn:viewController] baseViewController];
+
+ // Action.
+ UIAlertController* alertController =
+ [actionSheet alertCoordinatorUIAlertController:alertCoordinator];
+
+ // Test.
+ EXPECT_EQ(title, alertController.title);
+
+ // Only validate the popover location if it is displayed in a popover.
+ if (alertController.popoverPresentationController) {
+ CGPoint presentedLocation =
+ alertController.popoverPresentationController.sourceRect.origin;
+ EXPECT_EQ(location.x, presentedLocation.x);
+ EXPECT_EQ(location.y, presentedLocation.y);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698