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

Side by Side 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: Pull out ThreadChecker fix Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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 "content/renderer/scheduler/renderer_scheduler_impl.h" 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "cc/output/begin_frame_args.h" 8 #include "cc/output/begin_frame_args.h"
9 #include "cc/test/ordered_simple_task_runner.h" 9 #include "cc/test/ordered_simple_task_runner.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 18 matching lines...) Expand all
29 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } 29 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); }
30 30
31 void EnableIdleTasks() { 31 void EnableIdleTasks() {
32 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 32 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
33 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 33 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(),
34 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 34 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
35 scheduler_->DidCommitFrameToCompositor(); 35 scheduler_->DidCommitFrameToCompositor();
36 } 36 }
37 37
38 protected: 38 protected:
39 static base::TimeDelta compositor_priority_after_touch_duration() {
40 return base::TimeDelta::FromMilliseconds(
41 RendererSchedulerImpl::kCompositorPriorityAfterTouchMillis);
42 }
43
39 scoped_refptr<cc::TestNowSource> clock_; 44 scoped_refptr<cc::TestNowSource> clock_;
40 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 45 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
41 46
42 scoped_ptr<RendererSchedulerImpl> scheduler_; 47 scoped_ptr<RendererSchedulerImpl> scheduler_;
43 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 48 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
44 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 49 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
45 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 50 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
46 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 51 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
47 52
48 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); 53 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 bool* should_yield_after) { 130 bool* should_yield_after) {
126 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); 131 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork();
127 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); 132 task_runner->PostTask(FROM_HERE, base::Bind(NullTask));
128 if (simulate_input) { 133 if (simulate_input) {
129 scheduler->DidReceiveInputEventOnCompositorThread( 134 scheduler->DidReceiveInputEventOnCompositorThread(
130 blink::WebInputEvent::GestureFlingStart); 135 blink::WebInputEvent::GestureFlingStart);
131 } 136 }
132 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); 137 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork();
133 } 138 }
134 139
140 void AnticipationTestTask(RendererSchedulerImpl* scheduler,
141 bool simulate_input,
142 bool* is_anticipated_before,
143 bool* is_anticipated_after) {
144 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated();
145 if (simulate_input) {
146 scheduler->DidReceiveInputEventOnCompositorThread(
147 blink::WebInputEvent::GestureFlingStart);
148 }
149 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated();
150 }
151
135 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { 152 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) {
136 int result = 0; 153 int result = 0;
137 default_task_runner_->PostTask(FROM_HERE, 154 default_task_runner_->PostTask(FROM_HERE,
138 base::Bind(OrderedTestTask, 1, &result)); 155 base::Bind(OrderedTestTask, 1, &result));
139 default_task_runner_->PostTask(FROM_HERE, 156 default_task_runner_->PostTask(FROM_HERE,
140 base::Bind(OrderedTestTask, 2, &result)); 157 base::Bind(OrderedTestTask, 2, &result));
141 default_task_runner_->PostTask(FROM_HERE, 158 default_task_runner_->PostTask(FROM_HERE,
142 base::Bind(OrderedTestTask, 3, &result)); 159 base::Bind(OrderedTestTask, 3, &result));
143 default_task_runner_->PostTask(FROM_HERE, 160 default_task_runner_->PostTask(FROM_HERE,
144 base::Bind(OrderedTestTask, 4, &result)); 161 base::Bind(OrderedTestTask, 4, &result));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 FROM_HERE, 509 FROM_HERE,
493 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); 510 base::Bind(&AppendToVectorTestTask, &order, std::string("C2")));
494 511
495 // Compositor policy mode should have ended now that the clock has advanced. 512 // Compositor policy mode should have ended now that the clock has advanced.
496 RunUntilIdle(); 513 RunUntilIdle();
497 EXPECT_THAT(order, 514 EXPECT_THAT(order,
498 testing::ElementsAre(std::string("D1"), std::string("C1"), 515 testing::ElementsAre(std::string("D1"), std::string("C1"),
499 std::string("D2"), std::string("C2"))); 516 std::string("D2"), std::string("C2")));
500 } 517 }
501 518
519 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) {
520 bool is_anticipated_before = false;
521 bool is_anticipated_after = false;
522
523 bool simulate_input = false;
524 default_task_runner_->PostTask(
525 FROM_HERE,
526 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
527 &is_anticipated_before, &is_anticipated_after));
528 RunUntilIdle();
529 // In its default state, without input receipt, the scheduler should indicate
530 // that no high-priority is anticipated.
531 EXPECT_FALSE(is_anticipated_before);
532 EXPECT_FALSE(is_anticipated_after);
533
534 simulate_input = true;
535 default_task_runner_->PostTask(
536 FROM_HERE,
537 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
538 &is_anticipated_before, &is_anticipated_after));
539 RunUntilIdle();
540 // When input is received, the scheduler should indicate that high-priority
541 // work is anticipated.
542 EXPECT_FALSE(is_anticipated_before);
543 EXPECT_TRUE(is_anticipated_after);
544
545 clock_->AdvanceNow(compositor_priority_after_touch_duration() * 2);
546 simulate_input = false;
547 default_task_runner_->PostTask(
548 FROM_HERE,
549 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
550 &is_anticipated_before, &is_anticipated_after));
551 RunUntilIdle();
552 // Without additional input, the scheduler should indicate that high-priority
553 // work is no longer anticipated.
554 EXPECT_FALSE(is_anticipated_before);
555 EXPECT_FALSE(is_anticipated_after);
556 }
557
502 TEST_F(RendererSchedulerImplTest, TestShouldYield) { 558 TEST_F(RendererSchedulerImplTest, TestShouldYield) {
503 bool should_yield_before = false; 559 bool should_yield_before = false;
504 bool should_yield_after = false; 560 bool should_yield_after = false;
505 561
506 default_task_runner_->PostTask( 562 default_task_runner_->PostTask(
507 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 563 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
508 default_task_runner_, false, &should_yield_before, 564 default_task_runner_, false, &should_yield_before,
509 &should_yield_after)); 565 &should_yield_after));
510 RunUntilIdle(); 566 RunUntilIdle();
511 // Posting to default runner shouldn't cause yielding. 567 // Posting to default runner shouldn't cause yielding.
(...skipping 13 matching lines...) Expand all
525 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 581 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
526 compositor_task_runner_, true, &should_yield_before, 582 compositor_task_runner_, true, &should_yield_before,
527 &should_yield_after)); 583 &should_yield_after));
528 RunUntilIdle(); 584 RunUntilIdle();
529 // We should be able to switch to compositor priority mid-task. 585 // We should be able to switch to compositor priority mid-task.
530 EXPECT_FALSE(should_yield_before); 586 EXPECT_FALSE(should_yield_before);
531 EXPECT_TRUE(should_yield_after); 587 EXPECT_TRUE(should_yield_after);
532 } 588 }
533 589
534 } // namespace content 590 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/scheduler/renderer_scheduler_impl.cc ('k') | content/renderer/scheduler/resource_dispatch_throttler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698