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/memory_pressure/memory_pressure_monitor.h" | 5 #include "components/memory_pressure/memory_pressure_monitor.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
11 #include "base/test/simple_test_tick_clock.h" | 12 #include "base/test/simple_test_tick_clock.h" |
12 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
13 #include "components/memory_pressure/memory_pressure_stats_collector.h" | 14 #include "components/memory_pressure/memory_pressure_stats_collector.h" |
14 #include "components/memory_pressure/test_memory_pressure_calculator.h" | 15 #include "components/memory_pressure/test_memory_pressure_calculator.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
(...skipping 12 matching lines...) Expand all Loading... |
30 using testing::_; | 31 using testing::_; |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 // A mock task runner. This isn't directly a TaskRunner as the reference | 35 // A mock task runner. This isn't directly a TaskRunner as the reference |
35 // counting confuses gmock. | 36 // counting confuses gmock. |
36 class LenientMockTaskRunner { | 37 class LenientMockTaskRunner { |
37 public: | 38 public: |
38 MOCK_METHOD3(PostDelayedTask, | 39 MOCK_METHOD3(PostDelayedTask, |
39 bool(const tracked_objects::Location&, | 40 bool(const tracked_objects::Location&, |
40 const base::Closure&, | 41 base::Closure*, |
41 base::TimeDelta)); | 42 base::TimeDelta)); |
| 43 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 44 base::Closure task, |
| 45 base::TimeDelta delay) { |
| 46 return PostDelayedTask(from_here, &task, delay); |
| 47 } |
42 }; | 48 }; |
43 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>; | 49 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>; |
44 | 50 |
45 // A TaskRunner implementation that wraps a MockTaskRunner. | 51 // A TaskRunner implementation that wraps a MockTaskRunner. |
46 class TaskRunnerProxy : public base::TaskRunner { | 52 class TaskRunnerProxy : public base::TaskRunner { |
47 public: | 53 public: |
48 // The provided |mock| must outlive this object. | 54 // The provided |mock| must outlive this object. |
49 explicit TaskRunnerProxy(MockTaskRunner* mock) : mock_(mock) {} | 55 explicit TaskRunnerProxy(MockTaskRunner* mock) : mock_(mock) {} |
50 bool RunsTasksOnCurrentThread() const override { return true; } | 56 bool RunsTasksOnCurrentThread() const override { return true; } |
51 bool PostDelayedTask(const tracked_objects::Location& location, | 57 bool PostDelayedTask(const tracked_objects::Location& location, |
52 const base::Closure& closure, | 58 base::Closure closure, |
53 base::TimeDelta delta) override { | 59 base::TimeDelta delta) override { |
54 return mock_->PostDelayedTask(location, closure, delta); | 60 return mock_->PostDelayedTask(location, std::move(closure), delta); |
55 } | 61 } |
56 | 62 |
57 private: | 63 private: |
58 MockTaskRunner* mock_; | 64 MockTaskRunner* mock_; |
59 ~TaskRunnerProxy() override {} | 65 ~TaskRunnerProxy() override {} |
60 }; | 66 }; |
61 | 67 |
62 class TestMemoryPressureMonitor : public MemoryPressureMonitor { | 68 class TestMemoryPressureMonitor : public MemoryPressureMonitor { |
63 public: | 69 public: |
64 // Expose the callback that is used for scheduled checks. | 70 // Expose the callback that is used for scheduled checks. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 ExpectDispatchCritical(); | 387 ExpectDispatchCritical(); |
382 monitor_->OnMemoryPressureChanged(MEMORY_PRESSURE_LEVEL_CRITICAL); | 388 monitor_->OnMemoryPressureChanged(MEMORY_PRESSURE_LEVEL_CRITICAL); |
383 VerifyAndClearExpectations(); | 389 VerifyAndClearExpectations(); |
384 ExpectCritical(); | 390 ExpectCritical(); |
385 EXPECT_EQ(2u, monitor_->scheduled_checks().size()); | 391 EXPECT_EQ(2u, monitor_->scheduled_checks().size()); |
386 } | 392 } |
387 | 393 |
388 #endif // !MEMORY_PRESSURE_IS_POLLING | 394 #endif // !MEMORY_PRESSURE_IS_POLLING |
389 | 395 |
390 } // namespace memory_pressure | 396 } // namespace memory_pressure |
OLD | NEW |