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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: Address jkarlin@ comments Created 3 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/format_macros.h" 16 #include "base/format_macros.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
23 #include "base/test/simple_test_clock.h" 24 #include "base/test/simple_test_clock.h"
25 #include "base/trace_event/memory_allocator_dump.h"
26 #include "base/trace_event/process_memory_dump.h"
27 #include "base/trace_event/trace_event_argument.h"
24 #include "net/base/cache_type.h" 28 #include "net/base/cache_type.h"
25 #include "net/base/elements_upload_data_stream.h" 29 #include "net/base/elements_upload_data_stream.h"
26 #include "net/base/host_port_pair.h" 30 #include "net/base/host_port_pair.h"
27 #include "net/base/ip_endpoint.h" 31 #include "net/base/ip_endpoint.h"
28 #include "net/base/load_flags.h" 32 #include "net/base/load_flags.h"
29 #include "net/base/load_timing_info.h" 33 #include "net/base/load_timing_info.h"
30 #include "net/base/load_timing_info_test_util.h" 34 #include "net/base/load_timing_info_test_util.h"
31 #include "net/base/net_errors.h" 35 #include "net/base/net_errors.h"
32 #include "net/base/upload_bytes_element_reader.h" 36 #include "net/base/upload_bytes_element_reader.h"
33 #include "net/cert/cert_status_flags.h" 37 #include "net/cert/cert_status_flags.h"
(...skipping 8287 matching lines...) Expand 10 before | Expand all | Expand 10 after
8321 HttpResponseInfo response_info; 8325 HttpResponseInfo response_info;
8322 RunTransactionTestWithResponseInfo(cache.http_cache(), 8326 RunTransactionTestWithResponseInfo(cache.http_cache(),
8323 kTypicalGET_Transaction, &response_info); 8327 kTypicalGET_Transaction, &response_info);
8324 8328
8325 EXPECT_FALSE(response_info.was_cached); 8329 EXPECT_FALSE(response_info.was_cached);
8326 EXPECT_TRUE(response_info.network_accessed); 8330 EXPECT_TRUE(response_info.network_accessed);
8327 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8331 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8328 response_info.cache_entry_status); 8332 response_info.cache_entry_status);
8329 } 8333 }
8330 8334
8335 // Basic test to make sure HttpCache::DumpMemoryStats doesn't crash.
8336 TEST(HttpCache, DumpMemoryStats) {
8337 MockHttpCache cache;
8338 cache.FailConditionalizations();
8339 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
8340
8341 HttpResponseInfo response_info;
8342 RunTransactionTestWithResponseInfo(cache.http_cache(),
8343 kTypicalGET_Transaction, &response_info);
8344
8345 EXPECT_FALSE(response_info.was_cached);
8346 EXPECT_TRUE(response_info.network_accessed);
8347 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8348 response_info.cache_entry_status);
8349
8350 base::trace_event::MemoryDumpArgs dump_args = {
8351 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
8352 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
8353 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
8354 base::trace_event::MemoryAllocatorDump* parent_dump =
8355 process_memory_dump->CreateAllocatorDump("parent");
8356 cache.http_cache()->DumpMemoryStats(process_memory_dump.get(),
8357 parent_dump->absolute_name());
8358
8359 const base::trace_event::MemoryAllocatorDump* dump =
8360 process_memory_dump->GetAllocatorDump("parent/http_cache");
8361 ASSERT_NE(nullptr, dump);
8362 std::unique_ptr<base::Value> raw_attrs =
8363 dump->attributes_for_testing()->ToBaseValue();
8364 base::DictionaryValue* attrs;
8365 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
8366 base::DictionaryValue* size_attrs;
8367 ASSERT_TRUE(attrs->GetDictionary(
8368 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
8369 std::string size;
8370 ASSERT_TRUE(size_attrs->GetString("value", &size));
8371 int actual_size = 0;
8372 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
8373 ASSERT_LT(0, actual_size);
8374 }
8375
8331 } // namespace net 8376 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698