1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_IOS_WAIT_UTIL_H_ 6 #define BASE_TEST_IOS_WAIT_UTIL_H_ 7 8 #import <Foundation/Foundation.h> 9 10 #include "base/ios/block_types.h" 11 #include "base/time/time.h" 12 13 namespace base::test::ios { 14 15 // Constant for UI wait loop. 16 constexpr TimeDelta kSpinDelaySeconds = Milliseconds(10); 17 18 // Constant for timeout while waiting for UI element. 19 constexpr TimeDelta kWaitForUIElementTimeout = Seconds(4); 20 21 // Constant for timeout while waiting for JavaScript completion. 22 constexpr TimeDelta kWaitForJSCompletionTimeout = Seconds(6); 23 24 // Constant for timeout while waiting for a download to complete. 25 constexpr TimeDelta kWaitForDownloadTimeout = Seconds(10); 26 27 // Constant for timeout while waiting for a pageload to complete. 28 constexpr TimeDelta kWaitForPageLoadTimeout = Seconds(10); 29 30 // Constant for timeout while waiting for a generic action to complete. 31 constexpr TimeDelta kWaitForActionTimeout = Seconds(10); 32 33 // Constant for timeout while waiting for clear browsing data. It seems this 34 // can take a very long time on the bots when running simulators in parallel. 35 // TODO(crbug.com/993513): Investigate why this is sometimes very slow. 36 constexpr TimeDelta kWaitForClearBrowsingDataTimeout = Seconds(45); 37 38 // Constant for timeout while waiting for cookies operations to complete. 39 constexpr TimeDelta kWaitForCookiesTimeout = Seconds(4); 40 41 // Constant for timeout while waiting for a file operation to complete. 42 constexpr TimeDelta kWaitForFileOperationTimeout = Seconds(2); 43 44 // Returns true when condition() becomes true, otherwise returns false after 45 // |timeout|. Repetitively runs the current NSRunLoop and the current 46 // MessageLoop (if |run_message_loop| is true). Passing |run_message_loop| true 47 // only makes sense in unit tests. 48 [[nodiscard]] bool WaitUntilConditionOrTimeout(TimeDelta timeout, 49 bool run_message_loop, 50 ConditionBlock condition); 51 52 // Same as above but `run_message_loop` is false. 53 [[nodiscard]] bool WaitUntilConditionOrTimeout(TimeDelta timeout, 54 ConditionBlock condition); 55 56 // Lets the run loop of the current thread process other messages 57 // within the given maximum delay. This method may return before max_delay 58 // elapsed. 59 void SpinRunLoopWithMaxDelay(TimeDelta max_delay); 60 61 // Lets the run loop of the current thread process other messages 62 // within the given minimum delay. This method returns after |min_delay| 63 // elapsed. 64 void SpinRunLoopWithMinDelay(TimeDelta min_delay); 65 66 } // namespace base::test::ios 67 68 #endif // BASE_TEST_IOS_WAIT_UTIL_H_ 69