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

Unified Diff: cc/base/delayed_unique_notifier_unittest.cc

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/base/delayed_unique_notifier.cc ('k') | cc/cc_tests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/delayed_unique_notifier_unittest.cc
diff --git a/cc/base/delayed_unique_notifier_unittest.cc b/cc/base/delayed_unique_notifier_unittest.cc
index 41cde83dab6ecc04359b47e073bdb22be24406a1..3e41d321f3e89060b16d8d56957af2c976d88dd2 100644
--- a/cc/base/delayed_unique_notifier_unittest.cc
+++ b/cc/base/delayed_unique_notifier_unittest.cc
@@ -262,5 +262,74 @@ TEST_F(DelayedUniqueNotifierTest, CancelAndHasPendingNotification) {
EXPECT_FALSE(notifier.HasPendingNotification());
}
+TEST_F(DelayedUniqueNotifierTest, ShutdownWithScheduledTask) {
+ base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
+ TestNotifier notifier(
+ task_runner_.get(),
+ base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
+ delay);
+
+ EXPECT_EQ(0, NotificationCount());
+
+ // Schedule for |delay| seconds from now.
+ base::TimeTicks schedule_time =
+ notifier.Now() + base::TimeDelta::FromInternalValue(10);
+ notifier.SetNow(schedule_time);
+ notifier.Schedule();
+ EXPECT_TRUE(notifier.HasPendingNotification());
+
+ // Shutdown the notifier.
+ notifier.Shutdown();
+
+ // The task is still there, but...
+ std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ ASSERT_EQ(1u, tasks.size());
+
+ // Running the task after shutdown does nothing since it's cancelled.
+ tasks[0].task.Run();
+ EXPECT_EQ(0, NotificationCount());
+
+ tasks = TakePendingTasks();
+ EXPECT_EQ(0u, tasks.size());
+
+ // We are no longer able to schedule tasks.
+ notifier.Schedule();
+ tasks = TakePendingTasks();
+ ASSERT_EQ(0u, tasks.size());
+
+ // Verify after the scheduled time happens there is still no task.
+ notifier.SetNow(notifier.Now() + delay);
+ tasks = TakePendingTasks();
+ ASSERT_EQ(0u, tasks.size());
+}
+
+TEST_F(DelayedUniqueNotifierTest, ShutdownPreventsSchedule) {
+ base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
+ TestNotifier notifier(
+ task_runner_.get(),
+ base::Bind(&DelayedUniqueNotifierTest::Notify, base::Unretained(this)),
+ delay);
+
+ EXPECT_EQ(0, NotificationCount());
+
+ // Schedule for |delay| seconds from now.
+ base::TimeTicks schedule_time =
+ notifier.Now() + base::TimeDelta::FromInternalValue(10);
+ notifier.SetNow(schedule_time);
+
+ // Shutdown the notifier.
+ notifier.Shutdown();
+
+ // Scheduling a task no longer does anything.
+ notifier.Schedule();
+ std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ ASSERT_EQ(0u, tasks.size());
+
+ // Verify after the scheduled time happens there is still no task.
+ notifier.SetNow(notifier.Now() + delay);
+ tasks = TakePendingTasks();
+ ASSERT_EQ(0u, tasks.size());
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/base/delayed_unique_notifier.cc ('k') | cc/cc_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698