| 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 "components/memory_pressure/memory_pressure_stats_collector.h" | 5 #include "components/memory_pressure/memory_pressure_stats_collector.h" |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 MemoryPressureLevel last_pressure_level() const { | 31 MemoryPressureLevel last_pressure_level() const { |
| 32 return last_pressure_level_; | 32 return last_pressure_level_; |
| 33 } | 33 } |
| 34 base::TimeTicks last_update_time() const { return last_update_time_; } | 34 base::TimeTicks last_update_time() const { return last_update_time_; } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Test fixture. | 37 // Test fixture. |
| 38 class MemoryPressureStatsCollectorTest : public testing::Test { | 38 class MemoryPressureStatsCollectorTest : public testing::Test { |
| 39 public: | 39 public: |
| 40 MemoryPressureStatsCollectorTest() : collector_(&tick_clock_) {} | 40 MemoryPressureStatsCollectorTest() |
| 41 : tick_clock_(base::TimeTicks()), collector_(&tick_clock_) {} |
| 41 | 42 |
| 42 void Tick(int ms) { | 43 void Tick(int ms) { |
| 43 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(ms)); | 44 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(ms)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Validates expectations on the amount of accumulated (and unreported) | 47 // Validates expectations on the amount of accumulated (and unreported) |
| 47 // time (milliseconds) per pressure level. | 48 // time (milliseconds) per pressure level. |
| 48 void ExpectAccumulated(int none_ms, int moderate_ms, int critical_ms) { | 49 void ExpectAccumulated(int none_ms, int moderate_ms, int critical_ms) { |
| 49 EXPECT_EQ(base::TimeDelta::FromMilliseconds(none_ms), | 50 EXPECT_EQ(base::TimeDelta::FromMilliseconds(none_ms), |
| 50 collector_.unreported_cumulative_time(0)); // None. | 51 collector_.unreported_cumulative_time(0)); // None. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 EXPECT_EQ(tick_clock_.NowTicks(), collector_.last_update_time()); | 131 EXPECT_EQ(tick_clock_.NowTicks(), collector_.last_update_time()); |
| 131 ExpectAccumulated(500, 250, 0); | 132 ExpectAccumulated(500, 250, 0); |
| 132 ExpectReported(1, 2, 0); | 133 ExpectReported(1, 2, 0); |
| 133 histograms_.ExpectBucketCount( | 134 histograms_.ExpectBucketCount( |
| 134 kPressureLevelChange, UMA_MEMORY_PRESSURE_LEVEL_CHANGE_NONE_TO_MODERATE, | 135 kPressureLevelChange, UMA_MEMORY_PRESSURE_LEVEL_CHANGE_NONE_TO_MODERATE, |
| 135 1); | 136 1); |
| 136 histograms_.ExpectTotalCount(kPressureLevelChange, 1); | 137 histograms_.ExpectTotalCount(kPressureLevelChange, 1); |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace memory_pressure | 140 } // namespace memory_pressure |
| OLD | NEW |