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> |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); | 633 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); |
634 EXPECT_EQ(server_hash, observer.last_server_hash()); | 634 EXPECT_EQ(server_hash, observer.last_server_hash()); |
635 | 635 |
636 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); | 636 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); |
637 EXPECT_EQ(1, observer.dictionary_removed_notifications()); | 637 EXPECT_EQ(1, observer.dictionary_removed_notifications()); |
638 EXPECT_EQ(server_hash, observer.last_server_hash()); | 638 EXPECT_EQ(server_hash, observer.last_server_hash()); |
639 | 639 |
640 sdch_manager()->RemoveObserver(&observer); | 640 sdch_manager()->RemoveObserver(&observer); |
641 } | 641 } |
642 | 642 |
643 TEST_F(SdchManagerTest, DumpMemoryStats) { | 643 class SdchManagerMemoryDumpTest |
| 644 : public SdchManagerTest, |
| 645 public testing::WithParamInterface< |
| 646 base::trace_event::MemoryDumpLevelOfDetail> {}; |
| 647 |
| 648 INSTANTIATE_TEST_CASE_P( |
| 649 /* no prefix */, |
| 650 SdchManagerMemoryDumpTest, |
| 651 ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED, |
| 652 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND)); |
| 653 |
| 654 TEST_P(SdchManagerMemoryDumpTest, DumpMemoryStats) { |
644 MockSdchObserver observer; | 655 MockSdchObserver observer; |
645 sdch_manager()->AddObserver(&observer); | 656 sdch_manager()->AddObserver(&observer); |
646 | 657 |
647 std::string dictionary_domain("x.y.z.google.com"); | 658 std::string dictionary_domain("x.y.z.google.com"); |
648 GURL target_gurl("http://" + dictionary_domain); | 659 GURL target_gurl("http://" + dictionary_domain); |
649 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 660 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
650 std::string client_hash; | 661 std::string client_hash; |
651 std::string server_hash; | 662 std::string server_hash; |
652 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); | 663 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); |
653 EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl)); | 664 EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl)); |
654 EXPECT_EQ(1, observer.dictionary_added_notifications()); | 665 EXPECT_EQ(1, observer.dictionary_added_notifications()); |
655 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); | 666 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); |
656 EXPECT_EQ(server_hash, observer.last_server_hash()); | 667 EXPECT_EQ(server_hash, observer.last_server_hash()); |
657 | 668 |
658 base::trace_event::MemoryDumpArgs dump_args = { | 669 base::trace_event::MemoryDumpArgs dump_args = {GetParam()}; |
659 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | |
660 std::unique_ptr<base::trace_event::ProcessMemoryDump> pmd( | 670 std::unique_ptr<base::trace_event::ProcessMemoryDump> pmd( |
661 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | 671 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
662 | 672 |
663 base::trace_event::MemoryAllocatorDump* parent = | 673 base::trace_event::MemoryAllocatorDump* parent = |
664 pmd->CreateAllocatorDump("parent"); | 674 pmd->CreateAllocatorDump("net/url_request_context_0x123"); |
665 sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name()); | 675 sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name()); |
666 | 676 |
667 const base::trace_event::MemoryAllocatorDump* sub_dump = | 677 const base::trace_event::MemoryAllocatorDump* sub_dump = |
668 pmd->GetAllocatorDump("parent/sdch_manager"); | 678 pmd->GetAllocatorDump("net/url_request_context_0x123/sdch_manager"); |
669 ASSERT_NE(nullptr, sub_dump); | 679 ASSERT_NE(nullptr, sub_dump); |
670 const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump( | 680 const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump( |
671 base::StringPrintf("net/sdch_manager_%p", sdch_manager())); | 681 base::StringPrintf("net/sdch_manager_%p", sdch_manager())); |
672 std::unique_ptr<base::Value> raw_attrs = | 682 std::unique_ptr<base::Value> raw_attrs = |
673 dump->attributes_for_testing()->ToBaseValue(); | 683 dump->attributes_for_testing()->ToBaseValue(); |
674 base::DictionaryValue* attrs; | 684 base::DictionaryValue* attrs; |
675 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | 685 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
676 base::DictionaryValue* size_attrs; | 686 base::DictionaryValue* size_attrs; |
677 ASSERT_TRUE(attrs->GetDictionary( | 687 ASSERT_TRUE(attrs->GetDictionary( |
678 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); | 688 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); |
679 size_t offset = dictionary_text.find("\n\n") + 2; | 689 size_t offset = dictionary_text.find("\n\n") + 2; |
680 std::string size; | 690 std::string size; |
681 ASSERT_TRUE(size_attrs->GetString("value", &size)); | 691 ASSERT_TRUE(size_attrs->GetString("value", &size)); |
682 int actual_size; | 692 int actual_size; |
683 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); | 693 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); |
684 EXPECT_EQ(dictionary_text.size() - offset, static_cast<size_t>(actual_size)); | 694 EXPECT_EQ(dictionary_text.size() - offset, static_cast<size_t>(actual_size)); |
685 | 695 |
686 base::DictionaryValue* count_attrs; | 696 base::DictionaryValue* count_attrs; |
687 ASSERT_TRUE(attrs->GetDictionary( | 697 ASSERT_TRUE(attrs->GetDictionary( |
688 base::trace_event::MemoryAllocatorDump::kNameObjectCount, &count_attrs)); | 698 base::trace_event::MemoryAllocatorDump::kNameObjectCount, &count_attrs)); |
689 std::string count; | 699 std::string count; |
690 ASSERT_TRUE(count_attrs->GetString("value", &count)); | 700 ASSERT_TRUE(count_attrs->GetString("value", &count)); |
691 // One dictionary. | 701 // One dictionary. |
692 EXPECT_EQ("1", count); | 702 EXPECT_EQ("1", count); |
693 | 703 |
694 sdch_manager()->RemoveObserver(&observer); | 704 sdch_manager()->RemoveObserver(&observer); |
695 } | 705 } |
696 | 706 |
697 } // namespace net | 707 } // namespace net |
OLD | NEW |