OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/metrics/leak_detector/leak_detector.h" | 5 #include "components/metrics/leak_detector/leak_detector.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
| 9 #include "base/allocator/allocator_extension.h" |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace metrics { | 15 namespace metrics { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Default values for LeakDetector params. See header file for the meaning of | 19 // Default values for LeakDetector params. See header file for the meaning of |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // test is over. | 72 // test is over. |
72 scoped_ptr<LeakDetector> detector_; | 73 scoped_ptr<LeakDetector> detector_; |
73 | 74 |
74 private: | 75 private: |
75 // For supporting content::BrowserThread operations. | 76 // For supporting content::BrowserThread operations. |
76 content::TestBrowserThreadBundle thread_bundle_; | 77 content::TestBrowserThreadBundle thread_bundle_; |
77 | 78 |
78 DISALLOW_COPY_AND_ASSIGN(LeakDetectorTest); | 79 DISALLOW_COPY_AND_ASSIGN(LeakDetectorTest); |
79 }; | 80 }; |
80 | 81 |
| 82 TEST_F(LeakDetectorTest, AllocatorHooks) { |
| 83 EXPECT_EQ(&LeakDetector::AllocHook, base::allocator::GetSingleAllocHook()); |
| 84 EXPECT_EQ(&LeakDetector::FreeHook, base::allocator::GetSingleFreeHook()); |
| 85 } |
| 86 |
81 TEST_F(LeakDetectorTest, NotifyObservers) { | 87 TEST_F(LeakDetectorTest, NotifyObservers) { |
82 // Generate two sets of leak reports. | 88 // Generate two sets of leak reports. |
83 std::vector<LeakReport> reports1(3); | 89 std::vector<LeakReport> reports1(3); |
84 reports1[0].alloc_size_bytes = 8; | 90 reports1[0].alloc_size_bytes = 8; |
85 reports1[0].call_stack = {1, 2, 3, 4}; | 91 reports1[0].call_stack = {1, 2, 3, 4}; |
86 reports1[1].alloc_size_bytes = 16; | 92 reports1[1].alloc_size_bytes = 16; |
87 reports1[1].call_stack = {5, 6, 7, 8}; | 93 reports1[1].call_stack = {5, 6, 7, 8}; |
88 reports1[2].alloc_size_bytes = 24; | 94 reports1[2].alloc_size_bytes = 24; |
89 reports1[2].call_stack = {9, 10, 11, 12}; | 95 reports1[2].call_stack = {9, 10, 11, 12}; |
90 | 96 |
(...skipping 24 matching lines...) Expand all Loading... |
115 for (const TestObserver* obs : {&obs1, &obs2, &obs3}) { | 121 for (const TestObserver* obs : {&obs1, &obs2, &obs3}) { |
116 EXPECT_EQ(6U, obs->reports().size()); | 122 EXPECT_EQ(6U, obs->reports().size()); |
117 for (const auto& report : {reports1[0], reports1[1], reports1[2], | 123 for (const auto& report : {reports1[0], reports1[1], reports1[2], |
118 reports2[0], reports2[1], reports2[2]}) { | 124 reports2[0], reports2[1], reports2[2]}) { |
119 EXPECT_TRUE(obs->reports().find(report) != obs->reports().end()); | 125 EXPECT_TRUE(obs->reports().find(report) != obs->reports().end()); |
120 } | 126 } |
121 } | 127 } |
122 } | 128 } |
123 | 129 |
124 } // namespace metrics | 130 } // namespace metrics |
OLD | NEW |