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/web_view_interaction_test_util.h" | 5 #import "ios/web/public/test/web_view_interaction_test_util.h" |
6 | 6 |
7 #import "base/mac/bind_objc_block.h" | 7 #import "base/mac/bind_objc_block.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 " var element = document.getElementById('%s');" | 135 " var element = document.getElementById('%s');" |
136 " if (element) {" | 136 " if (element) {" |
137 " element%s;" | 137 " element%s;" |
138 " return true;" | 138 " return true;" |
139 " }" | 139 " }" |
140 " return false;" | 140 " return false;" |
141 "})();", | 141 "})();", |
142 element_id.c_str(), js_action]; | 142 element_id.c_str(), js_action]; |
143 __block bool did_complete = false; | 143 __block bool did_complete = false; |
144 __block bool element_found = false; | 144 __block bool element_found = false; |
145 [web_controller executeUserJavaScript:script | 145 |
146 completionHandler:^(id result, NSError*) { | 146 // |executeUserJavaScript:completionHandler:| is no-op for app-specific URLs, |
147 did_complete = true; | 147 // so simulate a user gesture by calling TouchTracking method. |
148 element_found = [result boolValue]; | 148 [web_controller touched:YES]; |
149 }]; | 149 [web_controller executeJavaScript:script |
| 150 completionHandler:^(id result, NSError*) { |
| 151 did_complete = true; |
| 152 element_found = [result boolValue]; |
| 153 }]; |
150 | 154 |
151 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{ | 155 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{ |
152 return did_complete; | 156 return did_complete; |
153 }); | 157 }); |
154 | 158 |
155 return element_found; | 159 return element_found; |
156 } | 160 } |
157 | 161 |
158 bool TapWebViewElementWithId(web::WebState* web_state, | 162 bool TapWebViewElementWithId(web::WebState* web_state, |
159 const std::string& element_id) { | 163 const std::string& element_id) { |
160 return RunActionOnWebViewElementWithId(web_state, element_id, | 164 return RunActionOnWebViewElementWithId(web_state, element_id, |
161 ELEMENT_ACTION_CLICK); | 165 ELEMENT_ACTION_CLICK); |
162 } | 166 } |
163 | 167 |
164 bool FocusWebViewElementWithId(web::WebState* web_state, | 168 bool FocusWebViewElementWithId(web::WebState* web_state, |
165 const std::string& element_id) { | 169 const std::string& element_id) { |
166 return RunActionOnWebViewElementWithId(web_state, element_id, | 170 return RunActionOnWebViewElementWithId(web_state, element_id, |
167 ELEMENT_ACTION_FOCUS); | 171 ELEMENT_ACTION_FOCUS); |
168 } | 172 } |
169 | 173 |
170 bool SubmitWebViewFormWithId(web::WebState* web_state, | 174 bool SubmitWebViewFormWithId(web::WebState* web_state, |
171 const std::string& form_id) { | 175 const std::string& form_id) { |
172 return RunActionOnWebViewElementWithId(web_state, form_id, | 176 return RunActionOnWebViewElementWithId(web_state, form_id, |
173 ELEMENT_ACTION_SUBMIT); | 177 ELEMENT_ACTION_SUBMIT); |
174 } | 178 } |
175 | 179 |
176 } // namespace test | 180 } // namespace test |
177 } // namespace web | 181 } // namespace web |
OLD | NEW |