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

Side by Side Diff: ios/testing/wait_util.mm

Issue 2448753002: Refactor wait_util so it isn't coupled to EarlGrey. (Closed)
Patch Set: compile Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ios/testing/wait_util.h ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ios/testing/earl_grey/wait_util.h" 5 #import "ios/testing/wait_util.h"
6
7 #import <EarlGrey/EarlGrey.h>
8 6
9 #include "base/test/ios/wait_util.h" 7 #include "base/test/ios/wait_util.h"
10 8
11 namespace testing { 9 namespace testing {
12 10
13 const NSTimeInterval kSpinDelaySeconds = 0.01; 11 const NSTimeInterval kSpinDelaySeconds = 0.01;
14 const NSTimeInterval kWaitForJSCompletionTimeout = 2.0; 12 const NSTimeInterval kWaitForJSCompletionTimeout = 2.0;
15 const NSTimeInterval kWaitForUIElementTimeout = 4.0; 13 const NSTimeInterval kWaitForUIElementTimeout = 4.0;
16 const NSTimeInterval kWaitForDownloadTimeout = 10.0; 14 const NSTimeInterval kWaitForDownloadTimeout = 10.0;
17 15
18 void WaitUntilCondition(NSTimeInterval timeout, 16 bool WaitUntilConditionOrTimeout(NSTimeInterval timeout,
19 NSString* timeoutDescription, 17 ConditionBlock condition) {
20 bool (^condition)(void)) {
21 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:timeout]; 18 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:timeout];
22 while (!condition() && 19 bool success = condition();
23 [[NSDate date] compare:deadline] != NSOrderedDescending) { 20 while (!success && [[NSDate date] compare:deadline] != NSOrderedDescending) {
24 base::test::ios::SpinRunLoopWithMaxDelay( 21 base::test::ios::SpinRunLoopWithMaxDelay(
25 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); 22 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds));
23 success = condition();
26 } 24 }
27 GREYAssert(condition(), timeoutDescription); 25 return success;
28 }
29
30 void WaitUntilCondition(NSTimeInterval timeout, bool (^condition)(void)) {
31 WaitUntilCondition(timeout, @"Timeout waiting for condition.", condition);
32 } 26 }
33 27
34 } // namespace testing 28 } // namespace testing
OLDNEW
« no previous file with comments | « ios/testing/wait_util.h ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698