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