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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/trace_event/memory_allocator_dump.h" | |
22 #include "base/trace_event/process_memory_dump.h" | |
21 #include "net/base/address_list.h" | 23 #include "net/base/address_list.h" |
22 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
23 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
24 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
25 #include "net/cert/asn1_util.h" | 27 #include "net/cert/asn1_util.h" |
26 #include "net/cert/ct_policy_enforcer.h" | 28 #include "net/cert/ct_policy_enforcer.h" |
27 #include "net/cert/ct_policy_status.h" | 29 #include "net/cert/ct_policy_status.h" |
28 #include "net/cert/ct_verifier.h" | 30 #include "net/cert/ct_verifier.h" |
29 #include "net/cert/mock_cert_verifier.h" | 31 #include "net/cert/mock_cert_verifier.h" |
30 #include "net/cert/signed_certificate_timestamp_and_status.h" | 32 #include "net/cert/signed_certificate_timestamp_and_status.h" |
(...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3667 | 3669 |
3668 // Replace it with an alert. | 3670 // Replace it with an alert. |
3669 raw_transport->ReplaceReadResult( | 3671 raw_transport->ReplaceReadResult( |
3670 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); | 3672 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); |
3671 raw_transport->UnblockReadResult(); | 3673 raw_transport->UnblockReadResult(); |
3672 | 3674 |
3673 rv = callback.GetResult(rv); | 3675 rv = callback.GetResult(rv); |
3674 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); | 3676 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); |
3675 } | 3677 } |
3676 | 3678 |
3679 // Basic test for dumping memory stats. | |
3680 TEST_F(SSLClientSocketTest, DumpMemoryStats) { | |
3681 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | |
3682 | |
3683 int rv; | |
3684 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); | |
3685 EXPECT_THAT(rv, IsOk()); | |
3686 | |
3687 base::trace_event::MemoryDumpArgs dump_args = { | |
3688 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | |
3689 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | |
3690 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | |
3691 base::trace_event::MemoryAllocatorDump* parent_dump1 = | |
3692 process_memory_dump->CreateAllocatorDump("parent1"); | |
3693 sock_->DumpMemoryStats(process_memory_dump.get(), | |
3694 parent_dump1->absolute_name()); | |
3695 | |
3696 // Write the request. | |
3697 std::string request_text = "GET / HTTP/1.1\r\n\r\n"; | |
3698 scoped_refptr<IOBuffer> request_buffer(new StringIOBuffer(request_text)); | |
3699 TestCompletionCallback write_callback; | |
3700 rv = write_callback.GetResult(sock_->Write( | |
3701 request_buffer.get(), request_text.size(), write_callback.callback())); | |
3702 EXPECT_EQ(static_cast<int>(request_text.size()), rv); | |
3703 | |
3704 base::trace_event::MemoryAllocatorDump* parent_dump2 = | |
3705 process_memory_dump->CreateAllocatorDump("parent2"); | |
3706 sock_->DumpMemoryStats(process_memory_dump.get(), | |
3707 parent_dump2->absolute_name()); | |
davidben
2016/12/06 01:02:07
I'm not familiar with the MemoryAllocatorDump stuf
xunjieli
2016/12/06 18:36:08
Done. I tried to dump memory multiple times to be
| |
3708 | |
3709 // Read the response. | |
3710 TestCompletionCallback read_callback; | |
3711 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | |
3712 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); | |
3713 rv = read_callback.WaitForResult(); | |
3714 EXPECT_GT(rv, 0); | |
3715 | |
3716 base::trace_event::MemoryAllocatorDump* parent_dump3 = | |
3717 process_memory_dump->CreateAllocatorDump("parent3"); | |
3718 sock_->DumpMemoryStats(process_memory_dump.get(), | |
3719 parent_dump3->absolute_name()); | |
3720 | |
3721 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | |
3722 allocator_dumps = process_memory_dump->allocator_dumps(); | |
3723 bool did_dump[] = {false, false, false}; | |
3724 for (const auto& it : allocator_dumps) { | |
davidben
2016/12/06 01:02:07
Super nitpicky nitpick: it => pair? it is usually
xunjieli
2016/12/06 18:36:08
Done.
| |
3725 const std::string& dump_name = it.first; | |
3726 if (dump_name.find("parent1/ssl_socket") != std::string::npos) | |
3727 did_dump[0] = true; | |
3728 if (dump_name.find("parent2/ssl_socket") != std::string::npos) | |
3729 did_dump[1] = true; | |
3730 if (dump_name.find("parent3/ssl_socket") != std::string::npos) | |
3731 did_dump[2] = true; | |
3732 } | |
3733 EXPECT_THAT(did_dump, testing::ElementsAre(true, true, true)); | |
3734 } | |
3735 | |
3677 } // namespace net | 3736 } // namespace net |
OLD | NEW |