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

Side by Side Diff: chrome/browser/metrics/leak_detector/leak_detector_controller_unittest.cc

Issue 2549623006: Fix TestBrowserThread destruction order in CrOS tests. (Closed)
Patch Set: +comment on Leaky Created 4 years 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
OLDNEW
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 "chrome/browser/metrics/leak_detector/leak_detector_controller.h" 5 #include "chrome/browser/metrics/leak_detector/leak_detector_controller.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // For supporting content::BrowserThread operations. 49 // For supporting content::BrowserThread operations.
50 content::TestBrowserThreadBundle thread_bundle_; 50 content::TestBrowserThreadBundle thread_bundle_;
51 51
52 DISALLOW_COPY_AND_ASSIGN(LeakDetectorControllerTest); 52 DISALLOW_COPY_AND_ASSIGN(LeakDetectorControllerTest);
53 }; 53 };
54 54
55 // Use a global instance of the test class because LeakDetectorController 55 // Use a global instance of the test class because LeakDetectorController
56 // initializes class LeakDetector, which can only be initialized once, enforced 56 // initializes class LeakDetector, which can only be initialized once, enforced
57 // by an internal CHECK. Multiple initializations of LeakDetectorController in 57 // by an internal CHECK. Multiple initializations of LeakDetectorController in
58 // the same process will result in multiple initializations of class 58 // the same process will result in multiple initializations of class
59 // LeakDetector. 59 // LeakDetector. It has to be Leaky as running its destructor will otherwise
60 // DCHECK when called outside the scope of a TestBrowserThreadBundle.
60 // 61 //
61 // See src/components/metrics/leak_detector/leak_detector.h for more info. 62 // See src/components/metrics/leak_detector/leak_detector.h for more info.
62 base::LazyInstance<TestLeakDetectorController> g_instance = 63 base::LazyInstance<TestLeakDetectorController>::Leaky g_instance =
63 LAZY_INSTANCE_INITIALIZER; 64 LAZY_INSTANCE_INITIALIZER;
64 65
65 TEST_F(LeakDetectorControllerTest, SingleReport) { 66 TEST_F(LeakDetectorControllerTest, SingleReport) {
66 MemoryLeakReportProto report; 67 MemoryLeakReportProto report;
67 report.set_size_bytes(8); 68 report.set_size_bytes(8);
68 InitializeRepeatedField({1, 2, 3, 4}, report.mutable_call_stack()); 69 InitializeRepeatedField({1, 2, 3, 4}, report.mutable_call_stack());
69 70
70 TestLeakDetectorController* controller = &g_instance.Get(); 71 TestLeakDetectorController* controller = &g_instance.Get();
71 controller->OnLeaksFound({report}); 72 controller->OnLeaksFound({report});
72 73
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 EXPECT_EQ(13U, stored_reports[2].call_stack().Get(4)); 261 EXPECT_EQ(13U, stored_reports[2].call_stack().Get(4));
261 EXPECT_EQ(14U, stored_reports[2].call_stack().Get(5)); 262 EXPECT_EQ(14U, stored_reports[2].call_stack().Get(5));
262 EXPECT_EQ(15U, stored_reports[2].call_stack().Get(6)); 263 EXPECT_EQ(15U, stored_reports[2].call_stack().Get(6));
263 EXPECT_EQ(16U, stored_reports[2].call_stack().Get(7)); 264 EXPECT_EQ(16U, stored_reports[2].call_stack().Get(7));
264 265
265 controller->GetLeakReports(&stored_reports); 266 controller->GetLeakReports(&stored_reports);
266 ASSERT_EQ(0U, stored_reports.size()); 267 ASSERT_EQ(0U, stored_reports.size());
267 } 268 }
268 269
269 } // namespace metrics 270 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698