Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1647)

Unified Diff: net/test/event_waiter.h

Issue 904313003: Implement utility-side host resolver Mojo client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-proxy-resolver
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/net.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/event_waiter.h
diff --git a/net/test/event_waiter.h b/net/test/event_waiter.h
new file mode 100644
index 0000000000000000000000000000000000000000..618b8ede462dfa19cc7851b7ca90a203927348b5
--- /dev/null
+++ b/net/test/event_waiter.h
@@ -0,0 +1,40 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_TEST_EVENT_WAITER_H_
+#define NET_TEST_EVENT_WAITER_H_
+
+#include "base/run_loop.h"
+
+namespace net {
+
+// Helper class to run a RunLoop until an expected event is reported.
+template <typename Event>
+class EventWaiter {
+ public:
+ // Runs a RunLoop until NotifyEvent() is called with |event|.
+ void WaitForEvent(Event event) {
+ expected_event_ = event;
+ base::RunLoop run_loop;
+ quit_closure_ = run_loop.QuitClosure();
+ run_loop.Run();
+ }
+
+ // Unblocks a WaitForEvent() call if it was called with |event|. Otherwise,
+ // has no effect.
+ void NotifyEvent(Event event) {
+ if (event == expected_event_ && !quit_closure_.is_null()) {
+ quit_closure_.Run();
+ quit_closure_.Reset();
+ }
+ }
+
+ private:
+ Event expected_event_;
+ base::Closure quit_closure_;
+};
+
+} // namespace net
+
+#endif // NET_TEST_EVENT_WAITER_H_
« no previous file with comments | « net/net.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698