Index: ios/testing/earl_grey/matchers.mm |
diff --git a/ios/testing/earl_grey/matchers.mm b/ios/testing/earl_grey/matchers.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2d0acd07bf64d20312ce5f323f91c16778ae19f4 |
--- /dev/null |
+++ b/ios/testing/earl_grey/matchers.mm |
@@ -0,0 +1,40 @@ |
+// 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/testing/earl_grey/matchers.h" |
+ |
+namespace testing { |
+ |
+id<GREYMatcher> contextMenuItemContainingText(NSString* text) { |
+ // Both tablet and phone house context menu views inside an alert controller |
+ // view (on tablet that view is itself inside a popover view). |
+ id<GREYMatcher> context_menu_container = |
+ grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView")); |
+ |
+ return grey_allOf(grey_ancestor(context_menu_container), |
+ grey_interactable(), |
+ grey_text(text), |
+ nil); |
+} |
+ |
+id<GREYMatcher> elementToDismissContextMenu() { |
+ UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom]; |
+ if (idiom == UIUserInterfaceIdiomPad) { |
+ // On iPad the context menu is dismissed by tapping on something |
+ // that isn't the popover. The web controller container view is an easy |
+ // choice, although it needs to be not-underneath the popover. |
+ id<GREYMatcher> popover = |
+ grey_kindOfClass(NSClassFromString(@"_UIPopoverView")); |
+ return grey_allOf(grey_not(grey_ancestor(popover)), |
+ grey_kindOfClass( |
+ NSClassFromString(@"CRWWebControllerContainerView")), |
Eugene But (OOO till 7-30)
2016/08/30 18:11:04
CRWWebControllerContainerView is a private web cla
baxley
2016/08/31 04:25:43
nit: grey_allOf is more efficient if the matchers
marq (ping after 24h)
2016/08/31 13:07:57
Done.
marq (ping after 24h)
2016/08/31 13:07:57
Yep, turns out UIKit makes this very easy by label
|
+ nil); |
+ } else { |
+ // On iPhone the context menu is dismissed by tapping on the "Cancel" item. |
+ return contextMenuItemContainingText(@"Cancel"); |
Eugene But (OOO till 7-30)
2016/08/30 18:11:04
Can this string be localized somehow?
marq (ping after 24h)
2016/08/31 13:07:57
Yes, now callers pass in a string; if they use loc
|
+ } |
+} |
+ |
+} // namespace testing |
+ |