Index: ios/chrome/test/earl_grey/chrome_actions.mm |
diff --git a/ios/chrome/test/earl_grey/chrome_actions.mm b/ios/chrome/test/earl_grey/chrome_actions.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d893a86555c794cddc40011f54ada84e8a33e904 |
--- /dev/null |
+++ b/ios/chrome/test/earl_grey/chrome_actions.mm |
@@ -0,0 +1,44 @@ |
+// 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/test/earl_grey/chrome_actions.h" |
+ |
+#import "base/mac/foundation_util.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.h" |
+#import "ios/chrome/test/app/chrome_test_util.h" |
+#import "ios/web/public/test/earl_grey/web_view_actions.h" |
+ |
+namespace chrome_test_util { |
+ |
+id<GREYAction> longPressElementForContextMenu(const std::string& element_id, |
+ bool triggers_context_menu) { |
+ return webViewLongPressElementForContextMenu( |
+ chrome_test_util::GetCurrentWebState(), element_id, |
+ triggers_context_menu); |
+} |
+ |
+id<GREYAction> turnCollectionViewSwitchOn(BOOL on) { |
+ id<GREYMatcher> constraints = grey_not(grey_systemAlertViewShown()); |
+ NSString* actionName = |
+ [NSString stringWithFormat:@"Turn collection view switch to %@ state", |
+ on ? @"ON" : @"OFF"]; |
+ return [GREYActionBlock |
+ actionWithName:actionName |
+ constraints:constraints |
+ performBlock:^BOOL(id collectionViewCell, |
+ __strong NSError** errorOrNil) { |
+ CollectionViewSwitchCell* switchCell = |
+ base::mac::ObjCCastStrict<CollectionViewSwitchCell>( |
+ collectionViewCell); |
+ UISwitch* switchView = switchCell.switchView; |
+ if (switchView.on ^ on) { |
+ id<GREYAction> longPressAction = [GREYActions |
+ actionForLongPressWithDuration:kGREYLongPressDefaultDuration]; |
+ return [longPressAction perform:switchView error:errorOrNil]; |
+ } |
+ return YES; |
+ }]; |
+} |
+ |
+} // namespace chrome_test_util |