Commit 2bff664c authored by edchin's avatar edchin Committed by Commit bot

Add ability to submit a form using javascript.

BUG=none

Review-Url: https://codereview.chromium.org/2283963002
Cr-Commit-Position: refs/heads/master@{#414854}
parent 15f606fd
...@@ -19,5 +19,9 @@ bool TapWebViewElementWithId(web::WebState* web_state, ...@@ -19,5 +19,9 @@ bool TapWebViewElementWithId(web::WebState* web_state,
bool FocusWebViewElementWithId(web::WebState* web_state, bool FocusWebViewElementWithId(web::WebState* web_state,
const std::string& element_id); const std::string& element_id);
// Returns whether the form with |form_id| in the passed |web_state| has been
// submitted using a JavaScript submit() event.
bool SubmitWebViewFormWithId(web::WebState* web_state,
const std::string& form_id);
} // namespace test } // namespace test
} // namespace web } // namespace web
...@@ -15,7 +15,11 @@ using web::NavigationManager; ...@@ -15,7 +15,11 @@ using web::NavigationManager;
namespace web { namespace web {
namespace test { namespace test {
enum ElementAction { ELEMENT_ACTION_CLICK, ELEMENT_ACTION_FOCUS }; enum ElementAction {
ELEMENT_ACTION_CLICK,
ELEMENT_ACTION_FOCUS,
ELEMENT_ACTION_SUBMIT
};
// Returns whether the Javascript action specified by |action| ran on // Returns whether the Javascript action specified by |action| ran on
// |element_id| in the passed |web_state|. // |element_id| in the passed |web_state|.
...@@ -32,6 +36,9 @@ bool RunActionOnWebViewElementWithId(web::WebState* web_state, ...@@ -32,6 +36,9 @@ bool RunActionOnWebViewElementWithId(web::WebState* web_state,
case ELEMENT_ACTION_FOCUS: case ELEMENT_ACTION_FOCUS:
js_action = ".focus();"; js_action = ".focus();";
break; break;
case ELEMENT_ACTION_SUBMIT:
js_action = ".submit();";
break;
} }
NSString* script = [NSString NSString* script = [NSString
stringWithFormat:@"(function() {" stringWithFormat:@"(function() {"
...@@ -70,5 +77,11 @@ bool FocusWebViewElementWithId(web::WebState* web_state, ...@@ -70,5 +77,11 @@ bool FocusWebViewElementWithId(web::WebState* web_state,
ELEMENT_ACTION_FOCUS); ELEMENT_ACTION_FOCUS);
} }
bool SubmitWebViewFormWithId(web::WebState* web_state,
const std::string& form_id) {
return RunActionOnWebViewElementWithId(web_state, form_id,
ELEMENT_ACTION_SUBMIT);
}
} // namespace test } // namespace test
} // namespace web } // namespace web
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment