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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/budget_pool_unittest.cc

Issue 2741473002: [scheduler] Move TimeBudgetPool to a separate file. (Closed)
Patch Set: Addressed comments from alexclarke@ Created 3 years, 9 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/scheduler/renderer/task_queue_throttler.h"
6
7 #include <stddef.h>
8
9 #include <memory>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
14 #include "base/test/simple_test_tick_clock.h"
15 #include "cc/test/ordered_simple_task_runner.h"
16 #include "platform/scheduler/base/task_queue_impl.h"
17 #include "platform/scheduler/base/test_time_source.h"
18 #include "platform/scheduler/child/scheduler_tqm_delegate_for_test.h"
19 #include "platform/scheduler/renderer/budget_pool.h"
20 #include "platform/scheduler/renderer/renderer_scheduler_impl.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 namespace blink {
25 namespace scheduler {
26
27 class BudgetPoolTest : public testing::Test {
28 public:
29 BudgetPoolTest() {}
30 ~BudgetPoolTest() override {}
31
32 void SetUp() override {
33 clock_.reset(new base::SimpleTestTickClock());
34 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
35 mock_task_runner_ =
36 make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_.get(), true));
37 delegate_ = SchedulerTqmDelegateForTest::Create(
38 mock_task_runner_, base::MakeUnique<TestTimeSource>(clock_.get()));
39 scheduler_.reset(new RendererSchedulerImpl(delegate_));
40 task_queue_throttler_ = scheduler_->task_queue_throttler();
41 }
42
43 void TearDown() override {
44 scheduler_->Shutdown();
45 scheduler_.reset();
46 }
47
48 protected:
49 std::unique_ptr<base::SimpleTestTickClock> clock_;
50 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
51 scoped_refptr<SchedulerTqmDelegate> delegate_;
52 std::unique_ptr<RendererSchedulerImpl> scheduler_;
53 TaskQueueThrottler* task_queue_throttler_; // NOT OWNED
54
55 DISALLOW_COPY_AND_ASSIGN(BudgetPoolTest);
56 };
57
58 TEST_F(BudgetPoolTest, CPUTimeBudgetPool) {
59 CPUTimeBudgetPool* pool = task_queue_throttler_->CreateCPUTimeBudgetPool(
60 "test", base::nullopt, base::nullopt);
61
62 base::TimeTicks time_zero = clock_->NowTicks();
63
64 pool->SetTimeBudgetRecoveryRate(time_zero, 0.1);
65
66 EXPECT_TRUE(pool->HasEnoughBudgetToRun(time_zero));
67 EXPECT_EQ(time_zero, pool->GetNextAllowedRunTime());
68
69 // Run an expensive task and make sure that we're throttled.
70 pool->RecordTaskRunTime(time_zero,
71 time_zero + base::TimeDelta::FromMilliseconds(100));
72
73 EXPECT_FALSE(pool->HasEnoughBudgetToRun(
74 time_zero + base::TimeDelta::FromMilliseconds(500)));
75 EXPECT_EQ(time_zero + base::TimeDelta::FromMilliseconds(1000),
76 pool->GetNextAllowedRunTime());
77 EXPECT_TRUE(pool->HasEnoughBudgetToRun(
78 time_zero + base::TimeDelta::FromMilliseconds(1000)));
79
80 // Run a cheap task and make sure that it doesn't affect anything.
81 EXPECT_TRUE(pool->HasEnoughBudgetToRun(
82 time_zero + base::TimeDelta::FromMilliseconds(2000)));
83 pool->RecordTaskRunTime(time_zero + base::TimeDelta::FromMilliseconds(2000),
84 time_zero + base::TimeDelta::FromMilliseconds(2020));
85 EXPECT_TRUE(pool->HasEnoughBudgetToRun(
86 time_zero + base::TimeDelta::FromMilliseconds(2020)));
87 EXPECT_EQ(time_zero + base::TimeDelta::FromMilliseconds(2020),
88 pool->GetNextAllowedRunTime());
89
90 pool->Close();
91 }
92
93 } // namespace scheduler
94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698