1 // Copyright 2020 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_TEST_WAITABLE_EVENT_H_ 6 #define BASE_TEST_TEST_WAITABLE_EVENT_H_ 7 8 #include "base/synchronization/waitable_event.h" 9 #include "build/build_config.h" 10 11 #if BUILDFLAG(IS_WIN) 12 #include "base/win/scoped_handle.h" 13 #endif 14 15 namespace base { 16 17 // A WaitableEvent for use in tests, it has the same API as WaitableEvent with 18 // the following two distinctions: 19 // 1) ScopedAllowBaseSyncPrimitivesForTesting is not required to block on it. 20 // 2) It doesn't instantiate a ScopedBlockingCallWithBaseSyncPrimitives in 21 // Wait() (important in some //base tests that are thrown off when the 22 // WaitableEvents used to drive the test add additional ScopedBlockingCalls 23 // to the mix of monitored calls). 24 class TestWaitableEvent : public WaitableEvent { 25 public: 26 TestWaitableEvent(ResetPolicy reset_policy = ResetPolicy::MANUAL, 27 InitialState initial_state = InitialState::NOT_SIGNALED); 28 29 #if BUILDFLAG(IS_WIN) 30 explicit TestWaitableEvent(win::ScopedHandle event_handle); 31 #endif 32 }; 33 34 static_assert(sizeof(TestWaitableEvent) == sizeof(WaitableEvent), 35 "WaitableEvent is non-virtual, TestWaitableEvent must be usable " 36 "interchangeably."); 37 38 } // namespace base 39 40 #endif // BASE_TEST_TEST_WAITABLE_EVENT_H_ 41