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/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" |
11 #import "base/test/ios/wait_util.h" | 11 #import "base/test/ios/wait_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #import "ios/testing/wait_util.h" | 13 #import "ios/testing/wait_util.h" |
14 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 14 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
15 #import "ios/web/public/test/web_view_interaction_test_util.h" | 15 #import "ios/web/public/test/web_view_interaction_test_util.h" |
16 #import "ios/web/web_state/web_state_impl.h" | 16 #import "ios/web/web_state/web_state_impl.h" |
17 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
18 using web::test::ExecuteJavaScript; | 22 using web::test::ExecuteJavaScript; |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // Long press duration to trigger context menu. | 26 // Long press duration to trigger context menu. |
23 const NSTimeInterval kContextMenuLongPressDuration = 0.3; | 27 const NSTimeInterval kContextMenuLongPressDuration = 0.3; |
24 | 28 |
25 // Duration to wait for verification of JavaScript action. | 29 // Duration to wait for verification of JavaScript action. |
26 // TODO(crbug.com/670910): Reduce duration if the time required for verification | 30 // TODO(crbug.com/670910): Reduce duration if the time required for verification |
27 // is reduced on devices. | 31 // is reduced on devices. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 87 } |
84 } | 88 } |
85 return false; | 89 return false; |
86 }); | 90 }); |
87 | 91 |
88 if (!success) | 92 if (!success) |
89 return false; | 93 return false; |
90 | 94 |
91 // The callback doesn't care about any of the parameters, just whether it is | 95 // The callback doesn't care about any of the parameters, just whether it is |
92 // called or not. | 96 // called or not. |
93 auto callback = base::BindBlock(^bool(const base::DictionaryValue& /* json */, | 97 auto callback = base::BindBlockArc( |
94 const GURL& /* origin_url */, | 98 ^bool(const base::DictionaryValue& /* json */, |
95 bool /* user_is_interacting */) { | 99 const GURL& /* origin_url */, bool /* user_is_interacting */) { |
96 *verified = true; | 100 *verified = true; |
97 return true; | 101 return true; |
98 }); | 102 }); |
99 | 103 |
100 static_cast<web::WebStateImpl*>(web_state)->AddScriptCommandCallback( | 104 static_cast<web::WebStateImpl*>(web_state)->AddScriptCommandCallback( |
101 callback, kCallbackPrefix); | 105 callback, kCallbackPrefix); |
102 return true; | 106 return true; |
103 } | 107 } |
104 | 108 |
105 // Removes the injected callback. | 109 // Removes the injected callback. |
106 void RemoveVerifierForElementWithId(web::WebState* web_state, | 110 void RemoveVerifierForElementWithId(web::WebState* web_state, |
107 const std::string& element_id) { | 111 const std::string& element_id) { |
108 static_cast<web::WebStateImpl*>(web_state)->RemoveScriptCommandCallback( | 112 static_cast<web::WebStateImpl*>(web_state)->RemoveScriptCommandCallback( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 id<GREYAction> WebViewTapElement(WebState* state, | 222 id<GREYAction> WebViewTapElement(WebState* state, |
219 const std::string& element_id) { | 223 const std::string& element_id) { |
220 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); | 224 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); |
221 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); | 225 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); |
222 return CGRectIsEmpty(rect) ? WebViewElementNotFound(element_id) | 226 return CGRectIsEmpty(rect) ? WebViewElementNotFound(element_id) |
223 : WebViewVerifiedActionOnElement( | 227 : WebViewVerifiedActionOnElement( |
224 state, grey_tapAtPoint(point), element_id); | 228 state, grey_tapAtPoint(point), element_id); |
225 } | 229 } |
226 | 230 |
227 } // namespace web | 231 } // namespace web |
OLD | NEW |