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