Chromium Code Reviews| 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" | |
| 23 #include "base/trace_event/trace_event_argument.h" | |
| 24 #include "base/values.h" | |
| 21 #include "net/base/address_list.h" | 25 #include "net/base/address_list.h" |
| 22 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 23 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 24 #include "net/base/test_completion_callback.h" | 28 #include "net/base/test_completion_callback.h" |
| 25 #include "net/cert/asn1_util.h" | 29 #include "net/cert/asn1_util.h" |
| 26 #include "net/cert/ct_policy_enforcer.h" | 30 #include "net/cert/ct_policy_enforcer.h" |
| 27 #include "net/cert/ct_policy_status.h" | 31 #include "net/cert/ct_policy_status.h" |
| 28 #include "net/cert/ct_verifier.h" | 32 #include "net/cert/ct_verifier.h" |
| 29 #include "net/cert/mock_cert_verifier.h" | 33 #include "net/cert/mock_cert_verifier.h" |
| 30 #include "net/cert/signed_certificate_timestamp_and_status.h" | 34 #include "net/cert/signed_certificate_timestamp_and_status.h" |
| (...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3667 | 3671 |
| 3668 // Replace it with an alert. | 3672 // Replace it with an alert. |
| 3669 raw_transport->ReplaceReadResult( | 3673 raw_transport->ReplaceReadResult( |
| 3670 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); | 3674 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); |
| 3671 raw_transport->UnblockReadResult(); | 3675 raw_transport->UnblockReadResult(); |
| 3672 | 3676 |
| 3673 rv = callback.GetResult(rv); | 3677 rv = callback.GetResult(rv); |
| 3674 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); | 3678 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); |
| 3675 } | 3679 } |
| 3676 | 3680 |
| 3681 // Basic test for dumping memory stats. | |
| 3682 TEST_F(SSLClientSocketTest, DumpMemoryStats) { | |
| 3683 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | |
| 3684 | |
| 3685 int rv; | |
| 3686 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); | |
| 3687 EXPECT_THAT(rv, IsOk()); | |
| 3688 | |
| 3689 base::trace_event::MemoryDumpArgs dump_args = { | |
| 3690 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | |
| 3691 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | |
| 3692 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | |
| 3693 base::trace_event::MemoryAllocatorDump* parent_dump1 = | |
| 3694 process_memory_dump->CreateAllocatorDump("parent1"); | |
| 3695 sock_->DumpMemoryStats(process_memory_dump.get(), | |
| 3696 parent_dump1->absolute_name()); | |
| 3697 | |
| 3698 // Write the request. | |
| 3699 std::string request_text = "GET / HTTP/1.1\r\n\r\n"; | |
| 3700 scoped_refptr<IOBuffer> request_buffer(new StringIOBuffer(request_text)); | |
| 3701 TestCompletionCallback write_callback; | |
| 3702 rv = write_callback.GetResult(sock_->Write( | |
| 3703 request_buffer.get(), request_text.size(), write_callback.callback())); | |
| 3704 EXPECT_EQ(static_cast<int>(request_text.size()), rv); | |
| 3705 | |
| 3706 // Read the response. | |
| 3707 TestCompletionCallback read_callback; | |
| 3708 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | |
| 3709 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); | |
| 3710 rv = read_callback.WaitForResult(); | |
| 3711 EXPECT_GT(rv, 0); | |
| 3712 | |
| 3713 // Dump memory again and check that |buffer_size| should contain read buffer. | |
| 3714 base::trace_event::MemoryAllocatorDump* parent_dump3 = | |
| 3715 process_memory_dump->CreateAllocatorDump("parent2"); | |
| 3716 sock_->DumpMemoryStats(process_memory_dump.get(), | |
| 3717 parent_dump3->absolute_name()); | |
| 3718 | |
| 3719 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | |
| 3720 allocator_dumps = process_memory_dump->allocator_dumps(); | |
| 3721 bool did_dump[] = {false, false}; | |
| 3722 // Checks that there are three dumps because DumpMemoryStats() is invoked | |
| 3723 // before writing the request, before reading the response and after reading | |
| 3724 // the response. | |
| 3725 for (const auto& pair : allocator_dumps) { | |
| 3726 const std::string& dump_name = pair.first; | |
| 3727 if (dump_name.find("ssl_socket") == std::string::npos) | |
| 3728 return; | |
| 3729 std::unique_ptr<base::Value> raw_attrs = | |
| 3730 pair.second->attributes_for_testing()->ToBaseValue(); | |
| 3731 base::DictionaryValue* attrs; | |
| 3732 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | |
| 3733 base::DictionaryValue* buffer_size_attrs; | |
| 3734 ASSERT_TRUE(attrs->GetDictionary("buffer_size", &buffer_size_attrs)); | |
| 3735 std::string buffer_size; | |
| 3736 ASSERT_TRUE(buffer_size_attrs->GetString("value", &buffer_size)); | |
| 3737 ASSERT_TRUE(attrs->HasKey("serialized_cert_size")); | |
| 3738 ASSERT_TRUE(attrs->HasKey("serialized_cert_count")); | |
| 3739 if (dump_name.find("parent1/ssl_socket") != std::string::npos) { | |
| 3740 did_dump[0] = true; | |
| 3741 ASSERT_EQ("0", buffer_size); | |
| 3742 } | |
| 3743 if (dump_name.find("parent2/ssl_socket") != std::string::npos) { | |
| 3744 did_dump[1] = true; | |
| 3745 // Buffer size should take into account the read buffer size. | |
|
davidben
2016/12/07 19:42:58
Perhaps:
// The buffers should be released if the
xunjieli
2016/12/07 20:32:25
But in this case, the buffer size is not equals to
| |
| 3746 ASSERT_NE("0", buffer_size); | |
| 3747 } | |
| 3748 } | |
| 3749 EXPECT_THAT(did_dump, testing::ElementsAre(true, true)); | |
| 3750 } | |
| 3751 | |
| 3677 } // namespace net | 3752 } // namespace net |
| OLD | NEW |