Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 | 8 |
| 9 #import "base/mac/scoped_nsobject.h" | |
| 10 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
| 11 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" | 10 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 13 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 14 #import "ios/testing/earl_grey/disabled_test_macros.h" | 13 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| 15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 16 namespace { | 19 namespace { |
| 17 NSString* kTitle = @"Foo Title"; | 20 NSString* kTitle = @"Foo Title"; |
| 18 } // namespace | 21 } // namespace |
| 19 | 22 |
| 20 // Integration test for the alert coordinator using Earl Grey. | 23 // Integration test for the alert coordinator using Earl Grey. |
| 21 @interface AlertCoordinatorTestCase : ChromeTestCase | 24 @interface AlertCoordinatorTestCase : ChromeTestCase |
| 22 | 25 |
| 23 // Whether an alert is presented. | 26 // Whether an alert is presented. |
| 24 - (BOOL)isPresentingAlert; | 27 - (BOOL)isPresentingAlert; |
| 25 | 28 |
| 26 @end | 29 @end |
| 27 | 30 |
| 28 @implementation AlertCoordinatorTestCase | 31 @implementation AlertCoordinatorTestCase |
| 29 | 32 |
| 30 // Tests that if the alert coordinator is destroyed, the alert is dismissed. | 33 // Tests that if the alert coordinator is destroyed, the alert is dismissed. |
| 31 - (void)testDismissOnDestroy { | 34 - (void)testDismissOnDestroy { |
| 32 // TODO(crbug.com/663026): Reenable the test for devices. | 35 // TODO(crbug.com/663026): Reenable the test for devices. |
| 33 #if !TARGET_IPHONE_SIMULATOR | 36 #if !TARGET_IPHONE_SIMULATOR |
| 34 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 37 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |
| 35 @"alerts would prevent app alerts to present " | 38 @"alerts would prevent app alerts to present " |
| 36 @"correctly."); | 39 @"correctly."); |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 39 UIViewController* topViewController = | 42 UIViewController* topViewController = |
| 40 [[[UIApplication sharedApplication] keyWindow] rootViewController]; | 43 [[[UIApplication sharedApplication] keyWindow] rootViewController]; |
| 41 | 44 |
| 42 base::scoped_nsobject<AlertCoordinator> alertCoordinator( | 45 AlertCoordinator* alertCoordinator = |
| 43 [[AlertCoordinator alloc] initWithBaseViewController:topViewController | 46 [[AlertCoordinator alloc] initWithBaseViewController:topViewController |
| 44 title:kTitle | 47 title:kTitle |
| 45 message:nil]); | 48 message:nil]; |
| 46 | 49 |
| 47 [alertCoordinator start]; | 50 [alertCoordinator start]; |
| 48 | 51 |
| 49 GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); | 52 GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); |
| 50 | 53 |
| 51 alertCoordinator.reset(); | 54 alertCoordinator = nil; |
|
gambard
2017/02/08 16:08:29
The alert coordinator needs to be dealloc here, be
stkhapugin
2017/02/08 17:39:29
Generally, it is incorrect to assume exact object
gambard
2017/02/09 09:06:45
Acknowledged.
| |
| 52 | 55 |
| 53 GREYAssertFalse([self isPresentingAlert], @"The alert should be removed"); | 56 GREYAssertFalse([self isPresentingAlert], @"The alert should be removed"); |
| 54 } | 57 } |
| 55 | 58 |
| 56 - (void)testNoInteractionActionAfterTap { | 59 - (void)testNoInteractionActionAfterTap { |
| 57 // TODO(crbug.com/663026): Reenable the test for devices. | 60 // TODO(crbug.com/663026): Reenable the test for devices. |
| 58 #if !TARGET_IPHONE_SIMULATOR | 61 #if !TARGET_IPHONE_SIMULATOR |
| 59 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " | 62 EARL_GREY_TEST_DISABLED(@"Disabled for devices because existing system " |
| 60 @"alerts would prevent app alerts to present " | 63 @"alerts would prevent app alerts to present " |
| 61 @"correctly."); | 64 @"correctly."); |
| 62 #endif | 65 #endif |
| 63 | 66 |
| 64 UIViewController* topViewController = | 67 UIViewController* topViewController = |
| 65 [[[UIApplication sharedApplication] keyWindow] rootViewController]; | 68 [[[UIApplication sharedApplication] keyWindow] rootViewController]; |
| 66 | 69 |
| 67 base::scoped_nsobject<AlertCoordinator> alertCoordinator( | 70 AlertCoordinator* alertCoordinator = |
| 68 [[AlertCoordinator alloc] initWithBaseViewController:topViewController | 71 [[AlertCoordinator alloc] initWithBaseViewController:topViewController |
| 69 title:kTitle | 72 title:kTitle |
| 70 message:nil]); | 73 message:nil]; |
| 71 | 74 |
| 72 __block BOOL blockCalled = NO; | 75 __block BOOL blockCalled = NO; |
| 73 | 76 |
| 74 [alertCoordinator setNoInteractionAction:^{ | 77 [alertCoordinator setNoInteractionAction:^{ |
| 75 blockCalled = YES; | 78 blockCalled = YES; |
| 76 }]; | 79 }]; |
| 77 | 80 |
| 78 [alertCoordinator start]; | 81 [alertCoordinator start]; |
| 79 | 82 |
| 80 GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); | 83 GREYAssertTrue([self isPresentingAlert], @"An alert should be presented"); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 92 - (BOOL)isPresentingAlert { | 95 - (BOOL)isPresentingAlert { |
| 93 NSError* error = nil; | 96 NSError* error = nil; |
| 94 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kTitle)] | 97 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kTitle)] |
| 95 assertWithMatcher:grey_sufficientlyVisible() | 98 assertWithMatcher:grey_sufficientlyVisible() |
| 96 error:&error]; | 99 error:&error]; |
| 97 | 100 |
| 98 return (error == nil); | 101 return (error == nil); |
| 99 } | 102 } |
| 100 | 103 |
| 101 @end | 104 @end |
| OLD | NEW |