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