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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server_unittest.cc

Issue 2602243002: Use TaskScheduler instead of WorkerPool in multi_threaded_cert_verifier.cc. (Closed)
Patch Set: self-review Created 3 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 unified diff | Download patch
OLDNEW
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/message_loop/message_loop.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "base/test/scoped_task_scheduler.h"
17 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
18 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
19 #include "crypto/nss_util.h" 21 #include "crypto/nss_util.h"
20 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
21 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
22 #include "net/log/net_log_source.h" 24 #include "net/log/net_log_source.h"
23 #include "net/log/test_net_log.h" 25 #include "net/log/test_net_log.h"
24 #include "net/socket/client_socket_factory.h" 26 #include "net/socket/client_socket_factory.h"
25 #include "net/socket/stream_socket.h" 27 #include "net/socket/stream_socket.h"
26 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h" 28 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 mutable base::Lock lock_; 118 mutable base::Lock lock_;
117 119
118 DISALLOW_COPY_AND_ASSIGN(TestConnectionListener); 120 DISALLOW_COPY_AND_ASSIGN(TestConnectionListener);
119 }; 121 };
120 122
121 class EmbeddedTestServerTest 123 class EmbeddedTestServerTest
122 : public testing::TestWithParam<EmbeddedTestServer::Type>, 124 : public testing::TestWithParam<EmbeddedTestServer::Type>,
123 public URLFetcherDelegate { 125 public URLFetcherDelegate {
124 public: 126 public:
125 EmbeddedTestServerTest() 127 EmbeddedTestServerTest()
126 : num_responses_received_(0), 128 : scoped_task_scheduler_(base::MessageLoop::current()),
129 num_responses_received_(0),
127 num_responses_expected_(0), 130 num_responses_expected_(0),
128 io_thread_("io_thread") { 131 io_thread_("io_thread") {}
129 }
130 132
131 void SetUp() override { 133 void SetUp() override {
132 #if defined(USE_NSS_CERTS) 134 #if defined(USE_NSS_CERTS)
133 // This is needed so NSS's HTTP client functions are initialized on the 135 // This is needed so NSS's HTTP client functions are initialized on the
134 // right thread. These tests create SSLClientSockets on a different thread. 136 // right thread. These tests create SSLClientSockets on a different thread.
135 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See 137 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See
136 // https://crbug.com/539520. 138 // https://crbug.com/539520.
137 crypto::EnsureNSSInit(); 139 crypto::EnsureNSSInit();
138 EnsureNSSHttpIOInit(); 140 EnsureNSSHttpIOInit();
139 #endif 141 #endif
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); 188 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
187 http_response->set_code(code); 189 http_response->set_code(code);
188 http_response->set_content(content); 190 http_response->set_content(content);
189 http_response->set_content_type(content_type); 191 http_response->set_content_type(content_type);
190 return std::move(http_response); 192 return std::move(http_response);
191 } 193 }
192 194
193 return nullptr; 195 return nullptr;
194 } 196 }
195 197
198 private:
199 base::test::ScopedTaskScheduler scoped_task_scheduler_;
200
196 protected: 201 protected:
197 int num_responses_received_; 202 int num_responses_received_;
198 int num_responses_expected_; 203 int num_responses_expected_;
199 std::string request_relative_url_; 204 std::string request_relative_url_;
200 GURL request_absolute_url_; 205 GURL request_absolute_url_;
201 base::Thread io_thread_; 206 base::Thread io_thread_;
202 scoped_refptr<TestURLRequestContextGetter> request_context_getter_; 207 scoped_refptr<TestURLRequestContextGetter> request_context_getter_;
203 TestConnectionListener connection_listener_; 208 TestConnectionListener connection_listener_;
204 std::unique_ptr<EmbeddedTestServer> server_; 209 std::unique_ptr<EmbeddedTestServer> server_;
205 }; 210 };
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 503
499 // Below test exercises EmbeddedTestServer's ability to cope with the situation 504 // Below test exercises EmbeddedTestServer's ability to cope with the situation
500 // where there is no MessageLoop available on the thread at EmbeddedTestServer 505 // where there is no MessageLoop available on the thread at EmbeddedTestServer
501 // initialization and/or destruction. 506 // initialization and/or destruction.
502 507
503 typedef std::tr1::tuple<bool, bool, EmbeddedTestServer::Type> 508 typedef std::tr1::tuple<bool, bool, EmbeddedTestServer::Type>
504 ThreadingTestParams; 509 ThreadingTestParams;
505 510
506 class EmbeddedTestServerThreadingTest 511 class EmbeddedTestServerThreadingTest
507 : public testing::TestWithParam<ThreadingTestParams> { 512 : public testing::TestWithParam<ThreadingTestParams> {
513 protected:
514 EmbeddedTestServerThreadingTest()
515 : scoped_task_scheduler_(base::MessageLoop::current()) {}
516
508 void SetUp() override { 517 void SetUp() override {
509 #if defined(USE_NSS_CERTS) 518 #if defined(USE_NSS_CERTS)
510 // This is needed so NSS's HTTP client functions are initialized on the 519 // This is needed so NSS's HTTP client functions are initialized on the
511 // right thread. These tests create SSLClientSockets on a different thread. 520 // right thread. These tests create SSLClientSockets on a different thread.
512 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See 521 // TODO(davidben): Initialization can't be deferred to SSLClientSocket. See
513 // https://crbug.com/539520. 522 // https://crbug.com/539520.
514 crypto::EnsureNSSInit(); 523 crypto::EnsureNSSInit();
515 EnsureNSSHttpIOInit(); 524 EnsureNSSHttpIOInit();
516 #endif 525 #endif
517 } 526 }
518 527
519 void TearDown() override { 528 void TearDown() override {
520 #if defined(USE_NSS_CERTS) 529 #if defined(USE_NSS_CERTS)
521 ShutdownNSSHttpIO(); 530 ShutdownNSSHttpIO();
522 #endif 531 #endif
523 } 532 }
533
534 private:
535 base::test::ScopedTaskScheduler scoped_task_scheduler_;
524 }; 536 };
525 537
526 class EmbeddedTestServerThreadingTestDelegate 538 class EmbeddedTestServerThreadingTestDelegate
527 : public base::PlatformThread::Delegate, 539 : public base::PlatformThread::Delegate,
528 public URLFetcherDelegate { 540 public URLFetcherDelegate {
529 public: 541 public:
530 EmbeddedTestServerThreadingTestDelegate( 542 EmbeddedTestServerThreadingTestDelegate(
531 bool message_loop_present_on_initialize, 543 bool message_loop_present_on_initialize,
532 bool message_loop_present_on_shutdown, 544 bool message_loop_present_on_shutdown,
533 EmbeddedTestServer::Type type) 545 EmbeddedTestServer::Type type)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 INSTANTIATE_TEST_CASE_P( 613 INSTANTIATE_TEST_CASE_P(
602 EmbeddedTestServerThreadingTestInstantiation, 614 EmbeddedTestServerThreadingTestInstantiation,
603 EmbeddedTestServerThreadingTest, 615 EmbeddedTestServerThreadingTest,
604 testing::Combine(testing::Bool(), 616 testing::Combine(testing::Bool(),
605 testing::Bool(), 617 testing::Bool(),
606 testing::Values(EmbeddedTestServer::TYPE_HTTP, 618 testing::Values(EmbeddedTestServer::TYPE_HTTP,
607 EmbeddedTestServer::TYPE_HTTPS))); 619 EmbeddedTestServer::TYPE_HTTPS)));
608 620
609 } // namespace test_server 621 } // namespace test_server
610 } // namespace net 622 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698