PlzNavigate: Improvements to RFHM commit logic.
[chromium-blink-merge.git] / net / test / event_waiter.h
blob618b8ede462dfa19cc7851b7ca90a203927348b5
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"
10 namespace net {
12 // Helper class to run a RunLoop until an expected event is reported.
13 template <typename Event>
14 class EventWaiter {
15 public:
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();
21 run_loop.Run();
24 // Unblocks a WaitForEvent() call if it was called with |event|. Otherwise,
25 // has no effect.
26 void NotifyEvent(Event event) {
27 if (event == expected_event_ && !quit_closure_.is_null()) {
28 quit_closure_.Run();
29 quit_closure_.Reset();
33 private:
34 Event expected_event_;
35 base::Closure quit_closure_;
38 } // namespace net
40 #endif // NET_TEST_EVENT_WAITER_H_