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

Unified 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: Created 4 years, 4 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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