| 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 "ios/chrome/test/earl_grey/chrome_actions.h" | 5 #import "ios/chrome/test/earl_grey/chrome_actions.h" |
| 6 | 6 |
| 7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
| 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
| 9 #import "ios/chrome/test/app/chrome_test_util.h" | 9 #import "ios/chrome/test/app/chrome_test_util.h" |
| 10 #import "ios/web/public/test/earl_grey/web_view_actions.h" | 10 #import "ios/web/public/test/earl_grey/web_view_actions.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace chrome_test_util { | 16 namespace chrome_test_util { |
| 17 | 17 |
| 18 id<GREYAction> LongPressElementForContextMenu(const std::string& element_id, | 18 id<GREYAction> LongPressElementForContextMenu(const std::string& element_id, |
| 19 bool triggers_context_menu) { | 19 bool triggers_context_menu) { |
| 20 return WebViewLongPressElementForContextMenu( | 20 return WebViewLongPressElementForContextMenu( |
| 21 chrome_test_util::GetCurrentWebState(), element_id, | 21 chrome_test_util::GetCurrentWebState(), element_id, |
| 22 triggers_context_menu); | 22 triggers_context_menu); |
| 23 } | 23 } |
| 24 | 24 |
| 25 id<GREYAction> longPressElementForContextMenu(const std::string& element_id, | |
| 26 bool triggers_context_menu) { | |
| 27 return LongPressElementForContextMenu(element_id, triggers_context_menu); | |
| 28 } | |
| 29 | |
| 30 id<GREYAction> TurnCollectionViewSwitchOn(BOOL on) { | 25 id<GREYAction> TurnCollectionViewSwitchOn(BOOL on) { |
| 31 id<GREYMatcher> constraints = grey_not(grey_systemAlertViewShown()); | 26 id<GREYMatcher> constraints = grey_not(grey_systemAlertViewShown()); |
| 32 NSString* actionName = | 27 NSString* actionName = |
| 33 [NSString stringWithFormat:@"Turn collection view switch to %@ state", | 28 [NSString stringWithFormat:@"Turn collection view switch to %@ state", |
| 34 on ? @"ON" : @"OFF"]; | 29 on ? @"ON" : @"OFF"]; |
| 35 return [GREYActionBlock | 30 return [GREYActionBlock |
| 36 actionWithName:actionName | 31 actionWithName:actionName |
| 37 constraints:constraints | 32 constraints:constraints |
| 38 performBlock:^BOOL(id collectionViewCell, | 33 performBlock:^BOOL(id collectionViewCell, |
| 39 __strong NSError** errorOrNil) { | 34 __strong NSError** errorOrNil) { |
| 40 CollectionViewSwitchCell* switchCell = | 35 CollectionViewSwitchCell* switchCell = |
| 41 base::mac::ObjCCastStrict<CollectionViewSwitchCell>( | 36 base::mac::ObjCCastStrict<CollectionViewSwitchCell>( |
| 42 collectionViewCell); | 37 collectionViewCell); |
| 43 UISwitch* switchView = switchCell.switchView; | 38 UISwitch* switchView = switchCell.switchView; |
| 44 if (switchView.on ^ on) { | 39 if (switchView.on ^ on) { |
| 45 id<GREYAction> longPressAction = [GREYActions | 40 id<GREYAction> longPressAction = [GREYActions |
| 46 actionForLongPressWithDuration:kGREYLongPressDefaultDuration]; | 41 actionForLongPressWithDuration:kGREYLongPressDefaultDuration]; |
| 47 return [longPressAction perform:switchView error:errorOrNil]; | 42 return [longPressAction perform:switchView error:errorOrNil]; |
| 48 } | 43 } |
| 49 return YES; | 44 return YES; |
| 50 }]; | 45 }]; |
| 51 } | 46 } |
| 52 | 47 |
| 53 } // namespace chrome_test_util | 48 } // namespace chrome_test_util |
| OLD | NEW |