OLD | NEW |
---|---|
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_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/test/simple_test_clock.h" | 23 #include "base/test/simple_test_clock.h" |
24 #include "base/trace_event/memory_allocator_dump.h" | |
25 #include "base/trace_event/process_memory_dump.h" | |
24 #include "net/base/cache_type.h" | 26 #include "net/base/cache_type.h" |
25 #include "net/base/elements_upload_data_stream.h" | 27 #include "net/base/elements_upload_data_stream.h" |
26 #include "net/base/host_port_pair.h" | 28 #include "net/base/host_port_pair.h" |
27 #include "net/base/ip_endpoint.h" | 29 #include "net/base/ip_endpoint.h" |
28 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
29 #include "net/base/load_timing_info.h" | 31 #include "net/base/load_timing_info.h" |
30 #include "net/base/load_timing_info_test_util.h" | 32 #include "net/base/load_timing_info_test_util.h" |
31 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
32 #include "net/base/upload_bytes_element_reader.h" | 34 #include "net/base/upload_bytes_element_reader.h" |
33 #include "net/cert/cert_status_flags.h" | 35 #include "net/cert/cert_status_flags.h" |
(...skipping 8287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8321 HttpResponseInfo response_info; | 8323 HttpResponseInfo response_info; |
8322 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8324 RunTransactionTestWithResponseInfo(cache.http_cache(), |
8323 kTypicalGET_Transaction, &response_info); | 8325 kTypicalGET_Transaction, &response_info); |
8324 | 8326 |
8325 EXPECT_FALSE(response_info.was_cached); | 8327 EXPECT_FALSE(response_info.was_cached); |
8326 EXPECT_TRUE(response_info.network_accessed); | 8328 EXPECT_TRUE(response_info.network_accessed); |
8327 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8329 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
8328 response_info.cache_entry_status); | 8330 response_info.cache_entry_status); |
8329 } | 8331 } |
8330 | 8332 |
8333 // Basic test to make sure HttpCache::DumpMemoryStats doesn't crash. | |
8334 TEST(HttpCache, DumpMemoryStats) { | |
8335 MockHttpCache cache; | |
8336 cache.FailConditionalizations(); | |
8337 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); | |
8338 | |
8339 HttpResponseInfo response_info; | |
8340 RunTransactionTestWithResponseInfo(cache.http_cache(), | |
8341 kTypicalGET_Transaction, &response_info); | |
8342 | |
8343 EXPECT_FALSE(response_info.was_cached); | |
8344 EXPECT_TRUE(response_info.network_accessed); | |
8345 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | |
8346 response_info.cache_entry_status); | |
8347 | |
8348 base::trace_event::MemoryDumpArgs dump_args = { | |
8349 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | |
8350 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | |
8351 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | |
8352 base::trace_event::MemoryAllocatorDump* parent_dump = | |
8353 process_memory_dump->CreateAllocatorDump("parent"); | |
8354 cache.http_cache()->DumpMemoryStats(process_memory_dump.get(), | |
8355 parent_dump->absolute_name()); | |
8356 | |
8357 // Whether HttpCache::DumpMemoryStats() is invoked. | |
8358 bool did_dump = false; | |
8359 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | |
8360 allocator_dumps = process_memory_dump->allocator_dumps(); | |
8361 for (const auto& pair : allocator_dumps) { | |
8362 const std::string& dump_name = pair.first; | |
8363 if (dump_name.find("http_cache") == std::string::npos) | |
8364 continue; | |
8365 did_dump = true; | |
8366 } | |
8367 EXPECT_TRUE(did_dump); | |
jkarlin
2017/02/21 16:23:29
Can you add a simple check that the dump size is g
xunjieli
2017/02/21 19:44:14
Done.
| |
8368 } | |
8369 | |
8331 } // namespace net | 8370 } // namespace net |
OLD | NEW |