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

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 2541073003: Instrument SdchManager using MemoryDumpProvider (Closed)
Patch Set: Address Randy's comments Created 4 years 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 unified diff | Download patch
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/url_request/url_request_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/test/simple_test_clock.h" 16 #include "base/test/simple_test_clock.h"
17 #include "base/trace_event/memory_allocator_dump.h"
18 #include "base/trace_event/process_memory_dump.h"
19 #include "base/trace_event/trace_event_argument.h"
16 #include "net/base/sdch_observer.h" 20 #include "net/base/sdch_observer.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h" 22 #include "url/gurl.h"
19 23
20 namespace net { 24 namespace net {
21 25
22 //------------------------------------------------------------------------------ 26 //------------------------------------------------------------------------------
23 // Provide sample data and compression results with a sample VCDIFF dictionary. 27 // Provide sample data and compression results with a sample VCDIFF dictionary.
24 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary. 28 // Note an SDCH dictionary has extra meta-data before the VCDIFF dictionary.
25 static const char kTestVcdiffDictionary[] = "DictionaryFor" 29 static const char kTestVcdiffDictionary[] = "DictionaryFor"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 EXPECT_EQ(target_gurl, observer.last_dictionary_url()); 633 EXPECT_EQ(target_gurl, observer.last_dictionary_url());
630 EXPECT_EQ(server_hash, observer.last_server_hash()); 634 EXPECT_EQ(server_hash, observer.last_server_hash());
631 635
632 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash)); 636 EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash));
633 EXPECT_EQ(1, observer.dictionary_removed_notifications()); 637 EXPECT_EQ(1, observer.dictionary_removed_notifications());
634 EXPECT_EQ(server_hash, observer.last_server_hash()); 638 EXPECT_EQ(server_hash, observer.last_server_hash());
635 639
636 sdch_manager()->RemoveObserver(&observer); 640 sdch_manager()->RemoveObserver(&observer);
637 } 641 }
638 642
643 TEST_F(SdchManagerTest, DumpMemoryStats) {
644 MockSdchObserver observer;
645 sdch_manager()->AddObserver(&observer);
646
647 std::string dictionary_domain("x.y.z.google.com");
648 GURL target_gurl("http://" + dictionary_domain);
649 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
650 std::string client_hash;
651 std::string server_hash;
652 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash);
653 EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl));
654 EXPECT_EQ(1, observer.dictionary_added_notifications());
655 EXPECT_EQ(target_gurl, observer.last_dictionary_url());
656 EXPECT_EQ(server_hash, observer.last_server_hash());
657
658 base::trace_event::MemoryDumpArgs dump_args = {
659 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
660 std::unique_ptr<base::trace_event::ProcessMemoryDump> pmd(
661 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
662
663 base::trace_event::MemoryAllocatorDump* parent =
664 pmd->CreateAllocatorDump("parent");
665 sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name());
666
667 const base::trace_event::MemoryAllocatorDump* sub_dump =
668 pmd->GetAllocatorDump("parent/sdch_manager");
669 ASSERT_NE(nullptr, sub_dump);
670 const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump(
671 base::StringPrintf("net/sdch_manager_%p", sdch_manager()));
672 std::unique_ptr<base::Value> raw_attrs =
673 dump->attributes_for_testing()->ToBaseValue();
674 base::DictionaryValue* attrs;
675 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
676 base::DictionaryValue* size_attrs;
677 ASSERT_TRUE(attrs->GetDictionary(
678 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
679 size_t offset = dictionary_text.find("\n\n") + 2;
680 std::string size;
681 ASSERT_TRUE(size_attrs->GetString("value", &size));
682 int actual_size;
683 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
684 EXPECT_EQ(dictionary_text.size() - offset, static_cast<size_t>(actual_size));
685
686 base::DictionaryValue* count_attrs;
687 ASSERT_TRUE(attrs->GetDictionary(
688 base::trace_event::MemoryAllocatorDump::kNameObjectCount, &count_attrs));
689 std::string count;
690 ASSERT_TRUE(count_attrs->GetString("value", &count));
691 // One dictionary.
692 EXPECT_EQ("1", count);
693
694 sdch_manager()->RemoveObserver(&observer);
695 }
696
639 } // namespace net 697 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/url_request/url_request_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698