[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 7 | #include "cc/texture_layer.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 8 | |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame^] | 9 | #include "cc/layer_tree_host.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 10 | #include "cc/test/fake_layer_tree_host_client.h" |
| 11 | #include "cc/test/web_compositor_initializer.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 12 | #include "testing/gmock/include/gmock/gmock.h" |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 14 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 15 | using namespace cc; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 16 | using ::testing::Mock; |
| 17 | using ::testing::_; |
| 18 | using ::testing::AtLeast; |
| 19 | using ::testing::AnyNumber; |
| 20 | |
| 21 | namespace { |
| 22 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 23 | class MockLayerImplTreeHost : public LayerTreeHost { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 24 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | MockLayerImplTreeHost() |
| 26 | : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 27 | { |
| 28 | initialize(); |
| 29 | } |
| 30 | |
| 31 | MOCK_METHOD0(acquireLayerTextures, void()); |
| 32 | |
| 33 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 34 | FakeLayerImplTreeHostClient m_fakeClient; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 38 | class TextureLayerTest : public testing::Test { |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 39 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 40 | TextureLayerTest() |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 41 | : m_compositorInitializer(0) |
| 42 | { |
| 43 | } |
| 44 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 45 | protected: |
| 46 | virtual void SetUp() |
| 47 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 48 | m_layerTreeHost.reset(new MockLayerImplTreeHost); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | virtual void TearDown() |
| 52 | { |
| 53 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 54 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
| 55 | |
| 56 | m_layerTreeHost->setRootLayer(0); |
[email protected] | 357b517 | 2012-10-18 17:39:33 | [diff] [blame] | 57 | m_layerTreeHost.reset(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 60 | scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost; |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 61 | private: |
| 62 | WebKitTests::WebCompositorInitializer m_compositorInitializer; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 63 | }; |
| 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | TEST_F(TextureLayerTest, syncImplWhenChangingTextureId) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 66 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 67 | scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 68 | ASSERT_TRUE(testLayer); |
| 69 | |
| 70 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
| 71 | m_layerTreeHost->setRootLayer(testLayer); |
| 72 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 73 | EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
| 74 | |
| 75 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 76 | testLayer->setTextureId(1); |
| 77 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 78 | |
| 79 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
| 80 | testLayer->setTextureId(2); |
| 81 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 82 | |
| 83 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
| 84 | testLayer->setTextureId(0); |
| 85 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 86 | } |
| 87 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 88 | TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 89 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 90 | scoped_refptr<Layer> rootLayer = Layer::create(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 91 | ASSERT_TRUE(rootLayer); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 92 | scoped_refptr<Layer> childLayer = Layer::create(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 93 | ASSERT_TRUE(childLayer); |
| 94 | rootLayer->addChild(childLayer); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 95 | scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 96 | ASSERT_TRUE(testLayer); |
| 97 | testLayer->setTextureId(0); |
| 98 | childLayer->addChild(testLayer); |
| 99 | |
| 100 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
| 101 | m_layerTreeHost->setRootLayer(rootLayer); |
| 102 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 103 | |
| 104 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 105 | testLayer->removeFromParent(); |
| 106 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 107 | |
| 108 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 109 | childLayer->addChild(testLayer); |
| 110 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 111 | |
| 112 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 113 | testLayer->setTextureId(1); |
| 114 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 115 | |
| 116 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
| 117 | testLayer->removeFromParent(); |
| 118 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 119 | } |
| 120 | |
| 121 | } // anonymous namespace |