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