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

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl_unittest.cc

Issue 2080563003: (Merge m52) Fix a bug with throttling and timer queue suspension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 2970 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 EXPECT_EQ(expect_queue_enabled, 2981 EXPECT_EQ(expect_queue_enabled,
2982 scheduler_->TimerTaskRunner()->IsQueueEnabled()) 2982 scheduler_->TimerTaskRunner()->IsQueueEnabled())
2983 << "i = " << i; 2983 << "i = " << i;
2984 } 2984 }
2985 2985
2986 // Task is throttled but not completely blocked. 2986 // Task is throttled but not completely blocked.
2987 EXPECT_EQ(12u, count); 2987 EXPECT_EQ(12u, count);
2988 } 2988 }
2989 2989
2990 TEST_F(RendererSchedulerImplTest, 2990 TEST_F(RendererSchedulerImplTest,
2991 SYNCHRONIZED_GESTURE_TimerTaskThrottling_TimersSuspended) {
2992 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START);
2993
2994 base::TimeTicks first_throttled_run_time =
2995 ThrottlingHelper::ThrottledRunTime(clock_->NowTicks());
2996
2997 size_t count = 0;
2998 // With the compositor task taking 10ms, there is not enough time to run this
2999 // 7ms timer task in the 16ms frame.
3000 scheduler_->TimerTaskRunner()->PostTask(
3001 FROM_HERE, base::Bind(SlowCountingTask, &count, clock_.get(), 7,
3002 scheduler_->TimerTaskRunner()));
3003
3004 bool suspended = false;
3005 for (int i = 0; i < 1000; i++) {
3006 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create(
3007 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
3008 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL);
3009 begin_frame_args.on_critical_path = true;
3010 scheduler_->WillBeginFrame(begin_frame_args);
3011 scheduler_->DidHandleInputEventOnCompositorThread(
3012 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate),
3013 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
3014
3015 simulate_compositor_task_ran_ = false;
3016 compositor_task_runner_->PostTask(
3017 FROM_HERE,
3018 base::Bind(&RendererSchedulerImplTest::SimulateMainThreadCompositorTask,
3019 base::Unretained(this),
3020 base::TimeDelta::FromMilliseconds(10)));
3021
3022 mock_task_runner_->RunTasksWhile(
3023 base::Bind(&RendererSchedulerImplTest::SimulatedCompositorTaskPending,
3024 base::Unretained(this)));
3025 EXPECT_EQ(UseCase::SYNCHRONIZED_GESTURE, CurrentUseCase()) << "i = " << i;
3026
3027 // Before the policy is updated the queue will be enabled. Subsequently it
3028 // will be disabled until the throttled queue is pumped.
3029 bool expect_queue_enabled =
3030 (i == 0) || (clock_->NowTicks() > first_throttled_run_time);
3031 if (suspended)
3032 expect_queue_enabled = false;
3033 EXPECT_EQ(expect_queue_enabled,
3034 scheduler_->TimerTaskRunner()->IsQueueEnabled())
3035 << "i = " << i;
3036
3037 // After we've run any expensive tasks suspend the queue. The throttling
3038 // helper should /not/ re-enable this queue under any circumstances while
3039 // timers are suspended.
3040 if (count > 0 && !suspended) {
3041 EXPECT_EQ(2u, count);
3042 scheduler_->SuspendTimerQueue();
3043 suspended = true;
3044 }
3045 }
3046
3047 // Make sure the timer queue stayed suspended!
3048 EXPECT_EQ(2u, count);
3049 }
3050
3051 TEST_F(RendererSchedulerImplTest,
2991 SYNCHRONIZED_GESTURE_TimerTaskThrottling_task_not_expensive) { 3052 SYNCHRONIZED_GESTURE_TimerTaskThrottling_task_not_expensive) {
2992 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START); 3053 SimulateCompositorGestureStart(TouchEventPolicy::SEND_TOUCH_START);
2993 3054
2994 size_t count = 0; 3055 size_t count = 0;
2995 // With the compositor task taking 10ms, there is enough time to run this 6ms 3056 // With the compositor task taking 10ms, there is enough time to run this 6ms
2996 // timer task in the 16ms frame. 3057 // timer task in the 16ms frame.
2997 scheduler_->TimerTaskRunner()->PostTask( 3058 scheduler_->TimerTaskRunner()->PostTask(
2998 FROM_HERE, base::Bind(SlowCountingTask, &count, clock_.get(), 6, 3059 FROM_HERE, base::Bind(SlowCountingTask, &count, clock_.get(), 6,
2999 scheduler_->TimerTaskRunner())); 3060 scheduler_->TimerTaskRunner()));
3000 3061
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3204 base::Unretained(this))); 3265 base::Unretained(this)));
3205 EXPECT_EQ(UseCase::MAIN_THREAD_GESTURE, CurrentUseCase()) << "i = " << i; 3266 EXPECT_EQ(UseCase::MAIN_THREAD_GESTURE, CurrentUseCase()) << "i = " << i;
3206 } 3267 }
3207 3268
3208 EXPECT_EQ(TaskQueue::HIGH_PRIORITY, 3269 EXPECT_EQ(TaskQueue::HIGH_PRIORITY,
3209 scheduler_->CompositorTaskRunner()->GetQueuePriority()); 3270 scheduler_->CompositorTaskRunner()->GetQueuePriority());
3210 EXPECT_EQ(279u, run_order.size()); 3271 EXPECT_EQ(279u, run_order.size());
3211 } 3272 }
3212 3273
3213 } // namespace scheduler 3274 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/renderer_scheduler_impl.cc ('k') | components/scheduler/renderer/throttling_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698