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 #import "ios/testing/wait_util.h" | 5 #import "ios/testing/wait_util.h" |
6 | 6 |
7 #include "base/test/ios/wait_util.h" | 7 #include "base/test/ios/wait_util.h" |
8 | 8 |
| 9 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 10 #error "This file requires ARC support." |
| 11 #endif |
| 12 |
9 namespace testing { | 13 namespace testing { |
10 | 14 |
11 const NSTimeInterval kSpinDelaySeconds = 0.01; | 15 const NSTimeInterval kSpinDelaySeconds = 0.01; |
12 const NSTimeInterval kWaitForJSCompletionTimeout = 2.0; | 16 const NSTimeInterval kWaitForJSCompletionTimeout = 2.0; |
13 const NSTimeInterval kWaitForUIElementTimeout = 4.0; | 17 const NSTimeInterval kWaitForUIElementTimeout = 4.0; |
14 const NSTimeInterval kWaitForDownloadTimeout = 10.0; | 18 const NSTimeInterval kWaitForDownloadTimeout = 10.0; |
15 | 19 |
16 bool WaitUntilConditionOrTimeout(NSTimeInterval timeout, | 20 bool WaitUntilConditionOrTimeout(NSTimeInterval timeout, |
17 ConditionBlock condition) { | 21 ConditionBlock condition) { |
18 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:timeout]; | 22 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:timeout]; |
19 bool success = condition(); | 23 bool success = condition(); |
20 while (!success && [[NSDate date] compare:deadline] != NSOrderedDescending) { | 24 while (!success && [[NSDate date] compare:deadline] != NSOrderedDescending) { |
21 base::test::ios::SpinRunLoopWithMaxDelay( | 25 base::test::ios::SpinRunLoopWithMaxDelay( |
22 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); | 26 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
23 success = condition(); | 27 success = condition(); |
24 } | 28 } |
25 return success; | 29 return success; |
26 } | 30 } |
27 | 31 |
28 } // namespace testing | 32 } // namespace testing |
OLD | NEW |