OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/sdch_manager.h" | 5 #include "net/base/sdch_manager.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/test/simple_test_clock.h" | 15 #include "base/test/simple_test_clock.h" |
| 16 #include "base/trace_event/memory_allocator_dump.h" |
| 17 #include "base/trace_event/process_memory_dump.h" |
| 18 #include "base/trace_event/trace_event_argument.h" |
16 #include "net/base/sdch_observer.h" | 19 #include "net/base/sdch_observer.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "url/gurl.h" | 21 #include "url/gurl.h" |
19 | 22 |
20 namespace net { | 23 namespace net { |
21 | 24 |
22 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
23 // Provide sample data and compression results with a sample VCDIFF dictionary. | 26 // Provide sample data and compression results with a sample VCDIFF dictionary. |
24 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. | 27 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. |
25 static const char kTestVcdiffDictionary[] = "DictionaryFor" | 28 static const char kTestVcdiffDictionary[] = "DictionaryFor" |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); | 632 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); |
630 EXPECT_EQ(server_hash, observer.last_server_hash()); | 633 EXPECT_EQ(server_hash, observer.last_server_hash()); |
631 | 634 |
632 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); | 635 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); |
633 EXPECT_EQ(1, observer.dictionary_removed_notifications()); | 636 EXPECT_EQ(1, observer.dictionary_removed_notifications()); |
634 EXPECT_EQ(server_hash, observer.last_server_hash()); | 637 EXPECT_EQ(server_hash, observer.last_server_hash()); |
635 | 638 |
636 sdch_manager()->RemoveObserver(&observer); | 639 sdch_manager()->RemoveObserver(&observer); |
637 } | 640 } |
638 | 641 |
| 642 TEST_F(SdchManagerTest, DumpMemoryStats) { |
| 643 MockSdchObserver observer; |
| 644 sdch_manager()->AddObserver(&observer); |
| 645 |
| 646 std::string dictionary_domain("x.y.z.google.com"); |
| 647 GURL target_gurl("http://" + dictionary_domain); |
| 648 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 649 std::string client_hash; |
| 650 std::string server_hash; |
| 651 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 652 EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl)); |
| 653 EXPECT_EQ(1, observer.dictionary_added_notifications()); |
| 654 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); |
| 655 EXPECT_EQ(server_hash, observer.last_server_hash()); |
| 656 |
| 657 base::trace_event::MemoryDumpArgs dump_args = { |
| 658 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
| 659 std::unique_ptr<base::trace_event::ProcessMemoryDump> pmd( |
| 660 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
| 661 |
| 662 base::trace_event::MemoryAllocatorDump* parent = |
| 663 pmd->CreateAllocatorDump("parent"); |
| 664 sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name()); |
| 665 |
| 666 const base::trace_event::MemoryAllocatorDump* sub_dump = |
| 667 pmd->GetAllocatorDump("parent/sdch_manager"); |
| 668 ASSERT_NE(nullptr, sub_dump); |
| 669 const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump( |
| 670 base::StringPrintf("net/sdch_manager_%p", sdch_manager())); |
| 671 std::unique_ptr<base::Value> raw_attrs = |
| 672 dump->attributes_for_testing()->ToBaseValue(); |
| 673 base::DictionaryValue* attrs; |
| 674 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
| 675 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); |
| 676 base::DictionaryValue* count_attrs; |
| 677 ASSERT_TRUE(attrs->GetDictionary( |
| 678 base::trace_event::MemoryAllocatorDump::kNameObjectCount, &count_attrs)); |
| 679 std::string count; |
| 680 ASSERT_TRUE(count_attrs->GetString("value", &count)); |
| 681 // One dictionary. |
| 682 ASSERT_EQ("1", count); |
| 683 |
| 684 sdch_manager()->RemoveObserver(&observer); |
| 685 } |
| 686 |
639 } // namespace net | 687 } // namespace net |
OLD | NEW |