Index: ios/chrome/browser/ui/alert_coordinator/alert_coordinator_egtest.mm |
diff --git a/ios/chrome/browser/ui/alert_coordinator/alert_coordinator_egtest.mm b/ios/chrome/browser/ui/alert_coordinator/alert_coordinator_egtest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6ed6955b1669a0d06c52b7faecb92788e4851cbf |
--- /dev/null |
+++ b/ios/chrome/browser/ui/alert_coordinator/alert_coordinator_egtest.mm |
@@ -0,0 +1,101 @@ |
+// 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 <EarlGrey/EarlGrey.h> |
+#import <UIKit/UIKit.h> |
+#import <XCTest/XCTest.h> |
+ |
+#import "base/mac/scoped_nsobject.h" |
+#include "components/strings/grit/components_strings.h" |
+#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" |
+#import "ios/chrome/test/earl_grey/chrome_matchers.h" |
+#import "ios/chrome/test/earl_grey/chrome_test_case.h" |
+#import "ios/testing/earl_grey/disabled_test_macros.h" |
+ |
+namespace { |
+NSString* kTitle = @"Foo Title"; |
+} // namespace |
+ |
+// Integration test for the alert coordinator using Earl Grey. |
+@interface AlertCoordinatorTestCase : ChromeTestCase |
+ |
+// Whether an alert is presented. |
+- (BOOL)isPresentingAlert; |
+ |
+@end |
+ |
+@implementation AlertCoordinatorTestCase |
+ |
+// Tests that if the alert coordinator is destroyed, the alert is dismissed. |
+- (void)testDismissOnDestroy { |
+// TODO(crbug.com/663026): Reenable the test for devices. |
+#if !TARGET_IPHONE_SIMULATOR |
+ EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |
+ @"alerts would prevent app alerts to present " |
+ @"correctly."); |
+#endif |
+ |
+ UIViewController* topViewController = |
+ [[[UIApplication sharedApplication] keyWindow] rootViewController]; |
+ |
+ base::scoped_nsobject<AlertCoordinator> alertCoordinator( |
+ [[AlertCoordinator alloc] initWithBaseViewController:topViewController |
+ title:kTitle |
+ message:nil]); |
+ |
+ [alertCoordinator start]; |
+ |
+ GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); |
+ |
+ alertCoordinator.reset(); |
+ |
+ GREYAssertFalse([self isPresentingAlert], @"The alert should be removed"); |
+} |
+ |
+- (void)testNoInteractionActionAfterTap { |
+// TODO(crbug.com/663026): Reenable the test for devices. |
+#if !TARGET_IPHONE_SIMULATOR |
+ EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |
+ @"alerts would prevent app alerts to present " |
+ @"correctly."); |
+#endif |
+ |
+ UIViewController* topViewController = |
+ [[[UIApplication sharedApplication] keyWindow] rootViewController]; |
+ |
+ base::scoped_nsobject<AlertCoordinator> alertCoordinator( |
+ [[AlertCoordinator alloc] initWithBaseViewController:topViewController |
+ title:kTitle |
+ message:nil]); |
+ |
+ __block BOOL blockCalled = NO; |
+ |
+ [alertCoordinator setNoInteractionAction:^{ |
+ blockCalled = YES; |
+ }]; |
+ |
+ [alertCoordinator start]; |
+ |
+ GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); |
+ |
+ [[EarlGrey |
+ selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( |
+ IDS_OK)] performAction:grey_tap()]; |
+ |
+ GREYAssertFalse([self isPresentingAlert], @"The alert should be removed"); |
+ |
+ GREYAssertFalse(blockCalled, |
+ @"The noInteractionBlock should not have been called."); |
+} |
+ |
+- (BOOL)isPresentingAlert { |
+ NSError* error = nil; |
+ [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kTitle)] |
+ assertWithMatcher:grey_sufficientlyVisible() |
+ error:&error]; |
+ |
+ return (error == nil); |
+} |
+ |
+@end |