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

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

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: -unneeded callback_helpers.h Created 3 years, 9 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 #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
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);
gab 2017/03/24 15:56:08 Passing a pointer to a local variable to a mock me
tzik 2017/03/28 05:59:15 Removed the Closure parameter. This couldn't move
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698