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

Unified Diff: net/http/http_cache_unittest.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: address comments 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_cache_unittest.cc
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 868570b0fa609ba530cb6369f2bcc99c23f8b2ac..f7acbde0a6c1656569f443e18f46534038c962b6 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -18,9 +18,13 @@
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/strings/string_number_conversions.h"
#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 "base/trace_event/trace_event_argument.h"
#include "net/base/cache_type.h"
#include "net/base/elements_upload_data_stream.h"
#include "net/base/host_port_pair.h"
@@ -8353,4 +8357,45 @@ 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());
+
+ const base::trace_event::MemoryAllocatorDump* dump =
+ process_memory_dump->GetAllocatorDump("parent/http_cache");
+ ASSERT_NE(nullptr, dump);
+ std::unique_ptr<base::Value> raw_attrs =
+ dump->attributes_for_testing()->ToBaseValue();
+ base::DictionaryValue* attrs;
+ ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
+ base::DictionaryValue* size_attrs;
+ ASSERT_TRUE(attrs->GetDictionary(
+ base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
+ std::string size;
+ ASSERT_TRUE(size_attrs->GetString("value", &size));
+ int actual_size = 0;
+ ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
+ ASSERT_LT(0, actual_size);
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698