Index: ios/web/public/test/earl_grey/web_view_matchers.mm |
diff --git a/ios/web/public/test/earl_grey/web_view_matchers.mm b/ios/web/public/test/earl_grey/web_view_matchers.mm |
index e0202a0756140e6036363c4b7d4a9a36b78ede32..67fee3231a4bcb96ffcbc16a9671bd55d2538a12 100644 |
--- a/ios/web/public/test/earl_grey/web_view_matchers.mm |
+++ b/ios/web/public/test/earl_grey/web_view_matchers.mm |
@@ -12,7 +12,7 @@ |
#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" |
+#include "ios/testing/wait_util.h" |
#import "ios/web/public/test/web_view_interaction_test_util.h" |
using web::test::ExecuteJavaScript; |
@@ -46,21 +46,16 @@ id<GREYMatcher> webViewInWebState(WebState* web_state) { |
id<GREYMatcher> webViewContainingText(std::string text, WebState* web_state) { |
MatchesBlock matches = ^BOOL(WKWebView*) { |
- __block BOOL did_succeed = NO; |
- NSDate* deadline = |
- [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
- while (([[NSDate date] compare:deadline] != NSOrderedDescending) && |
- !did_succeed) { |
- std::unique_ptr<base::Value> value = |
- ExecuteJavaScript(web_state, kGetDocumentBodyJavaScript); |
- std::string body; |
- if (value && value->GetAsString(&body)) { |
- did_succeed = body.find(text) != std::string::npos; |
- } |
- base::test::ios::SpinRunLoopWithMaxDelay( |
- base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
- } |
- return did_succeed; |
+ return testing::WaitUntilConditionOrTimeout( |
+ testing::kWaitForUIElementTimeout, ^{ |
+ std::unique_ptr<base::Value> value = |
+ ExecuteJavaScript(web_state, kGetDocumentBodyJavaScript); |
+ std::string body; |
+ if (value && value->GetAsString(&body)) { |
+ return body.find(text) != std::string::npos; |
+ } |
+ return false; |
+ }); |
}; |
DescribeToBlock describe = ^(id<GREYDescription> description) { |
@@ -79,40 +74,35 @@ id<GREYMatcher> webViewContainingBlockedImage(std::string image_id, |
CGSize expected_size, |
WebState* web_state) { |
MatchesBlock matches = ^BOOL(WKWebView*) { |
- __block BOOL did_succeed = NO; |
- NSDate* deadline = |
- [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
- while (([[NSDate date] compare:deadline] != NSOrderedDescending) && |
- !did_succeed) { |
- NSString* const kGetElementAttributesScript = [NSString |
- stringWithFormat:@"var image = document.getElementById('%@');" |
- @"var imageHeight = image.height;" |
- @"var imageWidth = image.width;" |
- @"JSON.stringify({" |
- @" height:imageHeight," |
- @" width:imageWidth" |
- @"});", |
- base::SysUTF8ToNSString(image_id)]; |
- std::unique_ptr<base::Value> value = ExecuteJavaScript( |
- web_state, base::SysNSStringToUTF8(kGetElementAttributesScript)); |
- std::string result; |
- if (value && value->GetAsString(&result)) { |
- NSString* evaluation_result = base::SysUTF8ToNSString(result); |
- NSData* image_attributes_as_data = |
- [evaluation_result dataUsingEncoding:NSUTF8StringEncoding]; |
- NSDictionary* image_attributes = |
- [NSJSONSerialization JSONObjectWithData:image_attributes_as_data |
- options:0 |
- error:nil]; |
- CGFloat height = [image_attributes[@"height"] floatValue]; |
- CGFloat width = [image_attributes[@"width"] floatValue]; |
- did_succeed = |
- (height < expected_size.height && width < expected_size.width); |
- } |
- base::test::ios::SpinRunLoopWithMaxDelay( |
- base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
- } |
- return did_succeed; |
+ return testing::WaitUntilConditionOrTimeout( |
+ testing::kWaitForUIElementTimeout, ^{ |
+ NSString* const kGetElementAttributesScript = [NSString |
+ stringWithFormat:@"var image = document.getElementById('%@');" |
+ @"var imageHeight = image.height;" |
+ @"var imageWidth = image.width;" |
+ @"JSON.stringify({" |
+ @" height:imageHeight," |
+ @" width:imageWidth" |
+ @"});", |
+ base::SysUTF8ToNSString(image_id)]; |
+ std::unique_ptr<base::Value> value = ExecuteJavaScript( |
+ web_state, base::SysNSStringToUTF8(kGetElementAttributesScript)); |
+ std::string result; |
+ if (value && value->GetAsString(&result)) { |
+ NSString* evaluation_result = base::SysUTF8ToNSString(result); |
+ NSData* image_attributes_as_data = |
+ [evaluation_result dataUsingEncoding:NSUTF8StringEncoding]; |
+ NSDictionary* image_attributes = |
+ [NSJSONSerialization JSONObjectWithData:image_attributes_as_data |
+ options:0 |
+ error:nil]; |
+ CGFloat height = [image_attributes[@"height"] floatValue]; |
+ CGFloat width = [image_attributes[@"width"] floatValue]; |
+ return (height < expected_size.height && |
+ width < expected_size.width); |
+ } |
+ return false; |
+ }); |
}; |
DescribeToBlock describe = ^(id<GREYDescription> description) { |
@@ -131,18 +121,16 @@ id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) { |
MatchesBlock matches = ^BOOL(WKWebView*) { |
std::string script = base::StringPrintf(kTestCssSelectorJavaScriptTemplate, |
selector.c_str()); |
- __block bool did_succeed = false; |
- NSDate* deadline = |
- [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
- while (([[NSDate date] compare:deadline] != NSOrderedDescending) && |
- !did_succeed) { |
- std::unique_ptr<base::Value> value = ExecuteJavaScript(web_state, script); |
- if (value) |
- value->GetAsBoolean(&did_succeed); |
- base::test::ios::SpinRunLoopWithMaxDelay( |
- base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
- } |
- return did_succeed; |
+ return testing::WaitUntilConditionOrTimeout( |
+ testing::kWaitForUIElementTimeout, ^{ |
+ bool did_succeed = false; |
+ std::unique_ptr<base::Value> value = |
+ ExecuteJavaScript(web_state, script); |
+ if (value) { |
+ value->GetAsBoolean(&did_succeed); |
+ } |
+ return did_succeed; |
+ }); |
}; |
DescribeToBlock describe = ^(id<GREYDescription> description) { |