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

Side by Side Diff: chrome/browser/memory/tab_manager_unittest.cc

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/tab_manager.h" 5 #include "chrome/browser/memory/tab_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 LenientMockTaskRunner() {} 93 LenientMockTaskRunner() {}
94 MOCK_METHOD2(PostDelayedTask, 94 MOCK_METHOD2(PostDelayedTask,
95 bool(const tracked_objects::Location&, base::TimeDelta)); 95 bool(const tracked_objects::Location&, base::TimeDelta));
96 96
97 private: 97 private:
98 DISALLOW_COPY_AND_ASSIGN(LenientMockTaskRunner); 98 DISALLOW_COPY_AND_ASSIGN(LenientMockTaskRunner);
99 }; 99 };
100 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>; 100 using MockTaskRunner = testing::StrictMock<LenientMockTaskRunner>;
101 101
102 // Represents a pending task. 102 // Represents a pending task.
103 using Task = std::pair<base::TimeTicks, base::Closure>; 103 using Task = std::pair<base::TimeTicks, base::OnceClosure>;
104 104
105 // Comparator used for sorting Task objects. Can't use std::pair's default 105 // Comparator used for sorting Task objects. Can't use std::pair's default
106 // comparison operators because Closure's are comparable. 106 // comparison operators because Closure's are comparable.
107 struct TaskComparator { 107 struct TaskComparator {
108 bool operator()(const Task& t1, const Task& t2) const { 108 bool operator()(const Task& t1, const Task& t2) const {
109 // Reverse the sort order so this can be used with a min-heap. 109 // Reverse the sort order so this can be used with a min-heap.
110 return t1.first > t2.first; 110 return t1.first > t2.first;
111 } 111 }
112 }; 112 };
113 113
114 // A TaskRunner implementation that delegates to a MockTaskRunner for asserting 114 // A TaskRunner implementation that delegates to a MockTaskRunner for asserting
115 // on task insertion order, and which stores tasks for actual later execution. 115 // on task insertion order, and which stores tasks for actual later execution.
116 class TaskRunnerProxy : public base::TaskRunner { 116 class TaskRunnerProxy : public base::TaskRunner {
117 public: 117 public:
118 TaskRunnerProxy(MockTaskRunner* mock, 118 TaskRunnerProxy(MockTaskRunner* mock,
119 base::SimpleTestTickClock* clock) 119 base::SimpleTestTickClock* clock)
120 : mock_(mock), clock_(clock) {} 120 : mock_(mock), clock_(clock) {}
121 bool RunsTasksOnCurrentThread() const override { return true; } 121 bool RunsTasksOnCurrentThread() const override { return true; }
122 bool PostDelayedTask(const tracked_objects::Location& location, 122 bool PostDelayedTask(const tracked_objects::Location& location,
123 base::Closure closure, 123 base::OnceClosure closure,
124 base::TimeDelta delta) override { 124 base::TimeDelta delta) override {
125 mock_->PostDelayedTask(location, delta); 125 mock_->PostDelayedTask(location, delta);
126 base::TimeTicks when = clock_->NowTicks() + delta; 126 base::TimeTicks when = clock_->NowTicks() + delta;
127 tasks_.push_back(Task(when, std::move(closure))); 127 tasks_.push_back(Task(when, std::move(closure)));
128 // Use 'greater' comparator to make this a min heap. 128 // Use 'greater' comparator to make this a min heap.
129 std::push_heap(tasks_.begin(), tasks_.end(), TaskComparator()); 129 std::push_heap(tasks_.begin(), tasks_.end(), TaskComparator());
130 return true; 130 return true;
131 } 131 }
132 132
133 // Runs tasks up to the current time. Returns the number of tasks executed. 133 // Runs tasks up to the current time. Returns the number of tasks executed.
(...skipping 28 matching lines...) Expand all
162 162
163 size_t size() const { return tasks_.size(); } 163 size_t size() const { return tasks_.size(); }
164 164
165 private: 165 private:
166 ~TaskRunnerProxy() override {} 166 ~TaskRunnerProxy() override {}
167 167
168 MockTaskRunner* mock_; 168 MockTaskRunner* mock_;
169 base::SimpleTestTickClock* clock_; 169 base::SimpleTestTickClock* clock_;
170 170
171 // A min-heap of outstanding tasks. 171 // A min-heap of outstanding tasks.
172 using Task = std::pair<base::TimeTicks, base::Closure>; 172 using Task = std::pair<base::TimeTicks, base::OnceClosure>;
173 std::vector<Task> tasks_; 173 std::vector<Task> tasks_;
174 174
175 DISALLOW_COPY_AND_ASSIGN(TaskRunnerProxy); 175 DISALLOW_COPY_AND_ASSIGN(TaskRunnerProxy);
176 }; 176 };
177 177
178 enum TestIndicies { 178 enum TestIndicies {
179 kSelected, 179 kSelected,
180 kAutoDiscardable, 180 kAutoDiscardable,
181 kPinned, 181 kPinned,
182 kApp, 182 kApp,
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // Since tab2 is kept inactive and background for more than time-to-purge, 744 // Since tab2 is kept inactive and background for more than time-to-purge,
745 // tab2 should be purged. 745 // tab2 should be purged.
746 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged()); 746 EXPECT_TRUE(tab_manager.GetWebContentsData(tab2)->is_purged());
747 747
748 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. 748 // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED.
749 tabstrip.ActivateTabAt(1, true /* user_gesture */); 749 tabstrip.ActivateTabAt(1, true /* user_gesture */);
750 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged()); 750 EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->is_purged());
751 } 751 }
752 752
753 } // namespace memory 753 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/mock_user_manager.cc ('k') | chromecast/base/system_time_change_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698