blob: eeef64ac374aaf89b9fc1f148c24508e4afb3e71 [file] [log] [blame]
xunjieli96ab36a72016-12-05 21:36:051// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/url_request/url_request_context.h"
6
xunjielid5debfc2017-02-24 15:55:497#include "base/trace_event/memory_dump_request_args.h"
xunjieli96ab36a72016-12-05 21:36:058#include "base/trace_event/process_memory_dump.h"
Lily Houghton582d4622018-01-22 22:43:409#include "net/proxy_resolution/proxy_config_service_fixed.h"
Ramin Halavatica8d5252018-03-12 05:33:4910#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
xunjieli96ab36a72016-12-05 21:36:0511#include "net/url_request/url_request_context_builder.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
14namespace net {
15
xunjielid5debfc2017-02-24 15:55:4916class URLRequestContextMemoryDumpTest
17 : public testing::TestWithParam<
18 base::trace_event::MemoryDumpLevelOfDetail> {};
19
20INSTANTIATE_TEST_CASE_P(
21 /* no prefix */,
22 URLRequestContextMemoryDumpTest,
23 ::testing::Values(base::trace_event::MemoryDumpLevelOfDetail::DETAILED,
24 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND));
25
xunjieli96ab36a72016-12-05 21:36:0526// Checks if the dump provider runs without crashing and dumps root objects.
xunjielid5debfc2017-02-24 15:55:4927TEST_P(URLRequestContextMemoryDumpTest, MemoryDumpProvider) {
28 base::trace_event::MemoryDumpArgs dump_args = {GetParam()};
xunjieli96ab36a72016-12-05 21:36:0529 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
30 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
31 URLRequestContextBuilder builder;
32#if defined(OS_LINUX) || defined(OS_ANDROID)
Ramin Halavatica8d5252018-03-12 05:33:4933 builder.set_proxy_config_service(std::make_unique<ProxyConfigServiceFixed>(
34 ProxyConfigWithAnnotation::CreateDirect()));
xunjieli96ab36a72016-12-05 21:36:0535#endif // defined(OS_LINUX) || defined(OS_ANDROID)
36 std::unique_ptr<URLRequestContext> context(builder.Build());
37 context->OnMemoryDump(dump_args, process_memory_dump.get());
38 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
39 allocator_dumps = process_memory_dump->allocator_dumps();
40
xunjieli9f8c5fb52016-12-07 22:59:3341 bool did_dump_http_network_session = false;
42 bool did_dump_ssl_client_session_cache = false;
xunjieli96ab36a72016-12-05 21:36:0543 bool did_dump_url_request_context = false;
xunjieli2a2468bd2017-01-04 21:17:3344 bool did_dump_url_request_context_http_network_session = false;
xunjieli96ab36a72016-12-05 21:36:0545 for (const auto& it : allocator_dumps) {
46 const std::string& dump_name = it.first;
xunjieli9f8c5fb52016-12-07 22:59:3347 if (dump_name.find("net/http_network_session") != std::string::npos)
48 did_dump_http_network_session = true;
49 if (dump_name.find("net/ssl_session_cache") != std::string::npos)
50 did_dump_ssl_client_session_cache = true;
xunjieli2a2468bd2017-01-04 21:17:3351 if (dump_name.find("net/url_request_context") != std::string::npos) {
52 // A sub allocator dump to take into account of the sharing relationship.
53 if (dump_name.find("http_network_session") != std::string::npos) {
54 did_dump_url_request_context_http_network_session = true;
55 } else {
56 did_dump_url_request_context = true;
57 }
58 }
xunjieli96ab36a72016-12-05 21:36:0559 }
xunjieli9f8c5fb52016-12-07 22:59:3360 ASSERT_TRUE(did_dump_http_network_session);
61 ASSERT_TRUE(did_dump_ssl_client_session_cache);
xunjieli96ab36a72016-12-05 21:36:0562 ASSERT_TRUE(did_dump_url_request_context);
xunjieli2a2468bd2017-01-04 21:17:3363 ASSERT_TRUE(did_dump_url_request_context_http_network_session);
xunjieli96ab36a72016-12-05 21:36:0564}
65
xunjieli9f8c5fb52016-12-07 22:59:3366// TODO(xunjieli): Add more granular tests on the MemoryDumpProvider.
xunjieli96ab36a72016-12-05 21:36:0567} // namespace net