Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: ios/web/public/test/earl_grey/web_view_actions.mm

Issue 2777463002: Make custom GREYAction methods Chromium C-Style. (Closed)
Patch Set: cleanup Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/web/public/test/earl_grey/web_view_actions.h" 5 #import "ios/web/public/test/earl_grey/web_view_actions.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #import "base/mac/bind_objc_block.h" 9 #import "base/mac/bind_objc_block.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 // Removes the injected callback. 105 // Removes the injected callback.
106 void RemoveVerifierForElementWithId(web::WebState* web_state, 106 void RemoveVerifierForElementWithId(web::WebState* web_state,
107 const std::string& element_id) { 107 const std::string& element_id) {
108 static_cast<web::WebStateImpl*>(web_state)->RemoveScriptCommandCallback( 108 static_cast<web::WebStateImpl*>(web_state)->RemoveScriptCommandCallback(
109 CallbackPrefixForElementId(element_id)); 109 CallbackPrefixForElementId(element_id));
110 } 110 }
111 111
112 // Returns a no element found error. 112 // Returns a no element found error.
113 id<GREYAction> webViewElementNotFound(const std::string& element_id) { 113 id<GREYAction> WebViewElementNotFound(const std::string& element_id) {
114 NSString* description = [NSString 114 NSString* description = [NSString
115 stringWithFormat:@"Couldn't locate a bounding rect for element_id %s; " 115 stringWithFormat:@"Couldn't locate a bounding rect for element_id %s; "
116 @"either it isn't there or it has no area.", 116 @"either it isn't there or it has no area.",
117 element_id.c_str()]; 117 element_id.c_str()];
118 GREYPerformBlock throw_error = 118 GREYPerformBlock throw_error =
119 ^BOOL(id /* element */, __strong NSError** error) { 119 ^BOOL(id /* element */, __strong NSError** error) {
120 NSDictionary* user_info = @{NSLocalizedDescriptionKey : description}; 120 NSDictionary* user_info = @{NSLocalizedDescriptionKey : description};
121 *error = [NSError errorWithDomain:kGREYInteractionErrorDomain 121 *error = [NSError errorWithDomain:kGREYInteractionErrorDomain
122 code:kGREYInteractionActionFailedErrorCode 122 code:kGREYInteractionActionFailedErrorCode
123 userInfo:user_info]; 123 userInfo:user_info];
124 return NO; 124 return NO;
125 }; 125 };
126 return [GREYActionBlock actionWithName:@"Locate element bounds" 126 return [GREYActionBlock actionWithName:@"Locate element bounds"
127 performBlock:throw_error]; 127 performBlock:throw_error];
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 namespace web { 132 namespace web {
133 133
134 id<GREYAction> webViewVerifiedActionOnElement(WebState* state, 134 id<GREYAction> WebViewVerifiedActionOnElement(WebState* state,
135 id<GREYAction> action, 135 id<GREYAction> action,
136 const std::string& element_id) { 136 const std::string& element_id) {
137 NSString* action_name = 137 NSString* action_name =
138 [NSString stringWithFormat:@"Verified action (%@) on webview element %s.", 138 [NSString stringWithFormat:@"Verified action (%@) on webview element %s.",
139 action.name, element_id.c_str()]; 139 action.name, element_id.c_str()];
140 140
141 GREYPerformBlock verified_tap = ^BOOL(id element, __strong NSError** error) { 141 GREYPerformBlock verified_tap = ^BOOL(id element, __strong NSError** error) {
142 // A pointer to |verified| is passed into AddVerifierToElementWithId() so 142 // A pointer to |verified| is passed into AddVerifierToElementWithId() so
143 // the verifier can update its value, but |verified| also needs to be marked 143 // the verifier can update its value, but |verified| also needs to be marked
144 // as __block so that waitUntilCondition(), below, can access it by 144 // as __block so that waitUntilCondition(), below, can access it by
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // true by this point. 191 // true by this point.
192 DCHECK(verified); 192 DCHECK(verified);
193 return YES; 193 return YES;
194 }; 194 };
195 195
196 return [GREYActionBlock actionWithName:action_name 196 return [GREYActionBlock actionWithName:action_name
197 constraints:WebViewInWebState(state) 197 constraints:WebViewInWebState(state)
198 performBlock:verified_tap]; 198 performBlock:verified_tap];
199 } 199 }
200 200
201 id<GREYAction> webViewLongPressElementForContextMenu( 201 id<GREYAction> WebViewLongPressElementForContextMenu(
202 WebState* state, 202 WebState* state,
203 const std::string& element_id, 203 const std::string& element_id,
204 bool triggers_context_menu) { 204 bool triggers_context_menu) {
205 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); 205 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id);
206 if (CGRectIsEmpty(rect)) { 206 if (CGRectIsEmpty(rect)) {
207 return webViewElementNotFound(element_id); 207 return WebViewElementNotFound(element_id);
208 } 208 }
209 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); 209 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
210 id<GREYAction> longpress = 210 id<GREYAction> longpress =
211 grey_longPressAtPointWithDuration(point, kContextMenuLongPressDuration); 211 grey_longPressAtPointWithDuration(point, kContextMenuLongPressDuration);
212 if (triggers_context_menu) { 212 if (triggers_context_menu) {
213 return longpress; 213 return longpress;
214 } 214 }
215 return webViewVerifiedActionOnElement(state, longpress, element_id); 215 return WebViewVerifiedActionOnElement(state, longpress, element_id);
216 } 216 }
217 217
218 id<GREYAction> webViewTapElement(WebState* state, 218 id<GREYAction> WebViewTapElement(WebState* state,
219 const std::string& element_id) { 219 const std::string& element_id) {
220 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); 220 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id);
221 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); 221 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
222 return CGRectIsEmpty(rect) ? webViewElementNotFound(element_id) 222 return CGRectIsEmpty(rect) ? WebViewElementNotFound(element_id)
223 : webViewVerifiedActionOnElement( 223 : WebViewVerifiedActionOnElement(
224 state, grey_tapAtPoint(point), element_id); 224 state, grey_tapAtPoint(point), element_id);
225 } 225 }
226 226
227 } // namespace web 227 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698