Chromium Code Reviews| 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 <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/strings/string_util.h" | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
Toy don't need this, because there is no need for
gambard
2016/08/24 07:08:49
Done.
| |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/ios/wait_util.h" | 13 #include "base/test/ios/wait_util.h" |
| 14 #include "base/values.h" | |
| 13 #include "ios/testing/earl_grey/wait_util.h" | 15 #include "ios/testing/earl_grey/wait_util.h" |
| 14 | 16 |
| 15 using web::NavigationManager; | 17 using web::NavigationManager; |
| 16 | 18 |
| 17 namespace web { | 19 namespace web { |
| 18 namespace test { | 20 namespace test { |
| 19 | 21 |
| 20 void TapWebViewElementWithId(web::WebState* web_state, | 22 bool TapWebViewElementWithId(web::WebState* web_state, |
| 21 const std::string& element_id) { | 23 const std::string& element_id) { |
| 22 const char kJsClick[] = "document.getElementById('%s').click()"; | 24 const char kJsClick[] = |
| 25 "(function() {" | |
| 26 " var element = document.getElementById('%s');" | |
| 27 " if(typeof(element) != 'undefined' && element != null) {" | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
Would this work?:
if (element) {"
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
Space after |if|
gambard
2016/08/24 07:08:49
Done.
gambard
2016/08/24 07:08:50
Done.
| |
| 28 " element.click();" | |
| 29 " return 'true';" | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
return true;
And then use GetAsBoolean
gambard
2016/08/24 07:08:50
Done.
| |
| 30 " }" | |
| 31 " return 'false';" | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
return false;
gambard
2016/08/24 07:08:49
Done.
| |
| 32 "})();"; | |
| 33 | |
| 23 __block bool did_complete = false; | 34 __block bool did_complete = false; |
| 35 __block bool element_found = false; | |
| 24 web_state->ExecuteJavaScript( | 36 web_state->ExecuteJavaScript( |
| 25 base::UTF8ToUTF16(base::StringPrintf(kJsClick, element_id.c_str())), | 37 base::UTF8ToUTF16(base::StringPrintf(kJsClick, element_id.c_str())), |
| 26 base::BindBlock(^(const base::Value*) { | 38 base::BindBlock(^(const base::Value* value) { |
| 27 did_complete = true; | 39 did_complete = true; |
| 40 std::string str; | |
| 41 value->GetAsString(&str); | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
base::BindBlock(^(const base::Value* value) {
if
gambard
2016/08/24 07:08:49
Done.
| |
| 42 bool found = | |
| 43 base::StartsWith(str, "true", base::CompareCase::INSENSITIVE_ASCII); | |
| 44 if (!found) | |
| 45 return; | |
| 46 element_found = true; | |
| 28 })); | 47 })); |
| 29 | 48 |
| 30 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{ | 49 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{ |
| 31 return did_complete; | 50 return did_complete; |
| 32 }); | 51 }); |
| 52 | |
| 53 return did_complete && element_found; | |
|
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
return element_found;
You won't be here if |did_c
gambard
2016/08/24 07:08:49
Done.
| |
| 33 } | 54 } |
| 34 | 55 |
| 35 } // namespace test | 56 } // namespace test |
| 36 } // namespace web | 57 } // namespace web |
| OLD | NEW |