Index: ios/web/public/test/earl_grey/web_view_actions.mm |
diff --git a/ios/web/public/test/earl_grey/web_view_actions.mm b/ios/web/public/test/earl_grey/web_view_actions.mm |
index ec9df6b30ff32ac3003c42d15c22de15b048cd71..11c7031f94e19107bb477e255b97452ef8f4f7ed 100644 |
--- a/ios/web/public/test/earl_grey/web_view_actions.mm |
+++ b/ios/web/public/test/earl_grey/web_view_actions.mm |
@@ -105,6 +105,38 @@ void RemoveVerifierForElementWithId(web::WebState* web_state, |
CallbackPrefixForElementId(element_id)); |
} |
+// Finds the location of the element |element_id| in the webview of |state|. |
+// If the element is found, returns the action created by |action_factory| with |
+// the location of the element. Otherwise returns a failing action. |
+id<GREYAction> webviewRunActionOnElement( |
Eugene But (OOO till 7-30)
2016/09/07 16:44:43
This method does not run an action, but constructs
jif
2016/09/08 13:41:01
Sounds better, thanks.
|
+ WebState* state, |
+ const std::string& element_id, |
+ id<GREYAction> (^action_factory)(CGPoint)) { |
+ CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); |
+ // Check if |rect| is empty; if it is, return an action that just throws an |
+ // error. |
+ if (CGRectIsEmpty(rect)) { |
+ NSString* description = [NSString |
+ stringWithFormat:@"Couldn't locate a bounding rect for element_id %s; " |
+ @"either it isn't there or it has no area.", |
+ element_id.c_str()]; |
+ GREYPerformBlock throw_error = ^BOOL(id /* element */, |
+ __strong NSError** error) { |
+ NSDictionary* user_info = @{NSLocalizedDescriptionKey : description}; |
+ *error = [NSError errorWithDomain:kGREYInteractionErrorDomain |
+ code:kGREYInteractionActionFailedErrorCode |
+ userInfo:user_info]; |
+ return NO; |
+ }; |
+ return [GREYActionBlock actionWithName:@"Locate element bounds" |
+ performBlock:throw_error]; |
+ } |
+ |
+ // If there's a usable rect, long-press in the center. |
+ CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); |
+ return action_factory(point); |
+} |
+ |
} // namespace |
namespace web { |
@@ -178,38 +210,29 @@ id<GREYAction> webViewLongPressElementForContextMenu( |
WebState* state, |
const std::string& element_id, |
bool triggers_context_menu) { |
- CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); |
- // Check if |rect| is empty; if it is, return an action that just throws an |
- // error. |
- if (CGRectIsEmpty(rect)) { |
- NSString* description = [NSString |
- stringWithFormat:@"Couldn't locate a bounding rect for element_id %s; " |
- @"either it isn't there or it has no area.", |
- element_id.c_str()]; |
- GREYPerformBlock throw_error = ^BOOL(id /* element */, |
- __strong NSError** error) { |
- NSDictionary* user_info = @{NSLocalizedDescriptionKey : description}; |
- *error = [NSError errorWithDomain:kGREYInteractionErrorDomain |
- code:kGREYInteractionActionFailedErrorCode |
- userInfo:user_info]; |
- return NO; |
- }; |
- return [GREYActionBlock actionWithName:@"Locate element bounds" |
- performBlock:throw_error]; |
- } |
- |
- // If there's a usable rect, long-press in the center. |
- CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); |
- |
- id<GREYAction> longpress = |
- grey_longPressAtPointWithDuration(point, kContextMenuLongPressDuration); |
- id<GREYAction> action = longpress; |
+ std::string element_id_copy = element_id; |
+ id<GREYAction> (^action_factory)(CGPoint) = ^id<GREYAction>(CGPoint point) { |
+ id<GREYAction> longpress = |
+ grey_longPressAtPointWithDuration(point, kContextMenuLongPressDuration); |
+ id<GREYAction> action = nil; |
+ if (triggers_context_menu) { |
+ action = longpress; |
+ } else { |
+ action = |
+ webViewVerifiedActionOnElement(state, longpress, element_id_copy); |
+ } |
+ return action; |
+ }; |
- if (!triggers_context_menu) { |
- action = webViewVerifiedActionOnElement(state, longpress, element_id); |
- } |
+ return webviewRunActionOnElement(state, element_id, action_factory); |
+} |
- return action; |
+id<GREYAction> webViewPressElement(WebState* state, |
+ const std::string& element_id) { |
+ id<GREYAction> (^action_factory)(CGPoint) = ^id<GREYAction>(CGPoint point) { |
+ return grey_tapAtPoint(point); |
Eugene But (OOO till 7-30)
2016/09/07 16:56:38
Oh and this should be webViewVerifiedActionOnEleme
jif
2016/09/08 13:41:01
Done.
|
+ }; |
+ return webviewRunActionOnElement(state, element_id, action_factory); |
} |
} // namespace web |