blob: e1d8d1e2da1ef4b8378624176fc60c8e3d609722 [file] [log] [blame]
[email protected]666d7cf2013-10-12 01:30:291// 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.
4
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/resources/resource_update_queue.h"
11#include "cc/test/fake_layer_tree_host.h"
12#include "cc/test/fake_proxy.h"
13#include "testing/gtest/include/gtest/gtest.h"
14
15namespace cc {
16namespace {
17
18class MicroBenchmarkControllerTest : public testing::Test {
19 public:
20 virtual void SetUp() {
21 layer_tree_host_ = FakeLayerTreeHost::Create();
22 layer_tree_host_->SetRootLayer(Layer::Create());
23 layer_tree_host_->InitializeForTesting(
24 scoped_ptr<Proxy>(new FakeProxy));
25 }
26
27 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
28};
29
30void Noop(scoped_ptr<base::Value> value) {
31}
32
33void IncrementCallCount(int* count, scoped_ptr<base::Value> value) {
34 ++(*count);
35}
36
37TEST_F(MicroBenchmarkControllerTest, ScheduleFail) {
38 bool result = layer_tree_host_->ScheduleMicroBenchmark(
[email protected]752e2cf2013-10-21 21:41:1539 "non_existant_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop));
[email protected]666d7cf2013-10-12 01:30:2940 EXPECT_FALSE(result);
41}
42
43TEST_F(MicroBenchmarkControllerTest, CommitScheduled) {
44 EXPECT_FALSE(layer_tree_host_->needs_commit());
45 bool result = layer_tree_host_->ScheduleMicroBenchmark(
[email protected]752e2cf2013-10-21 21:41:1546 "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop));
[email protected]666d7cf2013-10-12 01:30:2947 EXPECT_TRUE(result);
48 EXPECT_TRUE(layer_tree_host_->needs_commit());
49}
50
51TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) {
52 int run_count = 0;
53 bool result = layer_tree_host_->ScheduleMicroBenchmark(
54 "unittest_only_benchmark",
[email protected]752e2cf2013-10-21 21:41:1555 scoped_ptr<base::Value>(),
[email protected]666d7cf2013-10-12 01:30:2956 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
57 EXPECT_TRUE(result);
58
59 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
60 layer_tree_host_->SetOutputSurfaceLostForTesting(false);
61 layer_tree_host_->UpdateLayers(queue.get());
62
63 EXPECT_EQ(1, run_count);
64}
65
66TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) {
67 int run_count = 0;
68 bool result = layer_tree_host_->ScheduleMicroBenchmark(
69 "unittest_only_benchmark",
[email protected]752e2cf2013-10-21 21:41:1570 scoped_ptr<base::Value>(),
[email protected]666d7cf2013-10-12 01:30:2971 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
72 EXPECT_TRUE(result);
73 result = layer_tree_host_->ScheduleMicroBenchmark(
74 "unittest_only_benchmark",
[email protected]752e2cf2013-10-21 21:41:1575 scoped_ptr<base::Value>(),
[email protected]666d7cf2013-10-12 01:30:2976 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
77 EXPECT_TRUE(result);
78
79 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
80 layer_tree_host_->SetOutputSurfaceLostForTesting(false);
81 layer_tree_host_->UpdateLayers(queue.get());
82
83 EXPECT_EQ(2, run_count);
84
85 result = layer_tree_host_->ScheduleMicroBenchmark(
86 "unittest_only_benchmark",
[email protected]752e2cf2013-10-21 21:41:1587 scoped_ptr<base::Value>(),
[email protected]666d7cf2013-10-12 01:30:2988 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
89 EXPECT_TRUE(result);
90 result = layer_tree_host_->ScheduleMicroBenchmark(
91 "unittest_only_benchmark",
[email protected]752e2cf2013-10-21 21:41:1592 scoped_ptr<base::Value>(),
[email protected]666d7cf2013-10-12 01:30:2993 base::Bind(&IncrementCallCount, base::Unretained(&run_count)));
94 EXPECT_TRUE(result);
95
96 layer_tree_host_->UpdateLayers(queue.get());
97 EXPECT_EQ(4, run_count);
98
99 layer_tree_host_->UpdateLayers(queue.get());
100 EXPECT_EQ(4, run_count);
101}
102
103} // namespace
104} // namespace cc