blob: 16dbcebaba12cdd01498909cb7675ea376399757 [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
[email protected]d50c6862012-10-23 02:08:319#include "cc/layer_tree_host.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
[email protected]96baf3e2012-10-22 23:09:5523class MockLayerImplTreeHost : public LayerTreeHost {
[email protected]c0dd24c2012-08-30 23:25:2724public:
[email protected]96baf3e2012-10-22 23:09:5525 MockLayerImplTreeHost()
26 : LayerTreeHost(&m_fakeClient, LayerTreeSettings())
[email protected]c0dd24c2012-08-30 23:25:2727 {
28 initialize();
29 }
30
31 MOCK_METHOD0(acquireLayerTextures, void());
32
33private:
[email protected]96baf3e2012-10-22 23:09:5534 FakeLayerImplTreeHostClient m_fakeClient;
[email protected]c0dd24c2012-08-30 23:25:2735};
36
37
[email protected]96baf3e2012-10-22 23:09:5538class TextureLayerTest : public testing::Test {
[email protected]0f077a52012-09-08 01:45:2439public:
[email protected]96baf3e2012-10-22 23:09:5540 TextureLayerTest()
[email protected]0f077a52012-09-08 01:45:2441 : m_compositorInitializer(0)
42 {
43 }
44
[email protected]c0dd24c2012-08-30 23:25:2745protected:
46 virtual void SetUp()
47 {
[email protected]96baf3e2012-10-22 23:09:5548 m_layerTreeHost.reset(new MockLayerImplTreeHost);
[email protected]c0dd24c2012-08-30 23:25:2749 }
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]357b5172012-10-18 17:39:3357 m_layerTreeHost.reset();
[email protected]c0dd24c2012-08-30 23:25:2758 }
59
[email protected]96baf3e2012-10-22 23:09:5560 scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost;
[email protected]0f077a52012-09-08 01:45:2461private:
62 WebKitTests::WebCompositorInitializer m_compositorInitializer;
[email protected]c0dd24c2012-08-30 23:25:2763};
64
[email protected]96baf3e2012-10-22 23:09:5565TEST_F(TextureLayerTest, syncImplWhenChangingTextureId)
[email protected]c0dd24c2012-08-30 23:25:2766{
[email protected]96baf3e2012-10-22 23:09:5567 scoped_refptr<TextureLayer> testLayer = TextureLayer::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
[email protected]96baf3e2012-10-22 23:09:5588TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree)
[email protected]c0dd24c2012-08-30 23:25:2789{
[email protected]96baf3e2012-10-22 23:09:5590 scoped_refptr<Layer> rootLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:2791 ASSERT_TRUE(rootLayer);
[email protected]96baf3e2012-10-22 23:09:5592 scoped_refptr<Layer> childLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:2793 ASSERT_TRUE(childLayer);
94 rootLayer->addChild(childLayer);
[email protected]96baf3e2012-10-22 23:09:5595 scoped_refptr<TextureLayer> testLayer = TextureLayer::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