OLD | NEW |
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 #include "ios/testing/earl_grey/wait_util.h" |
6 | 6 |
7 #import <EarlGrey/EarlGrey.h> | 7 #import <EarlGrey/EarlGrey.h> |
8 | 8 |
9 #include "base/test/ios/wait_util.h" | 9 #include "base/test/ios/wait_util.h" |
| 10 #include "ios/testing/wait_util.h" |
10 | 11 |
11 namespace testing { | 12 namespace testing { |
12 | 13 |
13 const NSTimeInterval kSpinDelaySeconds = 0.01; | |
14 const NSTimeInterval kWaitForJSCompletionTimeout = 2.0; | |
15 const NSTimeInterval kWaitForUIElementTimeout = 4.0; | |
16 const NSTimeInterval kWaitForDownloadTimeout = 10.0; | |
17 | |
18 void WaitUntilCondition(NSTimeInterval timeout, | 14 void WaitUntilCondition(NSTimeInterval timeout, |
19 NSString* timeoutDescription, | 15 NSString* timeoutDescription, |
20 bool (^condition)(void)) { | 16 bool (^condition)(void)) { |
21 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:timeout]; | 17 GREYAssert(testing::WaitUntilConditionOrTimeout(timeout, condition), |
22 while (!condition() && | 18 timeoutDescription); |
23 [[NSDate date] compare:deadline] != NSOrderedDescending) { | |
24 base::test::ios::SpinRunLoopWithMaxDelay( | |
25 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); | |
26 } | |
27 GREYAssert(condition(), timeoutDescription); | |
28 } | 19 } |
29 | 20 |
30 void WaitUntilCondition(NSTimeInterval timeout, bool (^condition)(void)) { | 21 void WaitUntilCondition(NSTimeInterval timeout, bool (^condition)(void)) { |
31 WaitUntilCondition(timeout, @"Timeout waiting for condition.", condition); | 22 WaitUntilCondition(timeout, @"Timeout waiting for condition.", condition); |
32 } | 23 } |
33 | 24 |
34 } // namespace testing | 25 } // namespace testing |
OLD | NEW |