| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/test/test_pending_task.h" | 9 #include "base/test/test_pending_task.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // Time to run, but a canceled task! | 255 // Time to run, but a canceled task! |
| 256 notifier.SetNow(notifier.Now() + delay); | 256 notifier.SetNow(notifier.Now() + delay); |
| 257 tasks[0].task.Run(); | 257 tasks[0].task.Run(); |
| 258 EXPECT_EQ(1, NotificationCount()); | 258 EXPECT_EQ(1, NotificationCount()); |
| 259 | 259 |
| 260 tasks = TakePendingTasks(); | 260 tasks = TakePendingTasks(); |
| 261 EXPECT_EQ(0u, tasks.size()); | 261 EXPECT_EQ(0u, tasks.size()); |
| 262 EXPECT_FALSE(notifier.HasPendingNotification()); | 262 EXPECT_FALSE(notifier.HasPendingNotification()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(DelayedUniqueNotifierTest, ShutdownWithScheduledTask) { |
| 266 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20); |
| 267 TestNotifier notifier( |
| 268 task_runner_.get(), |
| 269 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 270 delay); |
| 271 |
| 272 EXPECT_EQ(0, NotificationCount()); |
| 273 |
| 274 // Schedule for |delay| seconds from now. |
| 275 base::TimeTicks schedule_time = |
| 276 notifier.Now() + base::TimeDelta::FromInternalValue(10); |
| 277 notifier.SetNow(schedule_time); |
| 278 notifier.Schedule(); |
| 279 EXPECT_TRUE(notifier.HasPendingNotification()); |
| 280 |
| 281 // Shutdown the notifier. |
| 282 notifier.Shutdown(); |
| 283 |
| 284 // The task is still there, but... |
| 285 std::deque<base::TestPendingTask> tasks = TakePendingTasks(); |
| 286 ASSERT_EQ(1u, tasks.size()); |
| 287 |
| 288 // Running the task after shutdown does nothing since it's cancelled. |
| 289 tasks[0].task.Run(); |
| 290 EXPECT_EQ(0, NotificationCount()); |
| 291 |
| 292 tasks = TakePendingTasks(); |
| 293 EXPECT_EQ(0u, tasks.size()); |
| 294 |
| 295 // We are no longer able to schedule tasks. |
| 296 notifier.Schedule(); |
| 297 tasks = TakePendingTasks(); |
| 298 ASSERT_EQ(0u, tasks.size()); |
| 299 |
| 300 // Verify after the scheduled time happens there is still no task. |
| 301 notifier.SetNow(notifier.Now() + delay); |
| 302 tasks = TakePendingTasks(); |
| 303 ASSERT_EQ(0u, tasks.size()); |
| 304 } |
| 305 |
| 306 TEST_F(DelayedUniqueNotifierTest, ShutdownPreventsSchedule) { |
| 307 base::TimeDelta delay = base::TimeDelta::FromInternalValue(20); |
| 308 TestNotifier notifier( |
| 309 task_runner_.get(), |
| 310 base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)), |
| 311 delay); |
| 312 |
| 313 EXPECT_EQ(0, NotificationCount()); |
| 314 |
| 315 // Schedule for |delay| seconds from now. |
| 316 base::TimeTicks schedule_time = |
| 317 notifier.Now() + base::TimeDelta::FromInternalValue(10); |
| 318 notifier.SetNow(schedule_time); |
| 319 |
| 320 // Shutdown the notifier. |
| 321 notifier.Shutdown(); |
| 322 |
| 323 // Scheduling a task no longer does anything. |
| 324 notifier.Schedule(); |
| 325 std::deque<base::TestPendingTask> tasks = TakePendingTasks(); |
| 326 ASSERT_EQ(0u, tasks.size()); |
| 327 |
| 328 // Verify after the scheduled time happens there is still no task. |
| 329 notifier.SetNow(notifier.Now() + delay); |
| 330 tasks = TakePendingTasks(); |
| 331 ASSERT_EQ(0u, tasks.size()); |
| 332 } |
| 333 |
| 265 } // namespace | 334 } // namespace |
| 266 } // namespace cc | 335 } // namespace cc |
| OLD | NEW |