blob: f8491891106f9a3b510332a5d96fe16d80e6f368 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// 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]a8461d82012-10-16 21:11:147#include "cc/texture_layer.h"
[email protected]c0dd24c2012-08-30 23:25:278
9#include "CCLayerTreeHost.h"
[email protected]101441ce2012-10-16 01:45:0310#include "cc/test/fake_layer_tree_host_client.h"
11#include "cc/test/web_compositor_initializer.h"
[email protected]7f0c53db2012-10-02 00:23:1812#include "testing/gmock/include/gmock/gmock.h"
13#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2714
[email protected]9c88e562012-09-14 22:21:3015using namespace cc;
[email protected]c0dd24c2012-08-30 23:25:2716using ::testing::Mock;
17using ::testing::_;
18using ::testing::AtLeast;
19using ::testing::AnyNumber;
20
21namespace {
22
23class MockCCLayerTreeHost : public CCLayerTreeHost {
24public:
25 MockCCLayerTreeHost()
26 : CCLayerTreeHost(&m_fakeClient, CCLayerTreeSettings())
27 {
28 initialize();
29 }
30
31 MOCK_METHOD0(acquireLayerTextures, void());
32
33private:
34 FakeCCLayerTreeHostClient m_fakeClient;
35};
36
37
38class TextureLayerChromiumTest : public testing::Test {
[email protected]0f077a52012-09-08 01:45:2439public:
40 TextureLayerChromiumTest()
41 : m_compositorInitializer(0)
42 {
43 }
44
[email protected]c0dd24c2012-08-30 23:25:2745protected:
46 virtual void SetUp()
47 {
[email protected]c0dd24c2012-08-30 23:25:2748 m_layerTreeHost = adoptPtr(new MockCCLayerTreeHost);
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);
57 m_layerTreeHost.clear();
[email protected]c0dd24c2012-08-30 23:25:2758 }
59
60 OwnPtr<MockCCLayerTreeHost> m_layerTreeHost;
[email protected]0f077a52012-09-08 01:45:2461private:
62 WebKitTests::WebCompositorInitializer m_compositorInitializer;
[email protected]c0dd24c2012-08-30 23:25:2763};
64
65TEST_F(TextureLayerChromiumTest, syncImplWhenChangingTextureId)
66{
[email protected]d58499a2012-10-09 22:27:4767 scoped_refptr<TextureLayerChromium> testLayer = TextureLayerChromium::create(0);
[email protected]c0dd24c2012-08-30 23:25:2768 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
88TEST_F(TextureLayerChromiumTest, syncImplWhenRemovingFromTree)
89{
[email protected]d58499a2012-10-09 22:27:4790 scoped_refptr<LayerChromium> rootLayer = LayerChromium::create();
[email protected]c0dd24c2012-08-30 23:25:2791 ASSERT_TRUE(rootLayer);
[email protected]d58499a2012-10-09 22:27:4792 scoped_refptr<LayerChromium> childLayer = LayerChromium::create();
[email protected]c0dd24c2012-08-30 23:25:2793 ASSERT_TRUE(childLayer);
94 rootLayer->addChild(childLayer);
[email protected]d58499a2012-10-09 22:27:4795 scoped_refptr<TextureLayerChromium> testLayer = TextureLayerChromium::create(0);
[email protected]c0dd24c2012-08-30 23:25:2796 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