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

Side by Side Diff: net/ssl/ssl_client_session_cache_unittest.cc

Issue 2541093003: Instrument SSL sockets using MemoryDumpProvider (Closed)
Patch Set: Fix flaky test Created 4 years 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
« no previous file with comments | « net/ssl/ssl_client_session_cache.cc ('k') | net/url_request/url_request_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ssl/ssl_client_session_cache.h" 5 #include "net/ssl/ssl_client_session_cache.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/trace_event/memory_allocator_dump.h"
13 #include "base/trace_event/process_memory_dump.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/boringssl/src/include/openssl/ssl.h" 15 #include "third_party/boringssl/src/include/openssl/ssl.h"
14 16
15 namespace net { 17 namespace net {
16 18
17 namespace { 19 namespace {
18 20
19 std::unique_ptr<base::SimpleTestClock> MakeTestClock() { 21 std::unique_ptr<base::SimpleTestClock> MakeTestClock() {
20 std::unique_ptr<base::SimpleTestClock> clock = 22 std::unique_ptr<base::SimpleTestClock> clock =
21 base::MakeUnique<base::SimpleTestClock>(); 23 base::MakeUnique<base::SimpleTestClock>();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 EXPECT_TRUE(cache.Lookup("key2")); 294 EXPECT_TRUE(cache.Lookup("key2"));
293 EXPECT_EQ(1u, cache.size()); 295 EXPECT_EQ(1u, cache.size());
294 296
295 // Fire notification that will flush everything. 297 // Fire notification that will flush everything.
296 base::MemoryPressureListener::NotifyMemoryPressure( 298 base::MemoryPressureListener::NotifyMemoryPressure(
297 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); 299 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
298 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
299 EXPECT_EQ(0u, cache.size()); 301 EXPECT_EQ(0u, cache.size());
300 } 302 }
301 303
304 // Basic test for dumping memory stats.
305 TEST(SSLClientSessionCacheTest, TestDumpMemoryStats) {
306 SSLClientSessionCache::Config config;
307 SSLClientSessionCache cache(config);
308
309 bssl::UniquePtr<SSL_SESSION> session1(SSL_SESSION_new());
310 bssl::UniquePtr<SSL_SESSION> session2(SSL_SESSION_new());
311 bssl::UniquePtr<SSL_SESSION> session3(SSL_SESSION_new());
312
313 // Insert three entries.
314 cache.Insert("key1", session1.get());
315 cache.Insert("key2", session2.get());
316 cache.Insert("key3", session3.get());
317 EXPECT_EQ(session1.get(), cache.Lookup("key1").get());
318 EXPECT_EQ(session2.get(), cache.Lookup("key2").get());
319 EXPECT_EQ(session3.get(), cache.Lookup("key3").get());
320 EXPECT_EQ(3u, cache.size());
321
322 base::trace_event::MemoryDumpArgs dump_args = {
323 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
324 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
325 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
326 cache.DumpMemoryStats(process_memory_dump.get());
327
328 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
329 allocator_dumps = process_memory_dump->allocator_dumps();
330
331 size_t num_entry_dump = 0;
332 for (const auto& pair : allocator_dumps) {
333 const std::string& dump_name = pair.first;
334 if (dump_name.find("net/ssl_session_cache/entry") != std::string::npos)
335 num_entry_dump++;
336 }
337 ASSERT_EQ(3u, num_entry_dump);
338 }
339
302 } // namespace net 340 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/ssl_client_session_cache.cc ('k') | net/url_request/url_request_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698