Index: ios/web/public/test/web_view_interaction_test_util.mm |
diff --git a/ios/web/public/test/web_view_interaction_test_util.mm b/ios/web/public/test/web_view_interaction_test_util.mm |
index 7f989186fc20c7e98e18091afe456a076b019ac3..4b6b0e448ebbf3a98dad7ab25e95368930f60a58 100644 |
--- a/ios/web/public/test/web_view_interaction_test_util.mm |
+++ b/ios/web/public/test/web_view_interaction_test_util.mm |
@@ -15,12 +15,12 @@ using web::NavigationManager; |
namespace web { |
namespace test { |
-void TapWebViewElementWithId(web::WebState* web_state, |
+bool TapWebViewElementWithId(web::WebState* web_state, |
const std::string& element_id) { |
- RunActionOnWebViewElementWithId(web_state, element_id, CLICK); |
+ return RunActionOnWebViewElementWithId(web_state, element_id, CLICK); |
} |
-void RunActionOnWebViewElementWithId(web::WebState* web_state, |
+bool RunActionOnWebViewElementWithId(web::WebState* web_state, |
const std::string& element_id, |
ElementAction action) { |
CRWWebController* web_controller = |
@@ -34,18 +34,30 @@ void RunActionOnWebViewElementWithId(web::WebState* web_state, |
jsAction = ".focus();"; |
break; |
} |
- NSString* script = |
- [NSString stringWithFormat:@"document.getElementById('%s')%s", |
- element_id.c_str(), jsAction]; |
+ NSString* script = [NSString |
+ stringWithFormat:@"(function() {" |
+ " var element = document.getElementById('%s');" |
+ " if (element) {" |
+ " element%s;" |
+ " return true;" |
+ " }" |
+ " return false;" |
+ "})();", |
+ element_id.c_str(), jsAction]; |
Eugene But (OOO till 7-30)
2016/08/26 13:19:56
Could you please s/jsAction/js_action
jif-google
2016/08/26 13:30:35
Acknowledged.
gambard
2016/08/26 14:35:52
Done.
|
__block bool did_complete = false; |
+ __block bool element_found = false; |
[web_controller executeUserJavaScript:script |
- completionHandler:^(id, NSError*) { |
+ completionHandler:^(id result, NSError* error) { |
did_complete = true; |
+ if (!error && result) |
Eugene But (OOO till 7-30)
2016/08/26 13:19:56
No need for this check if there is an error |resul
jif-google
2016/08/26 13:30:35
Acknowledged.
gambard
2016/08/26 14:35:52
Done.
|
+ element_found = [result boolValue]; |
}]; |
testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{ |
return did_complete; |
}); |
+ |
+ return element_found; |
} |
} // namespace test |