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/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "net/test/embedded_test_server/embedded_test_server_connection_listener
.h" | 23 #include "net/test/embedded_test_server/embedded_test_server_connection_listener
.h" |
24 #include "net/test/embedded_test_server/http_request.h" | 24 #include "net/test/embedded_test_server/http_request.h" |
25 #include "net/test/embedded_test_server/http_response.h" | 25 #include "net/test/embedded_test_server/http_response.h" |
26 #include "net/test/embedded_test_server/request_handler_util.h" | 26 #include "net/test/embedded_test_server/request_handler_util.h" |
27 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
28 #include "net/url_request/url_fetcher_delegate.h" | 28 #include "net/url_request/url_fetcher_delegate.h" |
29 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 33 #if defined(USE_NSS_VERIFIER) |
34 #include "net/cert_net/nss_ocsp.h" | 34 #include "net/cert_net/nss_ocsp.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace net { | 37 namespace net { |
38 namespace test_server { | 38 namespace test_server { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Gets the content from the given URLFetcher. | 42 // Gets the content from the given URLFetcher. |
43 std::string GetContentFromFetcher(const URLFetcher& fetcher) { | 43 std::string GetContentFromFetcher(const URLFetcher& fetcher) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 : public testing::TestWithParam<EmbeddedTestServer::Type>, | 115 : public testing::TestWithParam<EmbeddedTestServer::Type>, |
116 public URLFetcherDelegate { | 116 public URLFetcherDelegate { |
117 public: | 117 public: |
118 EmbeddedTestServerTest() | 118 EmbeddedTestServerTest() |
119 : num_responses_received_(0), | 119 : num_responses_received_(0), |
120 num_responses_expected_(0), | 120 num_responses_expected_(0), |
121 io_thread_("io_thread") { | 121 io_thread_("io_thread") { |
122 } | 122 } |
123 | 123 |
124 void SetUp() override { | 124 void SetUp() override { |
125 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 125 #if defined(USE_NSS_VERIFIER) |
126 // This is needed so NSS's HTTP client functions are initialized on the | 126 // This is needed so NSS's HTTP client functions are initialized on the |
127 // right thread. These tests create SSLClientSockets on a different thread. | 127 // right thread. These tests create SSLClientSockets on a different thread. |
128 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See | 128 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See |
129 // https://crbug.com/539520. | 129 // https://crbug.com/539520. |
130 crypto::EnsureNSSInit(); | 130 crypto::EnsureNSSInit(); |
131 EnsureNSSHttpIOInit(); | 131 EnsureNSSHttpIOInit(); |
132 #endif | 132 #endif |
133 | 133 |
134 base::Thread::Options thread_options; | 134 base::Thread::Options thread_options; |
135 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 135 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
136 ASSERT_TRUE(io_thread_.StartWithOptions(thread_options)); | 136 ASSERT_TRUE(io_thread_.StartWithOptions(thread_options)); |
137 | 137 |
138 request_context_getter_ = | 138 request_context_getter_ = |
139 new TestURLRequestContextGetter(io_thread_.task_runner()); | 139 new TestURLRequestContextGetter(io_thread_.task_runner()); |
140 | 140 |
141 server_.reset(new EmbeddedTestServer(GetParam())); | 141 server_.reset(new EmbeddedTestServer(GetParam())); |
142 server_->SetConnectionListener(&connection_listener_); | 142 server_->SetConnectionListener(&connection_listener_); |
143 } | 143 } |
144 | 144 |
145 void TearDown() override { | 145 void TearDown() override { |
146 if (server_->Started()) | 146 if (server_->Started()) |
147 ASSERT_TRUE(server_->ShutdownAndWaitUntilComplete()); | 147 ASSERT_TRUE(server_->ShutdownAndWaitUntilComplete()); |
148 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 148 #if defined(USE_NSS_VERIFIER) |
149 ShutdownNSSHttpIO(); | 149 ShutdownNSSHttpIO(); |
150 #endif | 150 #endif |
151 } | 151 } |
152 | 152 |
153 // URLFetcherDelegate override. | 153 // URLFetcherDelegate override. |
154 void OnURLFetchComplete(const URLFetcher* source) override { | 154 void OnURLFetchComplete(const URLFetcher* source) override { |
155 ++num_responses_received_; | 155 ++num_responses_received_; |
156 if (num_responses_received_ == num_responses_expected_) | 156 if (num_responses_received_ == num_responses_expected_) |
157 base::MessageLoop::current()->QuitWhenIdle(); | 157 base::MessageLoop::current()->QuitWhenIdle(); |
158 } | 158 } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // Below test exercises EmbeddedTestServer's ability to cope with the situation | 489 // Below test exercises EmbeddedTestServer's ability to cope with the situation |
490 // where there is no MessageLoop available on the thread at EmbeddedTestServer | 490 // where there is no MessageLoop available on the thread at EmbeddedTestServer |
491 // initialization and/or destruction. | 491 // initialization and/or destruction. |
492 | 492 |
493 typedef std::tr1::tuple<bool, bool, EmbeddedTestServer::Type> | 493 typedef std::tr1::tuple<bool, bool, EmbeddedTestServer::Type> |
494 ThreadingTestParams; | 494 ThreadingTestParams; |
495 | 495 |
496 class EmbeddedTestServerThreadingTest | 496 class EmbeddedTestServerThreadingTest |
497 : public testing::TestWithParam<ThreadingTestParams> { | 497 : public testing::TestWithParam<ThreadingTestParams> { |
498 void SetUp() override { | 498 void SetUp() override { |
499 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 499 #if defined(USE_NSS_VERIFIER) |
500 // This is needed so NSS's HTTP client functions are initialized on the | 500 // This is needed so NSS's HTTP client functions are initialized on the |
501 // right thread. These tests create SSLClientSockets on a different thread. | 501 // right thread. These tests create SSLClientSockets on a different thread. |
502 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See | 502 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See |
503 // https://crbug.com/539520. | 503 // https://crbug.com/539520. |
504 crypto::EnsureNSSInit(); | 504 crypto::EnsureNSSInit(); |
505 EnsureNSSHttpIOInit(); | 505 EnsureNSSHttpIOInit(); |
506 #endif | 506 #endif |
507 } | 507 } |
508 | 508 |
509 void TearDown() override { | 509 void TearDown() override { |
510 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 510 #if defined(USE_NSS_VERIFIER) |
511 ShutdownNSSHttpIO(); | 511 ShutdownNSSHttpIO(); |
512 #endif | 512 #endif |
513 } | 513 } |
514 }; | 514 }; |
515 | 515 |
516 class EmbeddedTestServerThreadingTestDelegate | 516 class EmbeddedTestServerThreadingTestDelegate |
517 : public base::PlatformThread::Delegate, | 517 : public base::PlatformThread::Delegate, |
518 public URLFetcherDelegate { | 518 public URLFetcherDelegate { |
519 public: | 519 public: |
520 EmbeddedTestServerThreadingTestDelegate( | 520 EmbeddedTestServerThreadingTestDelegate( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 INSTANTIATE_TEST_CASE_P( | 591 INSTANTIATE_TEST_CASE_P( |
592 EmbeddedTestServerThreadingTestInstantiation, | 592 EmbeddedTestServerThreadingTestInstantiation, |
593 EmbeddedTestServerThreadingTest, | 593 EmbeddedTestServerThreadingTest, |
594 testing::Combine(testing::Bool(), | 594 testing::Combine(testing::Bool(), |
595 testing::Bool(), | 595 testing::Bool(), |
596 testing::Values(EmbeddedTestServer::TYPE_HTTP, | 596 testing::Values(EmbeddedTestServer::TYPE_HTTP, |
597 EmbeddedTestServer::TYPE_HTTPS))); | 597 EmbeddedTestServer::TYPE_HTTPS))); |
598 | 598 |
599 } // namespace test_server | 599 } // namespace test_server |
600 } // namespace net | 600 } // namespace net |
OLD | NEW |