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

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

Issue 2699163002: Whitelist net/ MemoryDumpProvider (Closed)
Patch Set: 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 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 EXPECT_TRUE(cache.Lookup("key2", nullptr)); 334 EXPECT_TRUE(cache.Lookup("key2", nullptr));
335 EXPECT_EQ(1u, cache.size()); 335 EXPECT_EQ(1u, cache.size());
336 336
337 // Fire notification that will flush everything. 337 // Fire notification that will flush everything.
338 base::MemoryPressureListener::NotifyMemoryPressure( 338 base::MemoryPressureListener::NotifyMemoryPressure(
339 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); 339 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
340 base::RunLoop().RunUntilIdle(); 340 base::RunLoop().RunUntilIdle();
341 EXPECT_EQ(0u, cache.size()); 341 EXPECT_EQ(0u, cache.size());
342 } 342 }
343 343
344 class SSLClientSessionCacheMemoryDumpTest
345 : public testing::TestWithParam<
346 base::trace_event::MemoryDumpLevelOfDetail> {};
347
348 INSTANTIATE_TEST_CASE_P(
349 /* no prefix */,
350 SSLClientSessionCacheMemoryDumpTest,
351 ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED,
352 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND));
353
344 // Basic test for dumping memory stats. 354 // Basic test for dumping memory stats.
345 TEST(SSLClientSessionCacheTest, TestDumpMemoryStats) { 355 TEST_P(SSLClientSessionCacheMemoryDumpTest, TestDumpMemoryStats) {
346 SSLClientSessionCache::Config config; 356 SSLClientSessionCache::Config config;
347 SSLClientSessionCache cache(config); 357 SSLClientSessionCache cache(config);
348 358
349 bssl::UniquePtr<SSL_SESSION> session1(SSL_SESSION_new()); 359 bssl::UniquePtr<SSL_SESSION> session1(SSL_SESSION_new());
350 bssl::UniquePtr<SSL_SESSION> session2(SSL_SESSION_new()); 360 bssl::UniquePtr<SSL_SESSION> session2(SSL_SESSION_new());
351 bssl::UniquePtr<SSL_SESSION> session3(SSL_SESSION_new()); 361 bssl::UniquePtr<SSL_SESSION> session3(SSL_SESSION_new());
352 362
353 // Insert three entries. 363 // Insert three entries.
354 cache.Insert("key1", session1.get()); 364 cache.Insert("key1", session1.get());
355 cache.Insert("key2", session2.get()); 365 cache.Insert("key2", session2.get());
356 cache.Insert("key3", session3.get()); 366 cache.Insert("key3", session3.get());
357 EXPECT_EQ(session1.get(), cache.Lookup("key1", nullptr).get()); 367 EXPECT_EQ(session1.get(), cache.Lookup("key1", nullptr).get());
358 EXPECT_EQ(session2.get(), cache.Lookup("key2", nullptr).get()); 368 EXPECT_EQ(session2.get(), cache.Lookup("key2", nullptr).get());
359 EXPECT_EQ(session3.get(), cache.Lookup("key3", nullptr).get()); 369 EXPECT_EQ(session3.get(), cache.Lookup("key3", nullptr).get());
360 EXPECT_EQ(3u, cache.size()); 370 EXPECT_EQ(3u, cache.size());
361 371
362 base::trace_event::MemoryDumpArgs dump_args = { 372 base::trace_event::MemoryDumpArgs dump_args = {GetParam()};
363 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
364 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( 373 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
365 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); 374 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
366 cache.DumpMemoryStats(process_memory_dump.get()); 375 cache.DumpMemoryStats(process_memory_dump.get());
367 376
368 const base::trace_event::MemoryAllocatorDump* dump = 377 const base::trace_event::MemoryAllocatorDump* dump =
369 process_memory_dump->GetAllocatorDump("net/ssl_session_cache"); 378 process_memory_dump->GetAllocatorDump("net/ssl_session_cache");
370 ASSERT_NE(nullptr, dump); 379 ASSERT_NE(nullptr, dump);
371 std::unique_ptr<base::Value> raw_attrs = 380 std::unique_ptr<base::Value> raw_attrs =
372 dump->attributes_for_testing()->ToBaseValue(); 381 dump->attributes_for_testing()->ToBaseValue();
373 base::DictionaryValue* attrs; 382 base::DictionaryValue* attrs;
374 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 383 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
375 ASSERT_TRUE(attrs->HasKey("cert_count")); 384 ASSERT_TRUE(attrs->HasKey("cert_count"));
376 ASSERT_TRUE(attrs->HasKey("cert_size")); 385 ASSERT_TRUE(attrs->HasKey("cert_size"));
377 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); 386 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize));
378 } 387 }
379 388
380 } // namespace net 389 } // namespace net
OLDNEW
« net/base/sdch_manager_unittest.cc ('K') | « net/spdy/spdy_session_pool_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698