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

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

Issue 2699163002: Whitelist net/ MemoryDumpProvider (Closed)
Patch Set: fix test on windows Created 3 years, 9 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
« no previous file with comments | « net/base/sdch_manager_unittest.cc ('k') | net/http/http_network_session.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 (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_number_conversions.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/test/simple_test_clock.h" 24 #include "base/test/simple_test_clock.h"
25 #include "base/trace_event/memory_allocator_dump.h" 25 #include "base/trace_event/memory_allocator_dump.h"
26 #include "base/trace_event/memory_dump_request_args.h"
26 #include "base/trace_event/process_memory_dump.h" 27 #include "base/trace_event/process_memory_dump.h"
27 #include "base/trace_event/trace_event_argument.h" 28 #include "base/trace_event/trace_event_argument.h"
28 #include "net/base/cache_type.h" 29 #include "net/base/cache_type.h"
29 #include "net/base/elements_upload_data_stream.h" 30 #include "net/base/elements_upload_data_stream.h"
30 #include "net/base/host_port_pair.h" 31 #include "net/base/host_port_pair.h"
31 #include "net/base/ip_endpoint.h" 32 #include "net/base/ip_endpoint.h"
32 #include "net/base/load_flags.h" 33 #include "net/base/load_flags.h"
33 #include "net/base/load_timing_info.h" 34 #include "net/base/load_timing_info.h"
34 #include "net/base/load_timing_info_test_util.h" 35 #include "net/base/load_timing_info_test_util.h"
35 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
(...skipping 8314 matching lines...) Expand 10 before | Expand all | Expand 10 after
8350 HttpResponseInfo response_info; 8351 HttpResponseInfo response_info;
8351 RunTransactionTestWithResponseInfo(cache.http_cache(), 8352 RunTransactionTestWithResponseInfo(cache.http_cache(),
8352 kTypicalGET_Transaction, &response_info); 8353 kTypicalGET_Transaction, &response_info);
8353 8354
8354 EXPECT_FALSE(response_info.was_cached); 8355 EXPECT_FALSE(response_info.was_cached);
8355 EXPECT_TRUE(response_info.network_accessed); 8356 EXPECT_TRUE(response_info.network_accessed);
8356 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8357 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8357 response_info.cache_entry_status); 8358 response_info.cache_entry_status);
8358 } 8359 }
8359 8360
8361 class HttpCacheMemoryDumpTest
8362 : public testing::TestWithParam<
8363 base::trace_event::MemoryDumpLevelOfDetail> {};
8364
8365 INSTANTIATE_TEST_CASE_P(
8366 /* no prefix */,
8367 HttpCacheMemoryDumpTest,
8368 ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED,
8369 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND));
8370
8360 // Basic test to make sure HttpCache::DumpMemoryStats doesn't crash. 8371 // Basic test to make sure HttpCache::DumpMemoryStats doesn't crash.
8361 TEST(HttpCache, DumpMemoryStats) { 8372 TEST_P(HttpCacheMemoryDumpTest, DumpMemoryStats) {
8362 MockHttpCache cache; 8373 MockHttpCache cache;
8363 cache.FailConditionalizations(); 8374 cache.FailConditionalizations();
8364 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); 8375 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
8365 8376
8366 HttpResponseInfo response_info; 8377 HttpResponseInfo response_info;
8367 RunTransactionTestWithResponseInfo(cache.http_cache(), 8378 RunTransactionTestWithResponseInfo(cache.http_cache(),
8368 kTypicalGET_Transaction, &response_info); 8379 kTypicalGET_Transaction, &response_info);
8369 8380
8370 EXPECT_FALSE(response_info.was_cached); 8381 EXPECT_FALSE(response_info.was_cached);
8371 EXPECT_TRUE(response_info.network_accessed); 8382 EXPECT_TRUE(response_info.network_accessed);
8372 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8383 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8373 response_info.cache_entry_status); 8384 response_info.cache_entry_status);
8374 8385
8375 base::trace_event::MemoryDumpArgs dump_args = { 8386 base::trace_event::MemoryDumpArgs dump_args = {GetParam()};
8376 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
8377 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( 8387 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
8378 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); 8388 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
8379 base::trace_event::MemoryAllocatorDump* parent_dump = 8389 base::trace_event::MemoryAllocatorDump* parent_dump =
8380 process_memory_dump->CreateAllocatorDump("parent"); 8390 process_memory_dump->CreateAllocatorDump("net/url_request_context_0x123");
8381 cache.http_cache()->DumpMemoryStats(process_memory_dump.get(), 8391 cache.http_cache()->DumpMemoryStats(process_memory_dump.get(),
8382 parent_dump->absolute_name()); 8392 parent_dump->absolute_name());
8383 8393
8384 const base::trace_event::MemoryAllocatorDump* dump = 8394 const base::trace_event::MemoryAllocatorDump* dump =
8385 process_memory_dump->GetAllocatorDump("parent/http_cache"); 8395 process_memory_dump->GetAllocatorDump(
8396 "net/url_request_context_0x123/http_cache");
8386 ASSERT_NE(nullptr, dump); 8397 ASSERT_NE(nullptr, dump);
8387 std::unique_ptr<base::Value> raw_attrs = 8398 std::unique_ptr<base::Value> raw_attrs =
8388 dump->attributes_for_testing()->ToBaseValue(); 8399 dump->attributes_for_testing()->ToBaseValue();
8389 base::DictionaryValue* attrs; 8400 base::DictionaryValue* attrs;
8390 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); 8401 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
8391 base::DictionaryValue* size_attrs; 8402 base::DictionaryValue* size_attrs;
8392 ASSERT_TRUE(attrs->GetDictionary( 8403 ASSERT_TRUE(attrs->GetDictionary(
8393 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 8404 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
8394 std::string size; 8405 std::string size;
8395 ASSERT_TRUE(size_attrs->GetString("value", &size)); 8406 ASSERT_TRUE(size_attrs->GetString("value", &size));
8396 int actual_size = 0; 8407 int actual_size = 0;
8397 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 8408 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
8398 ASSERT_LT(0, actual_size); 8409 ASSERT_LT(0, actual_size);
8399 } 8410 }
8400 8411
8401 } // namespace net 8412 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager_unittest.cc ('k') | net/http/http_network_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698