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

Unified Diff: ios/web/public/test/web_view_interaction_test_util.mm

Issue 2268863004: Add a return value to TapWebViewElementWithId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/public/test/web_view_interaction_test_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..db4000300e857f21bb245d6c750af05017db6fbd 100644
--- a/ios/web/public/test/web_view_interaction_test_util.mm
+++ b/ios/web/public/test/web_view_interaction_test_util.mm
@@ -15,37 +15,59 @@ using web::NavigationManager;
namespace web {
namespace test {
-void TapWebViewElementWithId(web::WebState* web_state,
- const std::string& element_id) {
- RunActionOnWebViewElementWithId(web_state, element_id, CLICK);
-}
+enum ElementAction { ELEMENT_ACTION_CLICK, ELEMENT_ACTION_FOCUS };
-void RunActionOnWebViewElementWithId(web::WebState* web_state,
+// Returns whether the Javascript action specified by |action| ran on
+// |element_id| in the passed |web_state|.
+bool RunActionOnWebViewElementWithId(web::WebState* web_state,
const std::string& element_id,
ElementAction action) {
CRWWebController* web_controller =
static_cast<WebStateImpl*>(web_state)->GetWebController();
- const char* jsAction = nullptr;
+ const char* js_action = nullptr;
switch (action) {
- case CLICK:
- jsAction = ".click()";
+ case ELEMENT_ACTION_CLICK:
+ js_action = ".click()";
break;
- case FOCUS:
- jsAction = ".focus();";
+ case ELEMENT_ACTION_FOCUS:
+ js_action = ".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(), js_action];
__block bool did_complete = false;
+ __block bool element_found = false;
[web_controller executeUserJavaScript:script
- completionHandler:^(id, NSError*) {
+ completionHandler:^(id result, NSError*) {
did_complete = true;
+ element_found = [result boolValue];
}];
testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{
return did_complete;
});
+
+ return element_found;
+}
+
+bool TapWebViewElementWithId(web::WebState* web_state,
+ const std::string& element_id) {
+ return RunActionOnWebViewElementWithId(web_state, element_id,
+ ELEMENT_ACTION_CLICK);
+}
+
+bool FocusWebViewElementWithId(web::WebState* web_state,
+ const std::string& element_id) {
+ return RunActionOnWebViewElementWithId(web_state, element_id,
+ ELEMENT_ACTION_FOCUS);
}
} // namespace test
« no previous file with comments | « ios/web/public/test/web_view_interaction_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698