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

Side by Side Diff: components/memory_pressure/memory_pressure_monitor_unittest.cc

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 years, 3 months 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 "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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 16 matching lines...) Expand all
27 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; 27 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
28 28
29 using testing::_; 29 using testing::_;
30 30
31 } // namespace 31 } // namespace
32 32
33 // A mock task runner. This isn't directly a TaskRunner as the reference 33 // A mock task runner. This isn't directly a TaskRunner as the reference
34 // counting confuses gmock. 34 // counting confuses gmock.
35 class LenientMockTaskRunner { 35 class LenientMockTaskRunner {
36 public: 36 public:
37 MOCK_METHOD3(PostDelayedTask, 37 MOCK_METHOD1(PostDelayedTask, bool(base::TimeDelta));
38 bool(const tracked_objects::Location&,
39 const base::Closure&,
40 base::TimeDelta));
41 }; 38 };
42 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>; 39 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>;
43 40
44 // A TaskRunner implementation that wraps a MockTaskRunner. 41 // A TaskRunner implementation that wraps a MockTaskRunner.
45 class TaskRunnerProxy : public base::TaskRunner { 42 class TaskRunnerProxy : public base::TaskRunner {
46 public: 43 public:
47 // The provided |mock| must outlive this object. 44 // The provided |mock| must outlive this object.
48 explicit TaskRunnerProxy(MockTaskRunner* mock) : mock_(mock) {} 45 explicit TaskRunnerProxy(MockTaskRunner* mock) : mock_(mock) {}
49 bool RunsTasksOnCurrentThread() const override { return true; } 46 bool RunsTasksOnCurrentThread() const override { return true; }
50 bool PostDelayedTask(const tracked_objects::Location& location, 47 bool PostDelayedTask(const tracked_objects::Location& location,
51 const base::Closure& closure, 48 base::OnceClosure closure,
52 base::TimeDelta delta) override { 49 base::TimeDelta delta) override {
53 return mock_->PostDelayedTask(location, closure, delta); 50 return mock_->PostDelayedTask(delta);
54 } 51 }
55 52
56 private: 53 private:
57 MockTaskRunner* mock_; 54 MockTaskRunner* mock_;
58 ~TaskRunnerProxy() override {} 55 ~TaskRunnerProxy() override {}
59 }; 56 };
60 57
61 class TestMemoryPressureMonitor : public MemoryPressureMonitor { 58 class TestMemoryPressureMonitor : public MemoryPressureMonitor {
62 public: 59 public:
63 // Expose the callback that is used for scheduled checks. 60 // Expose the callback that is used for scheduled checks.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 #endif // !MEMORY_PRESSURE_IS_POLLING 158 #endif // !MEMORY_PRESSURE_IS_POLLING
162 159
163 // Advances the tick clock by the given number of milliseconds. 160 // Advances the tick clock by the given number of milliseconds.
164 void Tick(int ms) { 161 void Tick(int ms) {
165 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(ms)); 162 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(ms));
166 } 163 }
167 164
168 // Sets expectations for tasks scheduled via |mock_task_runner_|. 165 // Sets expectations for tasks scheduled via |mock_task_runner_|.
169 void ExpectTaskPosted(int delay_ms) { 166 void ExpectTaskPosted(int delay_ms) {
170 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms); 167 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms);
171 EXPECT_CALL(mock_task_runner_, PostDelayedTask(_, _, delay)) 168 EXPECT_CALL(mock_task_runner_, PostDelayedTask(delay))
172 .WillOnce(testing::Return(true)); 169 .WillOnce(testing::Return(true));
173 } 170 }
174 171
175 // Sets up expectations for calls to |mock_dispatch_|. 172 // Sets up expectations for calls to |mock_dispatch_|.
176 void ExpectDispatch(MemoryPressureLevel level) { 173 void ExpectDispatch(MemoryPressureLevel level) {
177 EXPECT_CALL(mock_dispatch_, Dispatch(level)); 174 EXPECT_CALL(mock_dispatch_, Dispatch(level));
178 } 175 }
179 void ExpectDispatchModerate() { 176 void ExpectDispatchModerate() {
180 EXPECT_CALL(mock_dispatch_, Dispatch(MEMORY_PRESSURE_LEVEL_MODERATE)); 177 EXPECT_CALL(mock_dispatch_, Dispatch(MEMORY_PRESSURE_LEVEL_MODERATE));
181 } 178 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ExpectDispatchCritical(); 377 ExpectDispatchCritical();
381 monitor_->OnMemoryPressureChanged(MEMORY_PRESSURE_LEVEL_CRITICAL); 378 monitor_->OnMemoryPressureChanged(MEMORY_PRESSURE_LEVEL_CRITICAL);
382 VerifyAndClearExpectations(); 379 VerifyAndClearExpectations();
383 ExpectCritical(); 380 ExpectCritical();
384 EXPECT_EQ(2u, monitor_->scheduled_checks().size()); 381 EXPECT_EQ(2u, monitor_->scheduled_checks().size());
385 } 382 }
386 383
387 #endif // !MEMORY_PRESSURE_IS_POLLING 384 #endif // !MEMORY_PRESSURE_IS_POLLING
388 385
389 } // namespace memory_pressure 386 } // namespace memory_pressure
OLDNEW
« no previous file with comments | « chromeos/tpm/tpm_token_info_getter_unittest.cc ('k') | components/timers/alarm_timer_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698