Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "cc/base/thread.h" | 10 #include "cc/base/thread.h" |
| 11 #include "cc/layers/texture_layer_client.h" | 11 #include "cc/layers/texture_layer_client.h" |
| 12 #include "cc/layers/texture_layer_impl.h" | 12 #include "cc/layers/texture_layer_impl.h" |
| 13 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
| 15 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
| 16 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "cc/trees/single_thread_proxy.h" | 19 #include "cc/trees/single_thread_proxy.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using ::testing::Mock; | 23 using ::testing::Mock; |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
| 26 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
| 27 | 27 |
| 28 #define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) do { \ | |
|
David Trainor- moved to gerrit
2013/04/18 20:33:44
I copied this from layer_unittest.cc. Is there a
enne (OOO)
2013/04/18 20:40:14
You could move it to layer_test_common.h if you wa
| |
| 29 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \ | |
| 30 code_to_test; \ | |
| 31 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | |
| 32 } while (false) | |
| 33 | |
| 28 namespace cc { | 34 namespace cc { |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 class MockLayerTreeHost : public LayerTreeHost { | 37 class MockLayerTreeHost : public LayerTreeHost { |
| 32 public: | 38 public: |
| 33 explicit MockLayerTreeHost(LayerTreeHostClient* client) | 39 explicit MockLayerTreeHost(LayerTreeHostClient* client) |
| 34 : LayerTreeHost(client, LayerTreeSettings()) { | 40 : LayerTreeHost(client, LayerTreeSettings()) { |
| 35 Initialize(scoped_ptr<Thread>(NULL)); | 41 Initialize(scoped_ptr<Thread>(NULL)); |
| 36 } | 42 } |
| 37 | 43 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 180 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 175 test_layer->SetTextureId(1); | 181 test_layer->SetTextureId(1); |
| 176 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 182 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 177 | 183 |
| 178 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 184 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
| 179 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 185 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 180 test_layer->RemoveFromParent(); | 186 test_layer->RemoveFromParent(); |
| 181 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 187 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 182 } | 188 } |
| 183 | 189 |
| 190 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | |
| 191 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | |
| 192 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | |
| 193 | |
| 194 // Test properties that should call SetNeedsCommit. All properties need to | |
| 195 // be set to new values in order for SetNeedsCommit to be called. | |
| 196 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); | |
| 197 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( | |
| 198 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); | |
| 199 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( | |
| 200 0.5f, 0.5f, 0.5f, 0.5f)); | |
| 201 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); | |
| 202 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1)); | |
| 203 | |
| 204 // Calling SetTextureId can call AcquireLayerTextures. | |
| 205 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | |
| 206 } | |
| 207 | |
| 184 class MockMailboxCallback { | 208 class MockMailboxCallback { |
| 185 public: | 209 public: |
| 186 MOCK_METHOD3(Release, void(const std::string& mailbox, | 210 MOCK_METHOD3(Release, void(const std::string& mailbox, |
| 187 unsigned sync_point, | 211 unsigned sync_point, |
| 188 bool lost_resource)); | 212 bool lost_resource)); |
| 189 }; | 213 }; |
| 190 | 214 |
| 191 struct CommonMailboxObjects { | 215 struct CommonMailboxObjects { |
| 192 CommonMailboxObjects() | 216 CommonMailboxObjects() |
| 193 : mailbox_name1_(64, '1'), | 217 : mailbox_name1_(64, '1'), |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 | 625 |
| 602 // Used on either thread, protected by lock_. | 626 // Used on either thread, protected by lock_. |
| 603 base::Lock lock_; | 627 base::Lock lock_; |
| 604 unsigned expected_used_textures_on_commit_; | 628 unsigned expected_used_textures_on_commit_; |
| 605 }; | 629 }; |
| 606 | 630 |
| 607 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerClientTest); | 631 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerClientTest); |
| 608 | 632 |
| 609 } // namespace | 633 } // namespace |
| 610 } // namespace cc | 634 } // namespace cc |
| OLD | NEW |