Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/test/ios/wait_util.h" | 5 #import "base/test/ios/wait_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/timer/elapsed_timer.h" | 13 #include "base/timer/elapsed_timer.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 namespace test { | 16 namespace test { |
| 17 namespace ios { | 17 namespace ios { |
| 18 | 18 |
| 19 TimeDelta TimeUntilCondition(ProceduralBlock action, | 19 TimeDelta TimeUntilCondition(ProceduralBlock action, |
| 20 ConditionBlock condition, | 20 ConditionBlock condition, |
| 21 MessageLoop* message_loop, | 21 MessageLoop* message_loop, |
| 22 TimeDelta timeout) { | 22 TimeDelta timeout) { |
| 23 ElapsedTimer timer; | 23 ElapsedTimer timer; |
| 24 if (action) | 24 if (action) |
| 25 action(); | 25 action(); |
| 26 if (timeout.is_zero()) | 26 if (timeout.is_zero()) |
| 27 timeout = TestTimeouts::action_timeout(); | 27 timeout = TestTimeouts::action_timeout(); |
| 28 const TimeDelta spin_delay(TimeDelta::FromMilliseconds(10)); | 28 const TimeDelta spin_delay(TimeDelta::FromMilliseconds(10)); |
| 29 while (timer.Elapsed() < timeout && (!condition || !condition())) { | 29 while (timer.Elapsed() < timeout && (!condition || !condition())) { |
| 30 SpinRunLoopWithMaxDelay(spin_delay); | 30 SpinRunLoopWithMaxDelay(spin_delay); |
| 31 if (message_loop) { | 31 if (message_loop) { |
|
Lei Zhang
2016/07/08 17:08:42
Can we, maybe in a follow up, replace |message_loo
| |
| 32 message_loop->RunUntilIdle(); | 32 RunLoop().RunUntilIdle(); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 TimeDelta elapsed = timer.Elapsed(); | 35 TimeDelta elapsed = timer.Elapsed(); |
| 36 // If DCHECK is ever hit, check if |action| is doing something that is | 36 // If DCHECK is ever hit, check if |action| is doing something that is |
| 37 // taking an unreasonably long time, or if |condition| does not come | 37 // taking an unreasonably long time, or if |condition| does not come |
| 38 // true quickly enough. Increase |timeout| only if necessary. | 38 // true quickly enough. Increase |timeout| only if necessary. |
| 39 DCHECK(!condition || condition()); | 39 DCHECK(!condition || condition()); |
| 40 return elapsed; | 40 return elapsed; |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 53 void SpinRunLoopWithMaxDelay(TimeDelta max_delay) { | 53 void SpinRunLoopWithMaxDelay(TimeDelta max_delay) { |
| 54 scoped_nsobject<NSDate> beforeDate( | 54 scoped_nsobject<NSDate> beforeDate( |
| 55 [[NSDate alloc] initWithTimeIntervalSinceNow:max_delay.InSecondsF()]); | 55 [[NSDate alloc] initWithTimeIntervalSinceNow:max_delay.InSecondsF()]); |
| 56 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode | 56 [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode |
| 57 beforeDate:beforeDate]; | 57 beforeDate:beforeDate]; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace ios | 60 } // namespace ios |
| 61 } // namespace test | 61 } // namespace test |
| 62 } // namespace base | 62 } // namespace base |
| OLD | NEW |