cc: Remove ResourceUpdateQueue and ResourceUpdateController.
[chromium-blink-merge.git] / cc / debug / micro_benchmark_controller_unittest.cc
blob61f34f4b77ea3000a4f44a5e143b805da9a37b4e
1 // Copyright 2013 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.
5 #include "base/callback.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "cc/debug/micro_benchmark.h"
8 #include "cc/debug/micro_benchmark_controller.h"
9 #include "cc/layers/layer.h"
10 #include "cc/test/fake_layer_tree_host.h"
11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_proxy.h"
13 #include "cc/test/test_task_graph_runner.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace cc {
17 namespace {
19 class MicroBenchmarkControllerTest : public testing::Test {
20 public:
21 MicroBenchmarkControllerTest()
22 : layer_tree_host_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
24 void SetUp() override {
25 impl_proxy_ = make_scoped_ptr(new FakeImplProxy);
26 layer_tree_host_impl_ = make_scoped_ptr(new FakeLayerTreeHostImpl(
27 impl_proxy_.get(), &shared_bitmap_manager_, &task_graph_runner_));
29 layer_tree_host_ = FakeLayerTreeHost::Create(&layer_tree_host_client_,
30 &task_graph_runner_);
31 layer_tree_host_->SetRootLayer(Layer::Create(LayerSettings()));
32 layer_tree_host_->InitializeForTesting(scoped_ptr<Proxy>(new FakeProxy));
35 void TearDown() override {
36 layer_tree_host_impl_ = nullptr;
37 layer_tree_host_ = nullptr;
38 impl_proxy_ = nullptr;
41 FakeLayerTreeHostClient layer_tree_host_client_;
42 TestTaskGraphRunner task_graph_runner_;
43 TestSharedBitmapManager shared_bitmap_manager_;
44 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
45 scoped_ptr<FakeLayerTreeHostImpl> layer_tree_host_impl_;
46 scoped_ptr<FakeImplProxy> impl_proxy_;
49 void Noop(scoped_ptr<base::Value> value) {
52 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) {
53 ++(*count);
56 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) {
57 int id = layer_tree_host_->ScheduleMicroBenchmark(
58 "non_existant_benchmark", nullptr, base::Bind(&Noop));
59 EXPECT_EQ(id, 0);
62 TEST_F(MicroBenchmarkControllerTest, CommitScheduled) {
63 EXPECT_FALSE(layer_tree_host_->needs_commit());
64 int id = layer_tree_host_->ScheduleMicroBenchmark(
65 "unittest_only_benchmark", nullptr, base::Bind(&Noop));
66 EXPECT_GT(id, 0);
67 EXPECT_TRUE(layer_tree_host_->needs_commit());
70 TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) {
71 int run_count = 0;
72 int id = layer_tree_host_->ScheduleMicroBenchmark(
73 "unittest_only_benchmark",
74 nullptr,
75 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
76 EXPECT_GT(id, 0);
78 layer_tree_host_->SetOutputSurfaceLostForTesting(false);
79 layer_tree_host_->UpdateLayers();
81 EXPECT_EQ(1, run_count);
84 TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) {
85 int run_count = 0;
86 int id = layer_tree_host_->ScheduleMicroBenchmark(
87 "unittest_only_benchmark",
88 nullptr,
89 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
90 EXPECT_GT(id, 0);
91 id = layer_tree_host_->ScheduleMicroBenchmark(
92 "unittest_only_benchmark",
93 nullptr,
94 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
95 EXPECT_GT(id, 0);
97 layer_tree_host_->SetOutputSurfaceLostForTesting(false);
98 layer_tree_host_->UpdateLayers();
100 EXPECT_EQ(2, run_count);
102 id = layer_tree_host_->ScheduleMicroBenchmark(
103 "unittest_only_benchmark",
104 nullptr,
105 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
106 EXPECT_GT(id, 0);
107 id = layer_tree_host_->ScheduleMicroBenchmark(
108 "unittest_only_benchmark",
109 nullptr,
110 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
111 EXPECT_GT(id, 0);
113 layer_tree_host_->UpdateLayers();
114 EXPECT_EQ(4, run_count);
116 layer_tree_host_->UpdateLayers();
117 EXPECT_EQ(4, run_count);
120 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) {
121 int run_count = 0;
122 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue);
123 settings->SetBoolean("run_benchmark_impl", true);
125 // Schedule a main thread benchmark.
126 int id = layer_tree_host_->ScheduleMicroBenchmark(
127 "unittest_only_benchmark",
128 settings.Pass(),
129 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
130 EXPECT_GT(id, 0);
132 // Schedule impl benchmarks. In production code, this is run in commit.
133 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks(
134 layer_tree_host_impl_.get());
136 // Now complete the commit (as if on the impl thread).
137 layer_tree_host_impl_->CommitComplete();
139 // Make sure all posted messages run.
140 base::MessageLoop::current()->RunUntilIdle();
142 EXPECT_EQ(1, run_count);
145 TEST_F(MicroBenchmarkControllerTest, SendMessage) {
146 // Send valid message to invalid benchmark (id = 0)
147 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue);
148 message->SetBoolean("can_handle", true);
149 bool message_handled =
150 layer_tree_host_->SendMessageToMicroBenchmark(0, message.Pass());
151 EXPECT_FALSE(message_handled);
153 // Schedule a benchmark
154 int run_count = 0;
155 int id = layer_tree_host_->ScheduleMicroBenchmark(
156 "unittest_only_benchmark",
157 nullptr,
158 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
159 EXPECT_GT(id, 0);
161 // Send valid message to valid benchmark
162 message = make_scoped_ptr(new base::DictionaryValue);
163 message->SetBoolean("can_handle", true);
164 message_handled =
165 layer_tree_host_->SendMessageToMicroBenchmark(id, message.Pass());
166 EXPECT_TRUE(message_handled);
168 // Send invalid message to valid benchmark
169 message = make_scoped_ptr(new base::DictionaryValue);
170 message->SetBoolean("can_handle", false);
171 message_handled =
172 layer_tree_host_->SendMessageToMicroBenchmark(id, message.Pass());
173 EXPECT_FALSE(message_handled);
176 } // namespace
177 } // namespace cc