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

Side by Side Diff: ios/web/public/test/web_view_interaction_test_util.mm

Issue 2283963002: Add ability to submit a form using javascript. (Closed)
Patch Set: more descriptive naming Created 4 years, 3 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web_view_interaction_test_util.h" 5 #import "ios/web/public/test/web_view_interaction_test_util.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "ios/testing/earl_grey/wait_util.h" 9 #include "ios/testing/earl_grey/wait_util.h"
10 #import "ios/web/web_state/ui/crw_web_controller.h" 10 #import "ios/web/web_state/ui/crw_web_controller.h"
11 #include "ios/web/web_state/web_state_impl.h" 11 #include "ios/web/web_state/web_state_impl.h"
12 12
13 using web::NavigationManager; 13 using web::NavigationManager;
14 14
15 namespace web { 15 namespace web {
16 namespace test { 16 namespace test {
17 17
18 enum ElementAction { ELEMENT_ACTION_CLICK, ELEMENT_ACTION_FOCUS }; 18 enum ElementAction {
19 ELEMENT_ACTION_CLICK,
20 ELEMENT_ACTION_FOCUS,
21 ELEMENT_ACTION_SUBMIT
Eugene But (OOO till 7-30) 2016/08/26 21:48:05 Optional NIT: Maybe add comma after last item to m
edchin 2016/08/26 22:26:54 I followed the convention already on the page. See
22 };
19 23
20 // Returns whether the Javascript action specified by |action| ran on 24 // Returns whether the Javascript action specified by |action| ran on
21 // |element_id| in the passed |web_state|. 25 // |element_id| in the passed |web_state|.
22 bool RunActionOnWebViewElementWithId(web::WebState* web_state, 26 bool RunActionOnWebViewElementWithId(web::WebState* web_state,
23 const std::string& element_id, 27 const std::string& element_id,
24 ElementAction action) { 28 ElementAction action) {
25 CRWWebController* web_controller = 29 CRWWebController* web_controller =
26 static_cast<WebStateImpl*>(web_state)->GetWebController(); 30 static_cast<WebStateImpl*>(web_state)->GetWebController();
27 const char* js_action = nullptr; 31 const char* js_action = nullptr;
28 switch (action) { 32 switch (action) {
29 case ELEMENT_ACTION_CLICK: 33 case ELEMENT_ACTION_CLICK:
30 js_action = ".click()"; 34 js_action = ".click()";
31 break; 35 break;
32 case ELEMENT_ACTION_FOCUS: 36 case ELEMENT_ACTION_FOCUS:
33 js_action = ".focus();"; 37 js_action = ".focus();";
34 break; 38 break;
39 case ELEMENT_ACTION_SUBMIT:
40 js_action = ".submit();";
41 break;
35 } 42 }
36 NSString* script = [NSString 43 NSString* script = [NSString
37 stringWithFormat:@"(function() {" 44 stringWithFormat:@"(function() {"
38 " var element = document.getElementById('%s');" 45 " var element = document.getElementById('%s');"
39 " if (element) {" 46 " if (element) {"
40 " element%s;" 47 " element%s;"
41 " return true;" 48 " return true;"
42 " }" 49 " }"
43 " return false;" 50 " return false;"
44 "})();", 51 "})();",
(...skipping 18 matching lines...) Expand all
63 return RunActionOnWebViewElementWithId(web_state, element_id, 70 return RunActionOnWebViewElementWithId(web_state, element_id,
64 ELEMENT_ACTION_CLICK); 71 ELEMENT_ACTION_CLICK);
65 } 72 }
66 73
67 bool FocusWebViewElementWithId(web::WebState* web_state, 74 bool FocusWebViewElementWithId(web::WebState* web_state,
68 const std::string& element_id) { 75 const std::string& element_id) {
69 return RunActionOnWebViewElementWithId(web_state, element_id, 76 return RunActionOnWebViewElementWithId(web_state, element_id,
70 ELEMENT_ACTION_FOCUS); 77 ELEMENT_ACTION_FOCUS);
71 } 78 }
72 79
80 bool SubmitWebViewFormWithId(web::WebState* web_state,
81 const std::string& form_id) {
82 return RunActionOnWebViewElementWithId(web_state, form_id,
83 ELEMENT_ACTION_SUBMIT);
84 }
85
73 } // namespace test 86 } // namespace test
74 } // namespace web 87 } // namespace web
OLDNEW
« 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