Chromium Code Reviews| Index: net/http/http_cache_unittest.cc |
| diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc |
| index 635c15ca98b101b35f2087019bb9f5f31303ac18..92d9d75a85e6e6fb2e2953abc4f37284a5f2c11b 100644 |
| --- a/net/http/http_cache_unittest.cc |
| +++ b/net/http/http_cache_unittest.cc |
| @@ -21,6 +21,8 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/test/simple_test_clock.h" |
| +#include "base/trace_event/memory_allocator_dump.h" |
| +#include "base/trace_event/process_memory_dump.h" |
| #include "net/base/cache_type.h" |
| #include "net/base/elements_upload_data_stream.h" |
| #include "net/base/host_port_pair.h" |
| @@ -8328,4 +8330,41 @@ TEST(HttpCache, CacheEntryStatusCantConditionalize) { |
| response_info.cache_entry_status); |
| } |
| +// Basic test to make sure HttpCache::DumpMemoryStats doesn't crash. |
| +TEST(HttpCache, DumpMemoryStats) { |
| + MockHttpCache cache; |
| + cache.FailConditionalizations(); |
| + RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
| + |
| + HttpResponseInfo response_info; |
| + RunTransactionTestWithResponseInfo(cache.http_cache(), |
| + kTypicalGET_Transaction, &response_info); |
| + |
| + EXPECT_FALSE(response_info.was_cached); |
| + EXPECT_TRUE(response_info.network_accessed); |
| + EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| + response_info.cache_entry_status); |
| + |
| + base::trace_event::MemoryDumpArgs dump_args = { |
| + base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
| + std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( |
| + new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
| + base::trace_event::MemoryAllocatorDump* parent_dump = |
| + process_memory_dump->CreateAllocatorDump("parent"); |
| + cache.http_cache()->DumpMemoryStats(process_memory_dump.get(), |
| + parent_dump->absolute_name()); |
| + |
| + // Whether HttpCache::DumpMemoryStats() is invoked. |
| + bool did_dump = false; |
| + const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& |
| + allocator_dumps = process_memory_dump->allocator_dumps(); |
| + for (const auto& pair : allocator_dumps) { |
| + const std::string& dump_name = pair.first; |
| + if (dump_name.find("http_cache") == std::string::npos) |
| + continue; |
| + did_dump = true; |
| + } |
| + EXPECT_TRUE(did_dump); |
|
jkarlin
2017/02/21 16:23:29
Can you add a simple check that the dump size is g
xunjieli
2017/02/21 19:44:14
Done.
|
| +} |
| + |
| } // namespace net |