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

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

Issue 1895773002: Move responsiblity of tab suspending from renderer to TabManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix time Created 4 years, 8 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 static base::TimeDelta end_idle_when_hidden_delay() { 524 static base::TimeDelta end_idle_when_hidden_delay() {
525 return base::TimeDelta::FromMilliseconds( 525 return base::TimeDelta::FromMilliseconds(
526 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); 526 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis);
527 } 527 }
528 528
529 static base::TimeDelta idle_period_starvation_threshold() { 529 static base::TimeDelta idle_period_starvation_threshold() {
530 return base::TimeDelta::FromMilliseconds( 530 return base::TimeDelta::FromMilliseconds(
531 RendererSchedulerImpl::kIdlePeriodStarvationThresholdMillis); 531 RendererSchedulerImpl::kIdlePeriodStarvationThresholdMillis);
532 } 532 }
533 533
534 static base::TimeDelta suspend_timers_when_backgrounded_delay() {
535 return base::TimeDelta::FromMilliseconds(
536 RendererSchedulerImpl::kSuspendTimersWhenBackgroundedDelayMillis);
537 }
538
539 static base::TimeDelta rails_response_time() { 534 static base::TimeDelta rails_response_time() {
540 return base::TimeDelta::FromMilliseconds( 535 return base::TimeDelta::FromMilliseconds(
541 RendererSchedulerImpl::kRailsResponseTimeMillis); 536 RendererSchedulerImpl::kRailsResponseTimeMillis);
542 } 537 }
543 538
544 template <typename E> 539 template <typename E>
545 static void CallForEachEnumValue(E first, 540 static void CallForEachEnumValue(E first,
546 E last, 541 E last,
547 const char* (*function)(E)) { 542 const char* (*function)(E)) {
548 for (E val = first; val < last; 543 for (E val = first; val < last;
(...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 } 2078 }
2084 2079
2085 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { 2080 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) {
2086 scheduler_->Shutdown(); 2081 scheduler_->Shutdown();
2087 std::vector<std::string> run_order; 2082 std::vector<std::string> run_order;
2088 PostTestTasks(&run_order, "D1 C1"); 2083 PostTestTasks(&run_order, "D1 C1");
2089 RunUntilIdle(); 2084 RunUntilIdle();
2090 EXPECT_TRUE(run_order.empty()); 2085 EXPECT_TRUE(run_order.empty());
2091 } 2086 }
2092 2087
2093 TEST_F(RendererSchedulerImplTest, TestRendererBackgroundedTimerSuspension) {
2094 scheduler_->SetTimerQueueSuspensionWhenBackgroundedEnabled(true);
2095
2096 std::vector<std::string> run_order;
2097 PostTestTasks(&run_order, "T1 T2");
2098
2099 // The background signal will not immediately suspend the timer queue.
2100 scheduler_->OnRendererBackgrounded();
2101 RunUntilIdle();
2102 EXPECT_THAT(run_order,
2103 testing::ElementsAre(std::string("T1"), std::string("T2")));
2104
2105 run_order.clear();
2106 PostTestTasks(&run_order, "T3");
2107 RunUntilIdle();
2108 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T3")));
2109
2110 // Advance the time until after the scheduled timer queue suspension.
2111 run_order.clear();
2112 clock_->Advance(suspend_timers_when_backgrounded_delay() +
2113 base::TimeDelta::FromMilliseconds(10));
2114 RunUntilIdle();
2115 ASSERT_TRUE(run_order.empty());
2116
2117 // Timer tasks should be suspended until the foregrounded signal.
2118 PostTestTasks(&run_order, "T4 T5");
2119 RunUntilIdle();
2120 EXPECT_TRUE(run_order.empty());
2121
2122 scheduler_->OnRendererForegrounded();
2123 RunUntilIdle();
2124 EXPECT_THAT(run_order,
2125 testing::ElementsAre(std::string("T4"), std::string("T5")));
2126
2127 // Subsequent timer tasks should fire as usual.
2128 run_order.clear();
2129 PostTestTasks(&run_order, "T6");
2130 RunUntilIdle();
2131 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6")));
2132 }
2133
2134 TEST_F(RendererSchedulerImplTest, 2088 TEST_F(RendererSchedulerImplTest,
2135 ExpensiveLoadingTasksNotBlockedTillFirstBeginMainFrame) { 2089 ExpensiveLoadingTasksNotBlockedTillFirstBeginMainFrame) {
2136 std::vector<std::string> run_order; 2090 std::vector<std::string> run_order;
2137 2091
2138 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); 2092 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true);
2139 SimulateExpensiveTasks(loading_task_runner_); 2093 SimulateExpensiveTasks(loading_task_runner_);
2140 ForceTouchStartToBeExpectedSoon(); 2094 ForceTouchStartToBeExpectedSoon();
2141 PostTestTasks(&run_order, "L1 D1"); 2095 PostTestTasks(&run_order, "L1 D1");
2142 RunUntilIdle(); 2096 RunUntilIdle();
2143 2097
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 2754
2801 // Make sure TouchStart causes a policy change. 2755 // Make sure TouchStart causes a policy change.
2802 scheduler_->DidHandleInputEventOnCompositorThread( 2756 scheduler_->DidHandleInputEventOnCompositorThread(
2803 FakeInputEvent(blink::WebInputEvent::TouchStart), 2757 FakeInputEvent(blink::WebInputEvent::TouchStart),
2804 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 2758 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
2805 EXPECT_EQ(RendererScheduler::UseCase::TOUCHSTART, 2759 EXPECT_EQ(RendererScheduler::UseCase::TOUCHSTART,
2806 ForceUpdatePolicyAndGetCurrentUseCase()); 2760 ForceUpdatePolicyAndGetCurrentUseCase());
2807 } 2761 }
2808 2762
2809 } // namespace scheduler 2763 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698