wait_util.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_TEST_IOS_WAIT_UTIL_H_
  5. #define BASE_TEST_IOS_WAIT_UTIL_H_
  6. #import <Foundation/Foundation.h>
  7. #include "base/ios/block_types.h"
  8. #include "base/time/time.h"
  9. namespace base {
  10. namespace test {
  11. namespace ios {
  12. // Constant for UI wait loop in seconds.
  13. extern const NSTimeInterval kSpinDelaySeconds;
  14. // Constant for timeout in seconds while waiting for UI element.
  15. extern const NSTimeInterval kWaitForUIElementTimeout;
  16. // Constant for timeout in seconds while waiting for JavaScript completion.
  17. extern const NSTimeInterval kWaitForJSCompletionTimeout;
  18. // Constant for timeout in seconds while waiting for a download to complete.
  19. extern const NSTimeInterval kWaitForDownloadTimeout;
  20. // Constant for timeout in seconds while waiting for a pageload to complete.
  21. extern const NSTimeInterval kWaitForPageLoadTimeout;
  22. // Constant for timeout in seconds while waiting for a generic action to
  23. // complete.
  24. extern const NSTimeInterval kWaitForActionTimeout;
  25. // Constant for timeout in seconds while waiting for clear browsing data. It
  26. // seems this can take a very long time on the bots when running simulators in
  27. // parallel. TODO(crbug.com/993513): Investigate why this is sometimes very
  28. // slow.
  29. extern const NSTimeInterval kWaitForClearBrowsingDataTimeout;
  30. // Constant for timeout in seconds while waiting for cookies operations to
  31. // complete.
  32. extern const NSTimeInterval kWaitForCookiesTimeout;
  33. // Constant for timeout in seconds while waiting for a file operation to
  34. // complete.
  35. extern const NSTimeInterval kWaitForFileOperationTimeout;
  36. // Returns true when condition() becomes true, otherwise returns false after
  37. // |timeout|.
  38. [[nodiscard]] bool WaitUntilConditionOrTimeout(NSTimeInterval timeout,
  39. ConditionBlock condition);
  40. // Runs |action| if non-nil. Then, until either |condition| is true or |timeout|
  41. // expires, repetitively runs the current NSRunLoop and the current MessageLoop
  42. // (if |run_message_loop| is true). |condition| may be nil if there is no
  43. // condition to wait for; the NSRunLoop and current MessageLoop will be run run
  44. // until |timeout| expires. DCHECKs if |condition| is non-nil and |timeout|
  45. // expires before |condition| becomes true. If |timeout| is zero, a reasonable
  46. // default is used. Returns the time spent in the function.
  47. // DEPRECATED - Do not use in new code. http://crbug.com/784735
  48. TimeDelta TimeUntilCondition(ProceduralBlock action,
  49. ConditionBlock condition,
  50. bool run_message_loop,
  51. TimeDelta timeout);
  52. // Same as TimeUntilCondition, but doesn't run an action.
  53. // DEPRECATED - Do not use in new code. http://crbug.com/784735
  54. void WaitUntilCondition(ConditionBlock condition,
  55. bool run_message_loop,
  56. TimeDelta timeout);
  57. // DEPRECATED - Do not use in new code. http://crbug.com/784735
  58. void WaitUntilCondition(ConditionBlock condition);
  59. // Lets the run loop of the current thread process other messages
  60. // within the given maximum delay. This method may return before max_delay
  61. // elapsed.
  62. void SpinRunLoopWithMaxDelay(TimeDelta max_delay);
  63. // Lets the run loop of the current thread process other messages
  64. // within the given minimum delay. This method returns after |min_delay|
  65. // elapsed.
  66. void SpinRunLoopWithMinDelay(TimeDelta min_delay);
  67. } // namespace ios
  68. } // namespace test
  69. } // namespace base
  70. #endif // BASE_TEST_IOS_WAIT_UTIL_H_