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

Unified Diff: content/renderer/scheduler/renderer_scheduler_impl_unittest.cc

Issue 847883002: Reland "Throttle resource message requests during user interaction" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 5 years, 11 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: content/renderer/scheduler/renderer_scheduler_impl_unittest.cc
diff --git a/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc b/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc
index 869a742057ad6d83a6ed221534319a152bb7e47b..88af7db7cef69d110cf305a041ba98af0e3fe843 100644
--- a/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc
+++ b/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc
@@ -143,6 +143,18 @@ void PostingYieldingTestTask(
*should_yield_after = scheduler->ShouldYieldForHighPriorityWork();
}
+void AnticipationTestTask(RendererSchedulerImpl* scheduler,
+ bool simulate_input,
+ bool* should_anticipate_before,
+ bool* should_anticipate_after) {
+ *should_anticipate_before = scheduler->ShouldAnticipateHighPriorityWork();
+ if (simulate_input) {
+ scheduler->DidReceiveInputEventOnCompositorThread(
+ blink::WebInputEvent::GestureFlingStart);
+ }
+ *should_anticipate_after = scheduler->ShouldAnticipateHighPriorityWork();
+}
+
TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) {
int result = 0;
default_task_runner_->PostTask(FROM_HERE,
@@ -467,6 +479,45 @@ TEST_F(RendererSchedulerImplTest, TestCompositorPolicyEnds) {
std::string("D2"), std::string("C2")));
}
+TEST_F(RendererSchedulerImplTest, TestShouldAnticipate) {
+ bool should_anticipate_before = false;
+ bool should_anticipate_after = false;
+
+ bool simulate_input = false;
+ default_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
+ &should_anticipate_before, &should_anticipate_after));
+ RunUntilIdle();
+ // In its default state, without input receipt, the scheduler should indicate
+ // that no high-priority is anticipated.
+ EXPECT_FALSE(should_anticipate_before);
+ EXPECT_FALSE(should_anticipate_after);
+
+ simulate_input = true;
+ default_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
+ &should_anticipate_before, &should_anticipate_after));
+ RunUntilIdle();
+ // When input is received, the scheduler should indicate that high-priority
+ // work is anticipated.
+ EXPECT_FALSE(should_anticipate_before);
+ EXPECT_TRUE(should_anticipate_after);
+
+ clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(200));
+ simulate_input = false;
+ default_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
+ &should_anticipate_before, &should_anticipate_after));
+ RunUntilIdle();
+ // Without additional input, the scheduler should indicate that high-priority
+ // work is no longer anticipated.
+ EXPECT_FALSE(should_anticipate_before);
+ EXPECT_FALSE(should_anticipate_after);
+}
+
TEST_F(RendererSchedulerImplTest, TestShouldYield) {
bool should_yield_before = false;
bool should_yield_after = false;

Powered by Google App Engine
This is Rietveld 408576698