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

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc

Issue 2258713004: Make tasks cancellable inside the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Various comment nits addressed Created 4 years, 4 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
Index: third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc b/third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc
index 3648fca554c36643cc9ae2093c833faea2adfb58..69023fd7a9553ee40a298db323682382edcb08fd 100644
--- a/third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc
+++ b/third_party/WebKit/Source/platform/scheduler/base/time_domain_unittest.cc
@@ -30,6 +30,7 @@ class MockTimeDomain : public TimeDomain {
~MockTimeDomain() override {}
+ using TimeDomain::CancelDelayedWork;
using TimeDomain::ClearExpiredWakeups;
using TimeDomain::NextScheduledRunTime;
using TimeDomain::NextScheduledTaskQueue;
@@ -196,6 +197,83 @@ TEST_F(TimeDomainTest, ClearExpiredWakeups) {
ASSERT_FALSE(time_domain_->NextScheduledRunTime(&next_run_time));
}
+TEST_F(TimeDomainTest, CancelDelayedWork) {
+ base::TimeDelta delay = base::TimeDelta::FromMilliseconds(50);
+ EXPECT_CALL(*time_domain_.get(), RequestWakeup(_, delay));
+ base::TimeTicks now = time_domain_->Now();
+ base::TimeTicks delayed_runtime = now + delay;
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime, now);
+
+ base::TimeTicks next_run_time;
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime, next_run_time);
+
+ time_domain_->CancelDelayedWork(task_queue_.get(), delayed_runtime);
+ EXPECT_FALSE(time_domain_->NextScheduledRunTime(&next_run_time));
+}
+
+TEST_F(TimeDomainTest, CancelDelayedWorkTaskQueueDoesntMatch) {
+ base::TimeDelta delay = base::TimeDelta::FromMilliseconds(50);
+ EXPECT_CALL(*time_domain_.get(), RequestWakeup(_, delay));
+ base::TimeTicks now = time_domain_->Now();
+ base::TimeTicks delayed_runtime = now + delay;
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime, now);
+
+ base::TimeTicks next_run_time;
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime, next_run_time);
+
+ time_domain_->CancelDelayedWork(nullptr, delayed_runtime);
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime, next_run_time);
+}
+
+TEST_F(TimeDomainTest, CancelDelayedWorkTwoWakeUpsCancelFirst) {
+ base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(50);
+ base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(150);
+ EXPECT_CALL(*time_domain_.get(), RequestWakeup(_, delay1));
+ base::TimeTicks now = time_domain_->Now();
+ base::TimeTicks delayed_runtime1 = now + delay1;
+ base::TimeTicks delayed_runtime2 = now + delay2;
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime1, now);
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime2, now);
+
+ base::TimeTicks next_run_time;
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime1, next_run_time);
+ Mock::VerifyAndClearExpectations(time_domain_.get());
+
+ EXPECT_CALL(*time_domain_.get(), RequestWakeup(_, delay2));
+ time_domain_->CancelDelayedWork(task_queue_.get(), delayed_runtime1);
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime2, next_run_time);
+}
+
+TEST_F(TimeDomainTest, CancelDelayedWorkTwoWakeUpsCancelSecond) {
+ base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(50);
+ base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(150);
+ EXPECT_CALL(*time_domain_.get(), RequestWakeup(_, delay1));
+ base::TimeTicks now = time_domain_->Now();
+ base::TimeTicks delayed_runtime1 = now + delay1;
+ base::TimeTicks delayed_runtime2 = now + delay2;
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime1, now);
+ time_domain_->ScheduleDelayedWork(task_queue_.get(), delayed_runtime2, now);
+
+ base::TimeTicks next_run_time;
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime1, next_run_time);
+ Mock::VerifyAndClearExpectations(time_domain_.get());
+
+ time_domain_->CancelDelayedWork(task_queue_.get(), delayed_runtime2);
+ ASSERT_TRUE(time_domain_->NextScheduledRunTime(&next_run_time));
+ EXPECT_EQ(delayed_runtime1, next_run_time);
+
+ time_domain_->SetNow(delayed_runtime1);
+ LazyNow lazy_now = time_domain_->CreateLazyNow();
+ time_domain_->UpdateWorkQueues(false, nullptr, lazy_now);
+ ASSERT_FALSE(time_domain_->NextScheduledRunTime(&next_run_time));
+}
+
namespace {
class MockObserver : public TimeDomain::Observer {
public:

Powered by Google App Engine
This is Rietveld 408576698