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