OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef NET_TEST_EVENT_WAITER_H_ |
| 6 #define NET_TEST_EVENT_WAITER_H_ |
| 7 |
| 8 #include "base/run_loop.h" |
| 9 |
| 10 namespace net { |
| 11 |
| 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(); |
| 22 } |
| 23 |
| 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(); |
| 30 } |
| 31 } |
| 32 |
| 33 private: |
| 34 Event expected_event_; |
| 35 base::Closure quit_closure_; |
| 36 }; |
| 37 |
| 38 } // namespace net |
| 39 |
| 40 #endif // NET_TEST_EVENT_WAITER_H_ |
OLD | NEW |