| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/metrics_memory_details.h" | 5 #include "chrome/browser/metrics/metrics_memory_details.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class TestMemoryDetails : public MetricsMemoryDetails { | 16 class TestMemoryDetails : public MetricsMemoryDetails { |
| 17 public: | 17 public: |
| 18 TestMemoryDetails() | 18 TestMemoryDetails() |
| 19 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} | 19 : MetricsMemoryDetails(base::Bind(&base::DoNothing), nullptr) {} |
| 20 | 20 |
| 21 void StartFetchAndWait() { | 21 void StartFetchAndWait() { |
| 22 StartFetch(FROM_CHROME_ONLY); | 22 StartFetch(); |
| 23 content::RunMessageLoop(); | 23 content::RunMessageLoop(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 ~TestMemoryDetails() override {} | 27 ~TestMemoryDetails() override {} |
| 28 | 28 |
| 29 void OnDetailsAvailable() override { | 29 void OnDetailsAvailable() override { |
| 30 MetricsMemoryDetails::OnDetailsAvailable(); | 30 MetricsMemoryDetails::OnDetailsAvailable(); |
| 31 // Exit the loop initiated by StartFetchAndWait(). | 31 // Exit the loop initiated by StartFetchAndWait(). |
| 32 base::MessageLoop::current()->QuitWhenIdle(); | 32 base::MessageLoop::current()->QuitWhenIdle(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); | 52 scoped_refptr<TestMemoryDetails> details(new TestMemoryDetails); |
| 53 details->StartFetchAndWait(); | 53 details->StartFetchAndWait(); |
| 54 | 54 |
| 55 // Memory.Browser histogram should have a single non-0 sample recorded. | 55 // Memory.Browser histogram should have a single non-0 sample recorded. |
| 56 histogram_tester.ExpectTotalCount("Memory.Browser", 1); | 56 histogram_tester.ExpectTotalCount("Memory.Browser", 1); |
| 57 scoped_ptr<base::HistogramSamples> samples( | 57 scoped_ptr<base::HistogramSamples> samples( |
| 58 histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser")); | 58 histogram_tester.GetHistogramSamplesSinceCreation("Memory.Browser")); |
| 59 ASSERT_TRUE(samples); | 59 ASSERT_TRUE(samples); |
| 60 EXPECT_NE(0, samples->sum()); | 60 EXPECT_NE(0, samples->sum()); |
| 61 } | 61 } |
| OLD | NEW |