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_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 8312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8346 HttpResponseInfo response_info; | 8350 HttpResponseInfo response_info; |
8347 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8351 RunTransactionTestWithResponseInfo(cache.http_cache(), |
8348 kTypicalGET_Transaction, &response_info); | 8352 kTypicalGET_Transaction, &response_info); |
8349 | 8353 |
8350 EXPECT_FALSE(response_info.was_cached); | 8354 EXPECT_FALSE(response_info.was_cached); |
8351 EXPECT_TRUE(response_info.network_accessed); | 8355 EXPECT_TRUE(response_info.network_accessed); |
8352 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8356 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
8353 response_info.cache_entry_status); | 8357 response_info.cache_entry_status); |
8354 } | 8358 } |
8355 | 8359 |
| 8360 // Basic test to make sure HttpCache::DumpMemoryStats doesn't crash. |
| 8361 TEST(HttpCache, DumpMemoryStats) { |
| 8362 MockHttpCache cache; |
| 8363 cache.FailConditionalizations(); |
| 8364 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
| 8365 |
| 8366 HttpResponseInfo response_info; |
| 8367 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 8368 kTypicalGET_Transaction, &response_info); |
| 8369 |
| 8370 EXPECT_FALSE(response_info.was_cached); |
| 8371 EXPECT_TRUE(response_info.network_accessed); |
| 8372 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| 8373 response_info.cache_entry_status); |
| 8374 |
| 8375 base::trace_event::MemoryDumpArgs dump_args = { |
| 8376 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
| 8377 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( |
| 8378 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); |
| 8379 base::trace_event::MemoryAllocatorDump* parent_dump = |
| 8380 process_memory_dump->CreateAllocatorDump("parent"); |
| 8381 cache.http_cache()->DumpMemoryStats(process_memory_dump.get(), |
| 8382 parent_dump->absolute_name()); |
| 8383 |
| 8384 const base::trace_event::MemoryAllocatorDump* dump = |
| 8385 process_memory_dump->GetAllocatorDump("parent/http_cache"); |
| 8386 ASSERT_NE(nullptr, dump); |
| 8387 std::unique_ptr<base::Value> raw_attrs = |
| 8388 dump->attributes_for_testing()->ToBaseValue(); |
| 8389 base::DictionaryValue* attrs; |
| 8390 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
| 8391 base::DictionaryValue* size_attrs; |
| 8392 ASSERT_TRUE(attrs->GetDictionary( |
| 8393 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); |
| 8394 std::string size; |
| 8395 ASSERT_TRUE(size_attrs->GetString("value", &size)); |
| 8396 int actual_size = 0; |
| 8397 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); |
| 8398 ASSERT_LT(0, actual_size); |
| 8399 } |
| 8400 |
8356 } // namespace net | 8401 } // namespace net |
OLD | NEW |