Index: net/base/sdch_manager_unittest.cc |
diff --git a/net/base/sdch_manager_unittest.cc b/net/base/sdch_manager_unittest.cc |
index bfdb78fc7ca8c9002879fbfc11082781fa12f3bf..31162841b6c90495ed201818d9e1b042beee2e1a 100644 |
--- a/net/base/sdch_manager_unittest.cc |
+++ b/net/base/sdch_manager_unittest.cc |
@@ -11,8 +11,12 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/strings/string_number_conversions.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/sdch_observer.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
@@ -636,4 +640,58 @@ TEST_F(SdchManagerTest, AddRemoveNotifications) { |
sdch_manager()->RemoveObserver(&observer); |
} |
+TEST_F(SdchManagerTest, DumpMemoryStats) { |
+ MockSdchObserver observer; |
+ sdch_manager()->AddObserver(&observer); |
+ |
+ std::string dictionary_domain("x.y.z.google.com"); |
+ GURL target_gurl("http://" + dictionary_domain); |
+ std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
+ std::string client_hash; |
+ std::string server_hash; |
+ SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); |
+ EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl)); |
+ EXPECT_EQ(1, observer.dictionary_added_notifications()); |
+ EXPECT_EQ(target_gurl, observer.last_dictionary_url()); |
+ EXPECT_EQ(server_hash, observer.last_server_hash()); |
+ |
+ base::trace_event::MemoryDumpArgs dump_args = { |
+ base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
+ std::unique_ptr<base::trace_event::ProcessMemoryDump> pmd( |
+ new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
+ |
+ base::trace_event::MemoryAllocatorDump* parent = |
+ pmd->CreateAllocatorDump("parent"); |
+ sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name()); |
+ |
+ const base::trace_event::MemoryAllocatorDump* sub_dump = |
+ pmd->GetAllocatorDump("parent/sdch_manager"); |
+ ASSERT_NE(nullptr, sub_dump); |
+ const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump( |
+ base::StringPrintf("net/sdch_manager_%p", sdch_manager())); |
+ 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)); |
+ size_t offset = dictionary_text.find("\n\n") + 2; |
+ std::string size; |
+ ASSERT_TRUE(size_attrs->GetString("value", &size)); |
+ int actual_size; |
+ ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); |
+ EXPECT_EQ(dictionary_text.size() - offset, static_cast<size_t>(actual_size)); |
+ |
+ base::DictionaryValue* count_attrs; |
+ ASSERT_TRUE(attrs->GetDictionary( |
+ base::trace_event::MemoryAllocatorDump::kNameObjectCount, &count_attrs)); |
+ std::string count; |
+ ASSERT_TRUE(count_attrs->GetString("value", &count)); |
+ // One dictionary. |
+ EXPECT_EQ("1", count); |
+ |
+ sdch_manager()->RemoveObserver(&observer); |
+} |
+ |
} // namespace net |