OLD | NEW |
| (Empty) |
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 | |
7 #include "TextureLayerChromium.h" | |
8 | |
9 #include "CCLayerTreeHost.h" | |
10 #include "FakeCCLayerTreeHostClient.h" | |
11 #include "WebCompositorInitializer.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using namespace cc; | |
16 using ::testing::Mock; | |
17 using ::testing::_; | |
18 using ::testing::AtLeast; | |
19 using ::testing::AnyNumber; | |
20 | |
21 namespace { | |
22 | |
23 class MockCCLayerTreeHost : public CCLayerTreeHost { | |
24 public: | |
25 MockCCLayerTreeHost() | |
26 : CCLayerTreeHost(&m_fakeClient, CCLayerTreeSettings()) | |
27 { | |
28 initialize(); | |
29 } | |
30 | |
31 MOCK_METHOD0(acquireLayerTextures, void()); | |
32 | |
33 private: | |
34 FakeCCLayerTreeHostClient m_fakeClient; | |
35 }; | |
36 | |
37 | |
38 class TextureLayerChromiumTest : public testing::Test { | |
39 public: | |
40 TextureLayerChromiumTest() | |
41 : m_compositorInitializer(0) | |
42 { | |
43 } | |
44 | |
45 protected: | |
46 virtual void SetUp() | |
47 { | |
48 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(); | |
58 } | |
59 | |
60 OwnPtr<MockCCLayerTreeHost> m_layerTreeHost; | |
61 private: | |
62 WebKitTests::WebCompositorInitializer m_compositorInitializer; | |
63 }; | |
64 | |
65 TEST_F(TextureLayerChromiumTest, syncImplWhenChangingTextureId) | |
66 { | |
67 scoped_refptr<TextureLayerChromium> testLayer = TextureLayerChromium::create
(0); | |
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 | |
88 TEST_F(TextureLayerChromiumTest, syncImplWhenRemovingFromTree) | |
89 { | |
90 scoped_refptr<LayerChromium> rootLayer = LayerChromium::create(); | |
91 ASSERT_TRUE(rootLayer); | |
92 scoped_refptr<LayerChromium> childLayer = LayerChromium::create(); | |
93 ASSERT_TRUE(childLayer); | |
94 rootLayer->addChild(childLayer); | |
95 scoped_refptr<TextureLayerChromium> testLayer = TextureLayerChromium::create
(0); | |
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 | |
OLD | NEW |