[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 5 | #include "cc/base/delayed_unique_notifier.h" |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 6 | #include "base/bind.h" |
| 7 | #include "base/bind_helpers.h" |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 8 | #include "base/containers/circular_deque.h" |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 9 | #include "base/test/test_pending_task.h" |
| 10 | #include "base/test/test_simple_task_runner.h" |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
| 13 | namespace cc { |
| 14 | namespace { |
| 15 | |
| 16 | class TestNotifier : public DelayedUniqueNotifier { |
| 17 | public: |
| 18 | TestNotifier(base::SequencedTaskRunner* task_runner, |
| 19 | const base::Closure& closure, |
| 20 | const base::TimeDelta& delay) |
| 21 | : DelayedUniqueNotifier(task_runner, closure, delay) {} |
Chris Watkins | f635329 | 2017-12-04 02:36:05 | [diff] [blame^] | 22 | ~TestNotifier() override = default; |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 23 | |
| 24 | // Overridden from DelayedUniqueNotifier: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 25 | base::TimeTicks Now() const override { return now_; } |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 26 | |
| 27 | void SetNow(base::TimeTicks now) { now_ = now; } |
| 28 | |
| 29 | private: |
| 30 | base::TimeTicks now_; |
| 31 | }; |
| 32 | |
| 33 | class DelayedUniqueNotifierTest : public testing::Test { |
| 34 | public: |
| 35 | DelayedUniqueNotifierTest() : notification_count_(0) {} |
| 36 | |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 37 | void SetUp() override { |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 38 | notification_count_ = 0; |
kylechar | 96f3eba | 2017-09-25 20:23:56 | [diff] [blame] | 39 | task_runner_ = base::MakeRefCounted<base::TestSimpleTaskRunner>(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void Notify() { ++notification_count_; } |
| 43 | |
| 44 | int NotificationCount() const { return notification_count_; } |
| 45 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 46 | base::circular_deque<base::TestPendingTask> TakePendingTasks() { |
tzik | 2d1f91c | 2016-10-04 03:58:05 | [diff] [blame] | 47 | return task_runner_->TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | protected: |
| 51 | int notification_count_; |
| 52 | scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 53 | }; |
| 54 | |
| 55 | TEST_F(DelayedUniqueNotifierTest, ZeroDelay) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 56 | base::TimeDelta delay; // Zero delay. |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 57 | TestNotifier notifier( |
dcheng | 80bc5e3c | 2014-08-26 03:54:18 | [diff] [blame] | 58 | task_runner_.get(), |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 59 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 60 | delay); |
| 61 | |
| 62 | EXPECT_EQ(0, NotificationCount()); |
| 63 | |
| 64 | // Basic schedule for |delay| from now. |
| 65 | base::TimeTicks schedule_time = |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 66 | base::TimeTicks() + base::TimeDelta::FromMicroseconds(10); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 67 | |
| 68 | notifier.SetNow(schedule_time); |
| 69 | notifier.Schedule(); |
| 70 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 71 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 72 | ASSERT_EQ(1u, tasks.size()); |
| 73 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 74 | |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 75 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 76 | EXPECT_EQ(1, NotificationCount()); |
| 77 | |
| 78 | // 5 schedules should result in only one run. |
| 79 | for (int i = 0; i < 5; ++i) |
| 80 | notifier.Schedule(); |
| 81 | |
| 82 | tasks = TakePendingTasks(); |
| 83 | ASSERT_EQ(1u, tasks.size()); |
| 84 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 85 | |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 86 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 87 | EXPECT_EQ(2, NotificationCount()); |
| 88 | } |
| 89 | |
| 90 | TEST_F(DelayedUniqueNotifierTest, SmallDelay) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 91 | base::TimeDelta delay = base::TimeDelta::FromMicroseconds(20); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 92 | TestNotifier notifier( |
dcheng | 80bc5e3c | 2014-08-26 03:54:18 | [diff] [blame] | 93 | task_runner_.get(), |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 94 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 95 | delay); |
| 96 | |
| 97 | EXPECT_EQ(0, NotificationCount()); |
| 98 | |
| 99 | // Basic schedule for |delay| from now (now: 30, run time: 50). |
| 100 | base::TimeTicks schedule_time = |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 101 | base::TimeTicks() + base::TimeDelta::FromMicroseconds(30); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 102 | |
| 103 | notifier.SetNow(schedule_time); |
| 104 | notifier.Schedule(); |
| 105 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 106 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 107 | |
| 108 | ASSERT_EQ(1u, tasks.size()); |
| 109 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 110 | |
| 111 | // It's not yet time to run, so we expect no notifications. |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 112 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 113 | EXPECT_EQ(0, NotificationCount()); |
| 114 | |
| 115 | tasks = TakePendingTasks(); |
| 116 | |
| 117 | ASSERT_EQ(1u, tasks.size()); |
| 118 | // Now the time should be delay minus whatever the value of now happens to be |
| 119 | // (now: 30, run time: 50). |
| 120 | base::TimeTicks scheduled_run_time = notifier.Now() + delay; |
| 121 | base::TimeTicks scheduled_delay = |
| 122 | base::TimeTicks() + (scheduled_run_time - notifier.Now()); |
| 123 | EXPECT_EQ(scheduled_delay, tasks[0].GetTimeToRun()); |
| 124 | |
| 125 | // Move closer to the run time (time: 49, run time: 50). |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 126 | notifier.SetNow(notifier.Now() + base::TimeDelta::FromMicroseconds(19)); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 127 | |
| 128 | // It's not yet time to run, so we expect no notifications. |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 129 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 130 | EXPECT_EQ(0, NotificationCount()); |
| 131 | |
| 132 | tasks = TakePendingTasks(); |
| 133 | ASSERT_EQ(1u, tasks.size()); |
| 134 | |
| 135 | // Now the time should be delay minus whatever the value of now happens to be. |
| 136 | scheduled_delay = base::TimeTicks() + (scheduled_run_time - notifier.Now()); |
| 137 | EXPECT_EQ(scheduled_delay, tasks[0].GetTimeToRun()); |
| 138 | |
| 139 | // Move to exactly the run time (time: 50, run time: 50). |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 140 | notifier.SetNow(notifier.Now() + base::TimeDelta::FromMicroseconds(1)); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 141 | |
| 142 | // It's time to run! |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 143 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 144 | EXPECT_EQ(1, NotificationCount()); |
| 145 | |
| 146 | tasks = TakePendingTasks(); |
| 147 | EXPECT_EQ(0u, tasks.size()); |
| 148 | } |
| 149 | |
| 150 | TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 151 | base::TimeDelta delay = base::TimeDelta::FromMicroseconds(20); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 152 | TestNotifier notifier( |
dcheng | 80bc5e3c | 2014-08-26 03:54:18 | [diff] [blame] | 153 | task_runner_.get(), |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 154 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 155 | delay); |
| 156 | |
| 157 | base::TimeTicks schedule_time; |
| 158 | // Move time 19 units forward and reschedule, expecting that we still need to |
| 159 | // run in |delay| time and we don't get a notification. |
| 160 | for (int i = 0; i < 10; ++i) { |
| 161 | EXPECT_EQ(0, NotificationCount()); |
| 162 | |
| 163 | // Move time forward 19 units. |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 164 | schedule_time = notifier.Now() + base::TimeDelta::FromMicroseconds(19); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 165 | notifier.SetNow(schedule_time); |
| 166 | notifier.Schedule(); |
| 167 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 168 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 169 | |
| 170 | ASSERT_EQ(1u, tasks.size()); |
| 171 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 172 | |
| 173 | // It's not yet time to run, so we expect no notifications. |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 174 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 175 | EXPECT_EQ(0, NotificationCount()); |
| 176 | } |
| 177 | |
| 178 | // Move time forward 20 units, expecting a notification. |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 179 | schedule_time = notifier.Now() + base::TimeDelta::FromMicroseconds(20); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 180 | notifier.SetNow(schedule_time); |
| 181 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 182 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 183 | |
| 184 | ASSERT_EQ(1u, tasks.size()); |
| 185 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 186 | |
| 187 | // Time to run! |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 188 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 189 | EXPECT_EQ(1, NotificationCount()); |
| 190 | } |
| 191 | |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 192 | TEST_F(DelayedUniqueNotifierTest, CancelAndHasPendingNotification) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 193 | base::TimeDelta delay = base::TimeDelta::FromMicroseconds(20); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 194 | TestNotifier notifier( |
dcheng | 80bc5e3c | 2014-08-26 03:54:18 | [diff] [blame] | 195 | task_runner_.get(), |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 196 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 197 | delay); |
| 198 | |
| 199 | EXPECT_EQ(0, NotificationCount()); |
| 200 | |
| 201 | // Schedule for |delay| seconds from now. |
| 202 | base::TimeTicks schedule_time = |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 203 | notifier.Now() + base::TimeDelta::FromMicroseconds(10); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 204 | notifier.SetNow(schedule_time); |
| 205 | notifier.Schedule(); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 206 | EXPECT_TRUE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 207 | |
| 208 | // Cancel the run. |
| 209 | notifier.Cancel(); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 210 | EXPECT_FALSE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 211 | |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 212 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 213 | |
| 214 | ASSERT_EQ(1u, tasks.size()); |
| 215 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 216 | |
| 217 | // Time to run, but a canceled task! |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 218 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 219 | EXPECT_EQ(0, NotificationCount()); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 220 | EXPECT_FALSE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 221 | |
| 222 | tasks = TakePendingTasks(); |
| 223 | EXPECT_EQ(0u, tasks.size()); |
| 224 | |
| 225 | notifier.Schedule(); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 226 | EXPECT_TRUE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 227 | tasks = TakePendingTasks(); |
| 228 | |
| 229 | ASSERT_EQ(1u, tasks.size()); |
| 230 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 231 | |
| 232 | // Advance the time. |
| 233 | notifier.SetNow(notifier.Now() + delay); |
| 234 | |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 235 | // This should run since it wasn't canceled. |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 236 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 237 | EXPECT_EQ(1, NotificationCount()); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 238 | EXPECT_FALSE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 239 | |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 240 | for (int i = 0; i < 10; ++i) { |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 241 | notifier.Schedule(); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 242 | EXPECT_TRUE(notifier.HasPendingNotification()); |
| 243 | notifier.Cancel(); |
| 244 | EXPECT_FALSE(notifier.HasPendingNotification()); |
| 245 | } |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 246 | |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 247 | tasks = TakePendingTasks(); |
| 248 | |
| 249 | ASSERT_EQ(1u, tasks.size()); |
| 250 | EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun()); |
| 251 | |
| 252 | // Time to run, but a canceled task! |
| 253 | notifier.SetNow(notifier.Now() + delay); |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 254 | std::move(tasks[0].task).Run(); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 255 | EXPECT_EQ(1, NotificationCount()); |
| 256 | |
| 257 | tasks = TakePendingTasks(); |
| 258 | EXPECT_EQ(0u, tasks.size()); |
[email protected] | 0a102872 | 2014-05-30 10:08:03 | [diff] [blame] | 259 | EXPECT_FALSE(notifier.HasPendingNotification()); |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 260 | } |
| 261 | |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 262 | TEST_F(DelayedUniqueNotifierTest, ShutdownWithScheduledTask) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 263 | base::TimeDelta delay = base::TimeDelta::FromMicroseconds(20); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 264 | TestNotifier notifier( |
| 265 | task_runner_.get(), |
| 266 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 267 | delay); |
| 268 | |
| 269 | EXPECT_EQ(0, NotificationCount()); |
| 270 | |
| 271 | // Schedule for |delay| seconds from now. |
| 272 | base::TimeTicks schedule_time = |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 273 | notifier.Now() + base::TimeDelta::FromMicroseconds(10); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 274 | notifier.SetNow(schedule_time); |
| 275 | notifier.Schedule(); |
| 276 | EXPECT_TRUE(notifier.HasPendingNotification()); |
| 277 | |
| 278 | // Shutdown the notifier. |
| 279 | notifier.Shutdown(); |
| 280 | |
| 281 | // The task is still there, but... |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 282 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 283 | ASSERT_EQ(1u, tasks.size()); |
| 284 | |
| 285 | // Running the task after shutdown does nothing since it's cancelled. |
tzik | a6f0007a | 2017-01-27 04:01:11 | [diff] [blame] | 286 | std::move(tasks[0].task).Run(); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 287 | EXPECT_EQ(0, NotificationCount()); |
| 288 | |
| 289 | tasks = TakePendingTasks(); |
| 290 | EXPECT_EQ(0u, tasks.size()); |
| 291 | |
| 292 | // We are no longer able to schedule tasks. |
| 293 | notifier.Schedule(); |
| 294 | tasks = TakePendingTasks(); |
| 295 | ASSERT_EQ(0u, tasks.size()); |
| 296 | |
| 297 | // Verify after the scheduled time happens there is still no task. |
| 298 | notifier.SetNow(notifier.Now() + delay); |
| 299 | tasks = TakePendingTasks(); |
| 300 | ASSERT_EQ(0u, tasks.size()); |
| 301 | } |
| 302 | |
| 303 | TEST_F(DelayedUniqueNotifierTest, ShutdownPreventsSchedule) { |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 304 | base::TimeDelta delay = base::TimeDelta::FromMicroseconds(20); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 305 | TestNotifier notifier( |
| 306 | task_runner_.get(), |
| 307 | base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 308 | delay); |
| 309 | |
| 310 | EXPECT_EQ(0, NotificationCount()); |
| 311 | |
| 312 | // Schedule for |delay| seconds from now. |
| 313 | base::TimeTicks schedule_time = |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 314 | notifier.Now() + base::TimeDelta::FromMicroseconds(10); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 315 | notifier.SetNow(schedule_time); |
| 316 | |
| 317 | // Shutdown the notifier. |
| 318 | notifier.Shutdown(); |
| 319 | |
| 320 | // Scheduling a task no longer does anything. |
| 321 | notifier.Schedule(); |
Brett Wilson | 55ff1475e | 2017-09-26 00:28:48 | [diff] [blame] | 322 | base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks(); |
danakj | 1a3c317 | 2014-10-29 18:24:49 | [diff] [blame] | 323 | ASSERT_EQ(0u, tasks.size()); |
| 324 | |
| 325 | // Verify after the scheduled time happens there is still no task. |
| 326 | notifier.SetNow(notifier.Now() + delay); |
| 327 | tasks = TakePendingTasks(); |
| 328 | ASSERT_EQ(0u, tasks.size()); |
| 329 | } |
| 330 | |
[email protected] | afb84fc | 2014-05-29 01:47:53 | [diff] [blame] | 331 | } // namespace |
| 332 | } // namespace cc |