OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_EMBEDDED_TEST_SERVER_SIMPLE_CONNECTION_LISTENER_H_ |
| 6 #define NET_TEST_EMBEDDED_TEST_SERVER_SIMPLE_CONNECTION_LISTENER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "net/test/embedded_test_server/embedded_test_server_connection_listener
.h" |
| 12 |
| 13 namespace base { |
| 14 class SequencedTaskRunner; |
| 15 } |
| 16 |
| 17 namespace net { |
| 18 |
| 19 class StreamSocket; |
| 20 |
| 21 namespace test_server { |
| 22 |
| 23 // Waits for a specified number of connection attempts to be seen. |
| 24 class SimpleConnectionListener : public EmbeddedTestServerConnectionListener { |
| 25 public: |
| 26 enum AllowAdditionalConnections { |
| 27 // Add an expect failure if more than the specified number of connections |
| 28 // are seen. |
| 29 FAIL_ON_ADDITIONAL_CONNECTIONS, |
| 30 // Silently ignores extra connection attempts. |
| 31 ALLOW_ADDITIONAL_CONNECTIONS |
| 32 }; |
| 33 |
| 34 // A connection listener that waits for the specified number of total |
| 35 // connections when WaitForConnections() is called. Must be created on a |
| 36 // thread with a SingleThreadedTaskRunner. |
| 37 SimpleConnectionListener( |
| 38 int expected_connections, |
| 39 AllowAdditionalConnections allow_additional_connections); |
| 40 |
| 41 // Must be torn down only after the EmbeddedTestServer it's attached to is |
| 42 // shut down. |
| 43 ~SimpleConnectionListener() override; |
| 44 |
| 45 void AcceptedSocket(const StreamSocket& socket) override; |
| 46 void ReadFromSocket(const StreamSocket& socket, int rv) override; |
| 47 |
| 48 // Wait until the expected number of connections have been seen. |
| 49 void WaitForConnections(); |
| 50 |
| 51 private: |
| 52 int seen_connections_ = 0; |
| 53 |
| 54 const int expected_connections_; |
| 55 const AllowAdditionalConnections allow_additional_connections_; |
| 56 |
| 57 const scoped_refptr<base::SequencedTaskRunner> run_loop_task_runner_; |
| 58 |
| 59 base::RunLoop run_loop_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SimpleConnectionListener); |
| 62 }; |
| 63 |
| 64 } // namespace test_server |
| 65 } // namespace net |
| 66 |
| 67 #endif // NET_TEST_EMBEDDED_TEST_SERVER_SIMPLE_CONNECTION_LISTENER_H_ |
OLD | NEW |