| 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 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/test/ios/wait_util.h" | 11 #include "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 using web::test::ExecuteJavaScript; | 18 using web::test::ExecuteJavaScript; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Long press duration to trigger context menu. | 22 // Long press duration to trigger context menu. |
| 23 const NSTimeInterval kContextMenuLongPressDuration = 0.3; | 23 const NSTimeInterval kContextMenuLongPressDuration = 0.3; |
| 24 | 24 |
| 25 // Duration to wait for verification of JavaScript action. |
| 26 // TODO(crbug.com/670910): Reduce duration if the time required for verification |
| 27 // is reduced on devices. |
| 28 const NSTimeInterval kWaitForVerificationTimeout = 8.0; |
| 29 |
| 25 // Callback prefix for injected verifiers. | 30 // Callback prefix for injected verifiers. |
| 26 const std::string CallbackPrefixForElementId(const std::string& element_id) { | 31 const std::string CallbackPrefixForElementId(const std::string& element_id) { |
| 27 return "__web_test_" + element_id + "_interaction"; | 32 return "__web_test_" + element_id + "_interaction"; |
| 28 } | 33 } |
| 29 | 34 |
| 30 // Generic verification injector. Injects one-time mousedown verification into | 35 // Generic verification injector. Injects one-time mousedown verification into |
| 31 // |web_state| that will set the boolean pointed to by |verified| to true when | 36 // |web_state| that will set the boolean pointed to by |verified| to true when |
| 32 // |web_state|'s webview registers the mousedown event. | 37 // |web_state|'s webview registers the mousedown event. |
| 33 // RemoveVerifierForElementWithId() should be called after this to ensure | 38 // RemoveVerifierForElementWithId() should be called after this to ensure |
| 34 // future tests can add verifiers with the same prefix. | 39 // future tests can add verifiers with the same prefix. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (*error) { | 173 if (*error) { |
| 169 return NO; | 174 return NO; |
| 170 } | 175 } |
| 171 | 176 |
| 172 // Wait for the verified to trigger and set |verified|. | 177 // Wait for the verified to trigger and set |verified|. |
| 173 NSString* verification_timeout_message = | 178 NSString* verification_timeout_message = |
| 174 [NSString stringWithFormat:@"The action (%@) on element_id %s wasn't " | 179 [NSString stringWithFormat:@"The action (%@) on element_id %s wasn't " |
| 175 @"verified before timing out.", | 180 @"verified before timing out.", |
| 176 action.name, element_id.c_str()]; | 181 action.name, element_id.c_str()]; |
| 177 GREYAssert(testing::WaitUntilConditionOrTimeout( | 182 GREYAssert(testing::WaitUntilConditionOrTimeout( |
| 178 testing::kWaitForJSCompletionTimeout, | 183 kWaitForVerificationTimeout, |
| 179 ^{ | 184 ^{ |
| 180 return verified; | 185 return verified; |
| 181 }), | 186 }), |
| 182 verification_timeout_message); | 187 verification_timeout_message); |
| 183 | 188 |
| 184 // If |verified| is not true, the wait condition should have already exited | 189 // If |verified| is not true, the wait condition should have already exited |
| 185 // this control flow, so sanity check that it has in fact been set to | 190 // this control flow, so sanity check that it has in fact been set to |
| 186 // true by this point. | 191 // true by this point. |
| 187 DCHECK(verified); | 192 DCHECK(verified); |
| 188 return YES; | 193 return YES; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 213 id<GREYAction> webViewTapElement(WebState* state, | 218 id<GREYAction> webViewTapElement(WebState* state, |
| 214 const std::string& element_id) { | 219 const std::string& element_id) { |
| 215 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); | 220 CGRect rect = web::test::GetBoundingRectOfElementWithId(state, element_id); |
| 216 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); | 221 CGPoint point = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); |
| 217 return CGRectIsEmpty(rect) ? webViewElementNotFound(element_id) | 222 return CGRectIsEmpty(rect) ? webViewElementNotFound(element_id) |
| 218 : webViewVerifiedActionOnElement( | 223 : webViewVerifiedActionOnElement( |
| 219 state, grey_tapAtPoint(point), element_id); | 224 state, grey_tapAtPoint(point), element_id); |
| 220 } | 225 } |
| 221 | 226 |
| 222 } // namespace web | 227 } // namespace web |
| OLD | NEW |