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

Unified Diff: ios/web/public/test/earl_grey/web_view_actions.mm

Issue 2448753002: Refactor wait_util so it isn't coupled to EarlGrey. (Closed)
Patch Set: cleanup Created 4 years, 2 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
Index: ios/web/public/test/earl_grey/web_view_actions.mm
diff --git a/ios/web/public/test/earl_grey/web_view_actions.mm b/ios/web/public/test/earl_grey/web_view_actions.mm
index a8b13fb38ddf449dc932551f43a8140b134c96ad..6396b2ff623bccc238b254ed26bb80256b3529fa 100644
--- a/ios/web/public/test/earl_grey/web_view_actions.mm
+++ b/ios/web/public/test/earl_grey/web_view_actions.mm
@@ -10,7 +10,7 @@
#include "base/strings/stringprintf.h"
#include "base/test/ios/wait_util.h"
#include "base/values.h"
-#import "ios/testing/earl_grey/wait_util.h"
+#import "ios/testing/wait_util.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/web/public/test/web_view_interaction_test_util.h"
#import "ios/web/web_state/web_state_impl.h"
@@ -62,26 +62,25 @@ bool AddVerifierToElementWithId(web::WebState* web_state,
const std::string kAddVerifierScript =
base::StringPrintf(kAddInteractionVerifierScriptTemplate,
element_id.c_str(), kCallbackInvocation.c_str());
- NSDate* deadline =
- [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout];
- bool verifier_added = false;
- while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
- !verifier_added) {
- std::unique_ptr<base::Value> value =
- web::test::ExecuteJavaScript(web_state, kAddVerifierScript);
- if (value) {
- std::string error;
- if (value->GetAsString(&error)) {
- DLOG(ERROR) << "Verifier injection failed: " << error << ", retrying.";
- } else if (value->GetAsBoolean(&verifier_added)) {
- verifier_added = true;
- }
- }
- base::test::ios::SpinRunLoopWithMaxDelay(
- base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds));
- }
- if (!verifier_added)
+ bool success = testing::WaitUntilConditionOrTimeout(
+ testing::kWaitForUIElementTimeout, ^bool() {
Eugene But (OOO till 7-30) 2016/10/25 14:43:39 Optional nit: You don't need |bool() |
baxley 2016/10/25 18:50:05 Done.
+ bool verifier_added = false;
+ std::unique_ptr<base::Value> value =
+ web::test::ExecuteJavaScript(web_state, kAddVerifierScript);
+ if (value) {
+ std::string error;
+ if (value->GetAsString(&error)) {
+ DLOG(ERROR) << "Verifier injection failed: " << error
+ << ", retrying.";
+ } else if (value->GetAsBoolean(&verifier_added)) {
+ return true;
+ }
+ }
+ return false;
+ });
+
+ if (!success)
return false;
// The callback doesn't care about any of the parameters, just whether it is
@@ -175,10 +174,12 @@ id<GREYAction> webViewVerifiedActionOnElement(WebState* state,
[NSString stringWithFormat:@"The action (%@) on element_id %s wasn't "
@"verified before timing out.",
action.name, element_id.c_str()];
- testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout,
- verification_timeout_message, ^{
- return verified;
- });
+ GREYAssert(testing::WaitUntilConditionOrTimeout(
+ testing::kWaitForJSCompletionTimeout,
+ ^{
+ return verified;
+ }),
+ verification_timeout_message);
// If |verified| is not true, the wait condition should have already exited
// this control flow, so sanity check that it has in fact been set to

Powered by Google App Engine
This is Rietveld 408576698