OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/test/embedded_test_server/embedded_test_server.h" | 5 #include "net/test/embedded_test_server/embedded_test_server.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "crypto/nss_util.h" | 18 #include "crypto/nss_util.h" |
19 #include "net/base/test_completion_callback.h" | 19 #include "net/base/test_completion_callback.h" |
20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
21 #include "net/log/test_net_log.h" | 21 #include "net/log/test_net_log.h" |
22 #include "net/socket/client_socket_factory.h" | 22 #include "net/socket/client_socket_factory.h" |
23 #include "net/socket/stream_socket.h" | 23 #include "net/socket/stream_socket.h" |
24 #include "net/test/embedded_test_server/embedded_test_server_connection_listener
.h" | 24 #include "net/test/embedded_test_server/embedded_test_server_connection_listener
.h" |
25 #include "net/test/embedded_test_server/http_request.h" | 25 #include "net/test/embedded_test_server/http_request.h" |
26 #include "net/test/embedded_test_server/http_response.h" | 26 #include "net/test/embedded_test_server/http_response.h" |
27 #include "net/test/embedded_test_server/request_handler_util.h" | 27 #include "net/test/embedded_test_server/request_handler_util.h" |
| 28 #include "net/test/gtest_util.h" |
28 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
29 #include "net/url_request/url_fetcher_delegate.h" | 30 #include "net/url_request/url_fetcher_delegate.h" |
30 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
31 #include "net/url_request/url_request_test_util.h" | 32 #include "net/url_request/url_request_test_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
33 | 35 |
34 #if defined(USE_NSS_CERTS) | 36 #if defined(USE_NSS_CERTS) |
35 #include "net/cert_net/nss_ocsp.h" | 37 #include "net/cert_net/nss_ocsp.h" |
36 #endif | 38 #endif |
37 | 39 |
| 40 using net::test::IsOk; |
| 41 |
38 namespace net { | 42 namespace net { |
39 namespace test_server { | 43 namespace test_server { |
40 | 44 |
41 namespace { | 45 namespace { |
42 | 46 |
43 // Gets the content from the given URLFetcher. | 47 // Gets the content from the given URLFetcher. |
44 std::string GetContentFromFetcher(const URLFetcher& fetcher) { | 48 std::string GetContentFromFetcher(const URLFetcher& fetcher) { |
45 std::string result; | 49 std::string result; |
46 const bool success = fetcher.GetResponseAsString(&result); | 50 const bool success = fetcher.GetResponseAsString(&result); |
47 EXPECT_TRUE(success); | 51 EXPECT_TRUE(success); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 ASSERT_TRUE(server_->Start()); | 298 ASSERT_TRUE(server_->Start()); |
295 | 299 |
296 TestNetLog net_log; | 300 TestNetLog net_log; |
297 net::AddressList address_list; | 301 net::AddressList address_list; |
298 EXPECT_TRUE(server_->GetAddressList(&address_list)); | 302 EXPECT_TRUE(server_->GetAddressList(&address_list)); |
299 | 303 |
300 std::unique_ptr<StreamSocket> socket = | 304 std::unique_ptr<StreamSocket> socket = |
301 ClientSocketFactory::GetDefaultFactory()->CreateTransportClientSocket( | 305 ClientSocketFactory::GetDefaultFactory()->CreateTransportClientSocket( |
302 address_list, NULL, &net_log, NetLog::Source()); | 306 address_list, NULL, &net_log, NetLog::Source()); |
303 TestCompletionCallback callback; | 307 TestCompletionCallback callback; |
304 ASSERT_EQ(OK, callback.GetResult(socket->Connect(callback.callback()))); | 308 ASSERT_THAT(callback.GetResult(socket->Connect(callback.callback())), IsOk()); |
305 | 309 |
306 connection_listener_.WaitUntilFirstConnectionAccepted(); | 310 connection_listener_.WaitUntilFirstConnectionAccepted(); |
307 | 311 |
308 EXPECT_EQ(1u, connection_listener_.SocketAcceptedCount()); | 312 EXPECT_EQ(1u, connection_listener_.SocketAcceptedCount()); |
309 EXPECT_FALSE(connection_listener_.DidReadFromSocket()); | 313 EXPECT_FALSE(connection_listener_.DidReadFromSocket()); |
310 } | 314 } |
311 | 315 |
312 TEST_P(EmbeddedTestServerTest, ConnectionListenerRead) { | 316 TEST_P(EmbeddedTestServerTest, ConnectionListenerRead) { |
313 ASSERT_TRUE(server_->Start()); | 317 ASSERT_TRUE(server_->Start()); |
314 | 318 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 INSTANTIATE_TEST_CASE_P( | 597 INSTANTIATE_TEST_CASE_P( |
594 EmbeddedTestServerThreadingTestInstantiation, | 598 EmbeddedTestServerThreadingTestInstantiation, |
595 EmbeddedTestServerThreadingTest, | 599 EmbeddedTestServerThreadingTest, |
596 testing::Combine(testing::Bool(), | 600 testing::Combine(testing::Bool(), |
597 testing::Bool(), | 601 testing::Bool(), |
598 testing::Values(EmbeddedTestServer::TYPE_HTTP, | 602 testing::Values(EmbeddedTestServer::TYPE_HTTP, |
599 EmbeddedTestServer::TYPE_HTTPS))); | 603 EmbeddedTestServer::TYPE_HTTPS))); |
600 | 604 |
601 } // namespace test_server | 605 } // namespace test_server |
602 } // namespace net | 606 } // namespace net |
OLD | NEW |