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

Side by Side 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: Remove unecessary headers 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
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 void TapWebViewElementWithId(web::WebState* web_state, 18 bool TapWebViewElementWithId(web::WebState* web_state,
19 const std::string& element_id) { 19 const std::string& element_id) {
20 RunActionOnWebViewElementWithId(web_state, element_id, CLICK); 20 return RunActionOnWebViewElementWithId(web_state, element_id, CLICK);
21 } 21 }
22 22
23 void RunActionOnWebViewElementWithId(web::WebState* web_state, 23 bool RunActionOnWebViewElementWithId(web::WebState* web_state,
24 const std::string& element_id, 24 const std::string& element_id,
25 ElementAction action) { 25 ElementAction action) {
26 CRWWebController* web_controller = 26 CRWWebController* web_controller =
27 static_cast<WebStateImpl*>(web_state)->GetWebController(); 27 static_cast<WebStateImpl*>(web_state)->GetWebController();
28 const char* jsAction = nullptr; 28 const char* jsAction = nullptr;
29 switch (action) { 29 switch (action) {
30 case CLICK: 30 case CLICK:
31 jsAction = ".click()"; 31 jsAction = ".click()";
32 break; 32 break;
33 case FOCUS: 33 case FOCUS:
34 jsAction = ".focus();"; 34 jsAction = ".focus();";
35 break; 35 break;
36 } 36 }
37 NSString* script = 37 NSString* script = [NSString
38 [NSString stringWithFormat:@"document.getElementById('%s')%s", 38 stringWithFormat:@"(function() {"
39 element_id.c_str(), jsAction]; 39 " var element = document.getElementById('%s');"
40 " if (element) {"
41 " element%s;"
42 " return true;"
43 " }"
44 " return false;"
45 "})();",
46 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.
40 __block bool did_complete = false; 47 __block bool did_complete = false;
48 __block bool element_found = false;
41 [web_controller executeUserJavaScript:script 49 [web_controller executeUserJavaScript:script
42 completionHandler:^(id, NSError*) { 50 completionHandler:^(id result, NSError* error) {
43 did_complete = true; 51 did_complete = true;
52 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.
53 element_found = [result boolValue];
44 }]; 54 }];
45 55
46 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{ 56 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{
47 return did_complete; 57 return did_complete;
48 }); 58 });
59
60 return element_found;
49 } 61 }
50 62
51 } // namespace test 63 } // namespace test
52 } // namespace web 64 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698