1 // Copyright 2015 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.
5 #include "chrome/browser/metrics/metrics_memory_details.h"
7 #include "base/bind_helpers.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/test/histogram_tester.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/test/test_utils.h"
15 class TestMemoryDetails
: public MetricsMemoryDetails
{
18 : MetricsMemoryDetails(base::Bind(&base::DoNothing
), nullptr) {}
20 void StartFetchAndWait() {
21 StartFetch(FROM_CHROME_ONLY
);
22 content::RunMessageLoop();
26 ~TestMemoryDetails() override
{}
28 void OnDetailsAvailable() override
{
29 MetricsMemoryDetails::OnDetailsAvailable();
30 // Exit the loop initiated by StartFetchAndWait().
31 base::MessageLoop::current()->Quit();
34 DISALLOW_COPY_AND_ASSIGN(TestMemoryDetails
);
39 class MetricsMemoryDetailsBrowserTest
: public InProcessBrowserTest
{
41 MetricsMemoryDetailsBrowserTest() {}
42 ~MetricsMemoryDetailsBrowserTest() override
{}
45 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetailsBrowserTest
);
48 IN_PROC_BROWSER_TEST_F(MetricsMemoryDetailsBrowserTest
, TestMemoryDetails
) {
49 base::HistogramTester histogram_tester
;
51 scoped_refptr
<TestMemoryDetails
> details(new TestMemoryDetails
);
52 details
->StartFetchAndWait();
54 // Memory.Browser histogram should have a single non-0 sample recorded.
55 histogram_tester
.ExpectTotalCount("Memory.Browser", 1);
56 scoped_ptr
<base::HistogramSamples
> samples(
57 histogram_tester
.GetHistogramSamplesSinceCreation("Memory.Browser"));
59 EXPECT_NE(0, samples
->sum());