| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "cc/debug/micro_benchmark.h" | 7 #include "cc/debug/micro_benchmark.h" |
| 8 #include "cc/debug/micro_benchmark_controller.h" | 8 #include "cc/debug/micro_benchmark_controller.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/resources/resource_update_queue.h" | 10 #include "cc/resources/resource_update_queue.h" |
| 11 #include "cc/test/fake_layer_tree_host.h" | 11 #include "cc/test/fake_layer_tree_host.h" |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" |
| 12 #include "cc/test/fake_proxy.h" | 13 #include "cc/test/fake_proxy.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class MicroBenchmarkControllerTest : public testing::Test { | 19 class MicroBenchmarkControllerTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 virtual void SetUp() { | 21 virtual void SetUp() OVERRIDE { |
| 22 impl_proxy_ = make_scoped_ptr(new FakeImplProxy); |
| 23 layer_tree_host_impl_ = |
| 24 make_scoped_ptr(new FakeLayerTreeHostImpl(impl_proxy_.get())); |
| 25 |
| 21 layer_tree_host_ = FakeLayerTreeHost::Create(); | 26 layer_tree_host_ = FakeLayerTreeHost::Create(); |
| 22 layer_tree_host_->SetRootLayer(Layer::Create()); | 27 layer_tree_host_->SetRootLayer(Layer::Create()); |
| 23 layer_tree_host_->InitializeForTesting( | 28 layer_tree_host_->InitializeForTesting(scoped_ptr<Proxy>(new FakeProxy)); |
| 24 scoped_ptr<Proxy>(new FakeProxy)); | 29 } |
| 30 |
| 31 virtual void TearDown() OVERRIDE { |
| 32 layer_tree_host_impl_.reset(); |
| 33 layer_tree_host_.reset(); |
| 34 impl_proxy_.reset(); |
| 25 } | 35 } |
| 26 | 36 |
| 27 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | 37 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 38 scoped_ptr<FakeLayerTreeHostImpl> layer_tree_host_impl_; |
| 39 scoped_ptr<FakeImplProxy> impl_proxy_; |
| 28 }; | 40 }; |
| 29 | 41 |
| 30 void Noop(scoped_ptr<base::Value> value) { | 42 void Noop(scoped_ptr<base::Value> value) { |
| 31 } | 43 } |
| 32 | 44 |
| 33 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { | 45 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { |
| 34 ++(*count); | 46 ++(*count); |
| 35 } | 47 } |
| 36 | 48 |
| 37 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { | 49 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 105 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 94 EXPECT_TRUE(result); | 106 EXPECT_TRUE(result); |
| 95 | 107 |
| 96 layer_tree_host_->UpdateLayers(queue.get()); | 108 layer_tree_host_->UpdateLayers(queue.get()); |
| 97 EXPECT_EQ(4, run_count); | 109 EXPECT_EQ(4, run_count); |
| 98 | 110 |
| 99 layer_tree_host_->UpdateLayers(queue.get()); | 111 layer_tree_host_->UpdateLayers(queue.get()); |
| 100 EXPECT_EQ(4, run_count); | 112 EXPECT_EQ(4, run_count); |
| 101 } | 113 } |
| 102 | 114 |
| 115 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { |
| 116 int run_count = 0; |
| 117 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue); |
| 118 settings->SetBoolean("run_benchmark_impl", true); |
| 119 |
| 120 // Schedule a main thread benchmark. |
| 121 bool result = layer_tree_host_->ScheduleMicroBenchmark( |
| 122 "unittest_only_benchmark", |
| 123 settings.PassAs<base::Value>(), |
| 124 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 125 EXPECT_TRUE(result); |
| 126 |
| 127 // Schedule impl benchmarks. In production code, this is run in commit. |
| 128 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( |
| 129 layer_tree_host_impl_.get()); |
| 130 |
| 131 // Now complete the commit (as if on the impl thread). |
| 132 layer_tree_host_impl_->CommitComplete(); |
| 133 |
| 134 // Make sure all posted messages run. |
| 135 base::MessageLoop::current()->RunUntilIdle(); |
| 136 |
| 137 EXPECT_EQ(1, run_count); |
| 138 } |
| 139 |
| 103 } // namespace | 140 } // namespace |
| 104 } // namespace cc | 141 } // namespace cc |
| OLD | NEW |