OLD | NEW |
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" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 EXPECT_TRUE(cache.Lookup("key2", nullptr)); | 347 EXPECT_TRUE(cache.Lookup("key2", nullptr)); |
348 EXPECT_EQ(1u, cache.size()); | 348 EXPECT_EQ(1u, cache.size()); |
349 | 349 |
350 // Fire notification that will flush everything. | 350 // Fire notification that will flush everything. |
351 base::MemoryPressureListener::NotifyMemoryPressure( | 351 base::MemoryPressureListener::NotifyMemoryPressure( |
352 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 352 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
353 base::RunLoop().RunUntilIdle(); | 353 base::RunLoop().RunUntilIdle(); |
354 EXPECT_EQ(0u, cache.size()); | 354 EXPECT_EQ(0u, cache.size()); |
355 } | 355 } |
356 | 356 |
| 357 class SSLClientSessionCacheMemoryDumpTest |
| 358 : public SSLClientSessionCacheTest, |
| 359 public testing::WithParamInterface< |
| 360 base::trace_event::MemoryDumpLevelOfDetail> {}; |
| 361 |
| 362 INSTANTIATE_TEST_CASE_P( |
| 363 /* no prefix */, |
| 364 SSLClientSessionCacheMemoryDumpTest, |
| 365 ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED, |
| 366 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND)); |
| 367 |
357 // Basic test for dumping memory stats. | 368 // Basic test for dumping memory stats. |
358 TEST_F(SSLClientSessionCacheTest, TestDumpMemoryStats) { | 369 TEST_P(SSLClientSessionCacheMemoryDumpTest, TestDumpMemoryStats) { |
359 SSLClientSessionCache::Config config; | 370 SSLClientSessionCache::Config config; |
360 SSLClientSessionCache cache(config); | 371 SSLClientSessionCache cache(config); |
361 | 372 |
362 bssl::UniquePtr<SSL_SESSION> session1 = NewSSLSession(); | 373 bssl::UniquePtr<SSL_SESSION> session1 = NewSSLSession(); |
363 bssl::UniquePtr<SSL_SESSION> session2 = NewSSLSession(); | 374 bssl::UniquePtr<SSL_SESSION> session2 = NewSSLSession(); |
364 bssl::UniquePtr<SSL_SESSION> session3 = NewSSLSession(); | 375 bssl::UniquePtr<SSL_SESSION> session3 = NewSSLSession(); |
365 | 376 |
366 // Insert three entries. | 377 // Insert three entries. |
367 cache.Insert("key1", session1.get()); | 378 cache.Insert("key1", session1.get()); |
368 cache.Insert("key2", session2.get()); | 379 cache.Insert("key2", session2.get()); |
369 cache.Insert("key3", session3.get()); | 380 cache.Insert("key3", session3.get()); |
370 EXPECT_EQ(session1.get(), cache.Lookup("key1", nullptr).get()); | 381 EXPECT_EQ(session1.get(), cache.Lookup("key1", nullptr).get()); |
371 EXPECT_EQ(session2.get(), cache.Lookup("key2", nullptr).get()); | 382 EXPECT_EQ(session2.get(), cache.Lookup("key2", nullptr).get()); |
372 EXPECT_EQ(session3.get(), cache.Lookup("key3", nullptr).get()); | 383 EXPECT_EQ(session3.get(), cache.Lookup("key3", nullptr).get()); |
373 EXPECT_EQ(3u, cache.size()); | 384 EXPECT_EQ(3u, cache.size()); |
374 | 385 |
375 base::trace_event::MemoryDumpArgs dump_args = { | 386 base::trace_event::MemoryDumpArgs dump_args = {GetParam()}; |
376 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | |
377 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | 387 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( |
378 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | 388 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
379 cache.DumpMemoryStats(process_memory_dump.get()); | 389 cache.DumpMemoryStats(process_memory_dump.get()); |
380 | 390 |
381 const base::trace_event::MemoryAllocatorDump* dump = | 391 const base::trace_event::MemoryAllocatorDump* dump = |
382 process_memory_dump->GetAllocatorDump("net/ssl_session_cache"); | 392 process_memory_dump->GetAllocatorDump("net/ssl_session_cache"); |
383 ASSERT_NE(nullptr, dump); | 393 ASSERT_NE(nullptr, dump); |
384 std::unique_ptr<base::Value> raw_attrs = | 394 std::unique_ptr<base::Value> raw_attrs = |
385 dump->attributes_for_testing()->ToBaseValue(); | 395 dump->attributes_for_testing()->ToBaseValue(); |
386 base::DictionaryValue* attrs; | 396 base::DictionaryValue* attrs; |
387 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | 397 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
388 ASSERT_TRUE(attrs->HasKey("cert_count")); | 398 ASSERT_TRUE(attrs->HasKey("cert_count")); |
389 ASSERT_TRUE(attrs->HasKey("cert_size")); | 399 ASSERT_TRUE(attrs->HasKey("cert_size")); |
390 ASSERT_TRUE(attrs->HasKey("undeduped_cert_size")); | 400 ASSERT_TRUE(attrs->HasKey("undeduped_cert_size")); |
391 ASSERT_TRUE(attrs->HasKey("undeduped_cert_count")); | 401 ASSERT_TRUE(attrs->HasKey("undeduped_cert_count")); |
392 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); | 402 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); |
393 } | 403 } |
394 | 404 |
395 } // namespace net | 405 } // namespace net |
OLD | NEW |