1 // Copyright 2015 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.
5 #ifndef NET_TEST_EVENT_WAITER_H_
6 #define NET_TEST_EVENT_WAITER_H_
8 #include "base/run_loop.h"
12 // Helper class to run a RunLoop until an expected event is reported.
13 template <typename Event
>
16 // Runs a RunLoop until NotifyEvent() is called with |event|.
17 void WaitForEvent(Event event
) {
18 expected_event_
= event
;
19 base::RunLoop run_loop
;
20 quit_closure_
= run_loop
.QuitClosure();
24 // Unblocks a WaitForEvent() call if it was called with |event|. Otherwise,
26 void NotifyEvent(Event event
) {
27 if (event
== expected_event_
&& !quit_closure_
.is_null()) {
29 quit_closure_
.Reset();
34 Event expected_event_
;
35 base::Closure quit_closure_
;
40 #endif // NET_TEST_EVENT_WAITER_H_