Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_TEST_TEST_TIMEOUTS_H_ | 5 #ifndef BASE_TEST_TEST_TIMEOUTS_H_ |
| 6 #define BASE_TEST_TEST_TIMEOUTS_H_ | 6 #define BASE_TEST_TEST_TIMEOUTS_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time.h" | |
| 11 | |
| 12 using base::TimeDelta; | |
|
brettw
2012/01/03 05:38:48
You can't do this in a header file.
| |
| 10 | 13 |
| 11 // Returns common timeouts to use in tests. Makes it possible to adjust | 14 // Returns common timeouts to use in tests. Makes it possible to adjust |
| 12 // the timeouts for different environments (like Valgrind). | 15 // the timeouts for different environments (like Valgrind). |
| 13 class TestTimeouts { | 16 class TestTimeouts { |
| 14 public: | 17 public: |
| 15 // Initializes the timeouts. Non thread-safe. Should be called exactly once | 18 // Initializes the timeouts. Non thread-safe. Should be called exactly once |
| 16 // by the test suite. | 19 // by the test suite. |
| 17 static void Initialize(); | 20 static void Initialize(); |
| 18 | 21 |
| 19 // Timeout for actions that are expected to finish "almost instantly". | 22 // Timeout for actions that are expected to finish "almost instantly". |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 36 DCHECK(initialized_); | 39 DCHECK(initialized_); |
| 37 return action_max_timeout_ms_; | 40 return action_max_timeout_ms_; |
| 38 } | 41 } |
| 39 | 42 |
| 40 // Timeout for a large test that may take a few minutes to run. | 43 // Timeout for a large test that may take a few minutes to run. |
| 41 static int large_test_timeout_ms() { | 44 static int large_test_timeout_ms() { |
| 42 DCHECK(initialized_); | 45 DCHECK(initialized_); |
| 43 return large_test_timeout_ms_; | 46 return large_test_timeout_ms_; |
| 44 } | 47 } |
| 45 | 48 |
| 49 // Timeout for actions that are expected to finish "almost instantly". | |
| 50 static TimeDelta tiny_timeout() { | |
| 51 DCHECK(initialized_); | |
| 52 return TimeDelta::FromMilliseconds(tiny_timeout_ms_); | |
| 53 } | |
| 54 | |
| 55 // Timeout to wait for something to happen. If you are not sure | |
| 56 // which timeout to use, this is the one you want. | |
| 57 static TimeDelta action_timeout() { | |
| 58 DCHECK(initialized_); | |
| 59 return TimeDelta::FromMilliseconds(action_timeout_ms_); | |
| 60 } | |
| 61 | |
| 62 // Timeout longer than the above, but still suitable to use | |
| 63 // multiple times in a single test. Use if the timeout above | |
| 64 // is not sufficient. | |
| 65 static TimeDelta action_max_timeout() { | |
| 66 DCHECK(initialized_); | |
| 67 return TimeDelta::FromMilliseconds(action_max_timeout_ms_); | |
| 68 } | |
| 69 | |
| 70 // Timeout for a large test that may take a few minutes to run. | |
| 71 static TimeDelta large_test_timeout() { | |
| 72 DCHECK(initialized_); | |
| 73 return TimeDelta::FromMilliseconds(large_test_timeout_ms_); | |
| 74 } | |
| 75 | |
| 46 private: | 76 private: |
| 47 static bool initialized_; | 77 static bool initialized_; |
| 48 | 78 |
| 49 static int tiny_timeout_ms_; | 79 static int tiny_timeout_ms_; |
| 50 static int action_timeout_ms_; | 80 static int action_timeout_ms_; |
| 51 static int action_max_timeout_ms_; | 81 static int action_max_timeout_ms_; |
| 52 static int large_test_timeout_ms_; | 82 static int large_test_timeout_ms_; |
| 53 | 83 |
| 54 DISALLOW_IMPLICIT_CONSTRUCTORS(TestTimeouts); | 84 DISALLOW_IMPLICIT_CONSTRUCTORS(TestTimeouts); |
| 55 }; | 85 }; |
| 56 | 86 |
| 57 #endif // BASE_TEST_TEST_TIMEOUTS_H_ | 87 #endif // BASE_TEST_TEST_TIMEOUTS_H_ |
| OLD | NEW |