Index: ios/web/public/test/web_view_interaction_test_util.mm |
diff --git a/ios/web/public/test/web_view_interaction_test_util.mm b/ios/web/public/test/web_view_interaction_test_util.mm |
index 2290c0619c0e38c7cecff0519f08807cf95cd4bc..fb3768ece2ea1c563fef6919df10c6b3d4268803 100644 |
--- a/ios/web/public/test/web_view_interaction_test_util.mm |
+++ b/ios/web/public/test/web_view_interaction_test_util.mm |
@@ -7,9 +7,11 @@ |
#import <Foundation/Foundation.h> |
#include "base/mac/bind_objc_block.h" |
+#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.
|
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/test/ios/wait_util.h" |
+#include "base/values.h" |
#include "ios/testing/earl_grey/wait_util.h" |
using web::NavigationManager; |
@@ -17,20 +19,39 @@ using web::NavigationManager; |
namespace web { |
namespace test { |
-void TapWebViewElementWithId(web::WebState* web_state, |
+bool TapWebViewElementWithId(web::WebState* web_state, |
const std::string& element_id) { |
- const char kJsClick[] = "document.getElementById('%s').click()"; |
+ const char kJsClick[] = |
+ "(function() {" |
+ " var element = document.getElementById('%s');" |
+ " 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.
|
+ " element.click();" |
+ " 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.
|
+ " }" |
+ " return 'false';" |
Eugene But (OOO till 7-30)
2016/08/23 15:22:43
return false;
gambard
2016/08/24 07:08:49
Done.
|
+ "})();"; |
+ |
__block bool did_complete = false; |
+ __block bool element_found = false; |
web_state->ExecuteJavaScript( |
base::UTF8ToUTF16(base::StringPrintf(kJsClick, element_id.c_str())), |
- base::BindBlock(^(const base::Value*) { |
+ base::BindBlock(^(const base::Value* value) { |
did_complete = true; |
+ std::string str; |
+ 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.
|
+ bool found = |
+ base::StartsWith(str, "true", base::CompareCase::INSENSITIVE_ASCII); |
+ if (!found) |
+ return; |
+ element_found = true; |
})); |
testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{ |
return did_complete; |
}); |
+ |
+ 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.
|
} |
} // namespace test |
-} // namespace web |
+} // namespace web |