OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 <public/WebLayer.h> | 5 #include <public/WebLayer.h> |
6 | 6 |
7 #include "cc/thread.h" | 7 #include "cc/thread.h" |
8 #include "cc/test/compositor_fake_web_graphics_context_3d.h" | 8 #include "cc/test/compositor_fake_web_graphics_context_3d.h" |
9 #include "web_layer_impl.h" | 9 #include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h" |
10 #include "web_layer_tree_view_impl.h" | 10 #include "webkit/compositor_bindings/web_layer_impl.h" |
11 #include "web_layer_tree_view_test_common.h" | 11 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h" |
| 12 #include "webkit/compositor_bindings/web_content_layer_impl.h" |
| 13 #include "webkit/compositor_bindings/web_solid_color_layer_impl.h" |
| 14 #include "webkit/compositor_bindings/web_external_texture_layer_impl.h" |
12 #include <public/WebContentLayer.h> | 15 #include <public/WebContentLayer.h> |
13 #include <public/WebContentLayerClient.h> | 16 #include <public/WebContentLayerClient.h> |
14 #include <public/WebExternalTextureLayer.h> | 17 #include <public/WebExternalTextureLayer.h> |
15 #include <public/WebFloatPoint.h> | 18 #include <public/WebFloatPoint.h> |
16 #include <public/WebFloatRect.h> | 19 #include <public/WebFloatRect.h> |
17 #include <public/WebLayerScrollClient.h> | 20 #include <public/WebLayerScrollClient.h> |
18 #include <public/WebLayerTreeView.h> | 21 #include <public/WebLayerTreeView.h> |
19 #include <public/WebLayerTreeViewClient.h> | 22 #include <public/WebLayerTreeViewClient.h> |
20 #include <public/WebRect.h> | 23 #include <public/WebRect.h> |
21 #include <public/WebSize.h> | 24 #include <public/WebSize.h> |
(...skipping 20 matching lines...) Expand all Loading... |
42 }; | 45 }; |
43 | 46 |
44 class WebLayerTest : public Test { | 47 class WebLayerTest : public Test { |
45 public: | 48 public: |
46 WebLayerTest() | 49 WebLayerTest() |
47 { | 50 { |
48 } | 51 } |
49 | 52 |
50 virtual void SetUp() | 53 virtual void SetUp() |
51 { | 54 { |
52 m_rootLayer.reset(WebLayer::create()); | 55 m_rootLayer.reset(new WebLayerImpl); |
53 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 56 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
54 m_view.reset(new WebLayerTreeViewImpl(&m_client)); | 57 m_view.reset(new WebLayerTreeViewImpl(&m_client)); |
55 EXPECT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), scoped_ptr<
cc::Thread>(NULL))); | 58 EXPECT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), scoped_ptr<
cc::Thread>(NULL))); |
56 m_view->setRootLayer(*m_rootLayer); | 59 m_view->setRootLayer(*m_rootLayer); |
57 EXPECT_TRUE(m_view); | 60 EXPECT_TRUE(m_view); |
58 Mock::VerifyAndClearExpectations(&m_client); | 61 Mock::VerifyAndClearExpectations(&m_client); |
59 } | 62 } |
60 | 63 |
61 virtual void TearDown() | 64 virtual void TearDown() |
62 { | 65 { |
63 // We may get any number of scheduleComposite calls during shutdown. | 66 // We may get any number of scheduleComposite calls during shutdown. |
64 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 67 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
65 m_rootLayer.reset(); | 68 m_rootLayer.reset(); |
66 m_view.reset(); | 69 m_view.reset(); |
67 } | 70 } |
68 | 71 |
69 protected: | 72 protected: |
70 MockWebLayerTreeViewClient m_client; | 73 MockWebLayerTreeViewClient m_client; |
71 scoped_ptr<WebLayer> m_rootLayer; | 74 scoped_ptr<WebLayerImpl> m_rootLayer; |
72 scoped_ptr<WebLayerTreeViewImpl> m_view; | 75 scoped_ptr<WebLayerTreeViewImpl> m_view; |
73 }; | 76 }; |
74 | 77 |
75 // Tests that the client gets called to ask for a composite if we change the | 78 // Tests that the client gets called to ask for a composite if we change the |
76 // fields. | 79 // fields. |
77 TEST_F(WebLayerTest, Client) | 80 TEST_F(WebLayerTest, Client) |
78 { | 81 { |
79 // Base layer. | 82 // Base layer. |
80 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 83 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
81 scoped_ptr<WebLayer> layer(WebLayer::create()); | 84 scoped_ptr<WebLayer> layer(new WebLayerImpl); |
82 layer->setDrawsContent(true); | 85 layer->setDrawsContent(true); |
83 m_rootLayer->addChild(layer.get()); | 86 m_rootLayer->addChild(layer.get()); |
84 Mock::VerifyAndClearExpectations(&m_client); | 87 Mock::VerifyAndClearExpectations(&m_client); |
85 | 88 |
86 WebFloatPoint point(3, 4); | 89 WebFloatPoint point(3, 4); |
87 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 90 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
88 layer->setAnchorPoint(point); | 91 layer->setAnchorPoint(point); |
89 Mock::VerifyAndClearExpectations(&m_client); | 92 Mock::VerifyAndClearExpectations(&m_client); |
90 EXPECT_EQ(point, layer->anchorPoint()); | 93 EXPECT_EQ(point, layer->anchorPoint()); |
91 | 94 |
92 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 95 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
93 float anchorZ = 5; | 96 float anchorZ = 5; |
94 layer->setAnchorPointZ(anchorZ); | 97 layer->setAnchorPointZ(anchorZ); |
95 Mock::VerifyAndClearExpectations(&m_client); | 98 Mock::VerifyAndClearExpectations(&m_client); |
96 EXPECT_EQ(anchorZ, layer->anchorPointZ()); | 99 EXPECT_EQ(anchorZ, layer->anchorPointZ()); |
97 | 100 |
98 WebSize size(7, 8); | 101 WebSize size(7, 8); |
99 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 102 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
100 layer->setBounds(size); | 103 layer->setBounds(size); |
101 Mock::VerifyAndClearExpectations(&m_client); | 104 Mock::VerifyAndClearExpectations(&m_client); |
102 EXPECT_EQ(size, layer->bounds()); | 105 EXPECT_EQ(size, layer->bounds()); |
103 | 106 |
104 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 107 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
105 layer->setMasksToBounds(true); | 108 layer->setMasksToBounds(true); |
106 Mock::VerifyAndClearExpectations(&m_client); | 109 Mock::VerifyAndClearExpectations(&m_client); |
107 EXPECT_TRUE(layer->masksToBounds()); | 110 EXPECT_TRUE(layer->masksToBounds()); |
108 | 111 |
109 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 112 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
110 scoped_ptr<WebLayer> otherLayer(WebLayer::create()); | 113 scoped_ptr<WebLayer> otherLayer(new WebLayerImpl); |
111 m_rootLayer->addChild(otherLayer.get()); | 114 m_rootLayer->addChild(otherLayer.get()); |
112 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 115 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
113 layer->setMaskLayer(otherLayer.get()); | 116 layer->setMaskLayer(otherLayer.get()); |
114 Mock::VerifyAndClearExpectations(&m_client); | 117 Mock::VerifyAndClearExpectations(&m_client); |
115 | 118 |
116 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 119 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
117 float opacity = 0.123f; | 120 float opacity = 0.123f; |
118 layer->setOpacity(opacity); | 121 layer->setOpacity(opacity); |
119 Mock::VerifyAndClearExpectations(&m_client); | 122 Mock::VerifyAndClearExpectations(&m_client); |
120 EXPECT_EQ(opacity, layer->opacity()); | 123 EXPECT_EQ(opacity, layer->opacity()); |
121 | 124 |
122 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 125 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
123 layer->setOpaque(true); | 126 layer->setOpaque(true); |
124 Mock::VerifyAndClearExpectations(&m_client); | 127 Mock::VerifyAndClearExpectations(&m_client); |
125 EXPECT_TRUE(layer->opaque()); | 128 EXPECT_TRUE(layer->opaque()); |
126 | 129 |
127 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 130 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
128 layer->setPosition(point); | 131 layer->setPosition(point); |
129 Mock::VerifyAndClearExpectations(&m_client); | 132 Mock::VerifyAndClearExpectations(&m_client); |
130 EXPECT_EQ(point, layer->position()); | 133 EXPECT_EQ(point, layer->position()); |
131 | 134 |
132 // Texture layer. | 135 // Texture layer. |
133 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 136 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
134 scoped_ptr<WebExternalTextureLayer> textureLayer(WebExternalTextureLayer::cr
eate()); | 137 scoped_ptr<WebExternalTextureLayer> textureLayer(new WebExternalTextureLayer
Impl(NULL)); |
135 m_rootLayer->addChild(textureLayer->layer()); | 138 m_rootLayer->addChild(textureLayer->layer()); |
136 Mock::VerifyAndClearExpectations(&m_client); | 139 Mock::VerifyAndClearExpectations(&m_client); |
137 | 140 |
138 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 141 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
139 textureLayer->setTextureId(3); | 142 textureLayer->setTextureId(3); |
140 Mock::VerifyAndClearExpectations(&m_client); | 143 Mock::VerifyAndClearExpectations(&m_client); |
141 | 144 |
142 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 145 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
143 textureLayer->setFlipped(true); | 146 textureLayer->setFlipped(true); |
144 Mock::VerifyAndClearExpectations(&m_client); | 147 Mock::VerifyAndClearExpectations(&m_client); |
145 | 148 |
146 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 149 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
147 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f); | 150 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f); |
148 textureLayer->setUVRect(uvRect); | 151 textureLayer->setUVRect(uvRect); |
149 Mock::VerifyAndClearExpectations(&m_client); | 152 Mock::VerifyAndClearExpectations(&m_client); |
150 | 153 |
151 | 154 |
152 // Content layer. | 155 // Content layer. |
153 MockWebContentLayerClient contentClient; | 156 MockWebContentLayerClient contentClient; |
154 #if WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT | 157 #if WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT |
155 EXPECT_CALL(contentClient, paintContents(_, _, _, _)).Times(AnyNumber()); | 158 EXPECT_CALL(contentClient, paintContents(_, _, _, _)).Times(AnyNumber()); |
156 #else | 159 #else |
157 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber()); | 160 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber()); |
158 #endif // WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT | 161 #endif // WEBCONTENTLAYERCLIENT_HAS_CANPAINTLCDTEXT |
159 | 162 |
160 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 163 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
161 scoped_ptr<WebContentLayer> contentLayer(WebContentLayer::create(&contentCli
ent)); | 164 scoped_ptr<WebContentLayer> contentLayer(new WebContentLayerImpl(&contentCli
ent)); |
162 m_rootLayer->addChild(contentLayer->layer()); | 165 m_rootLayer->addChild(contentLayer->layer()); |
163 Mock::VerifyAndClearExpectations(&m_client); | 166 Mock::VerifyAndClearExpectations(&m_client); |
164 | 167 |
165 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 168 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
166 contentLayer->layer()->setDrawsContent(false); | 169 contentLayer->layer()->setDrawsContent(false); |
167 Mock::VerifyAndClearExpectations(&m_client); | 170 Mock::VerifyAndClearExpectations(&m_client); |
168 EXPECT_FALSE(contentLayer->layer()->drawsContent()); | 171 EXPECT_FALSE(contentLayer->layer()->drawsContent()); |
169 | 172 |
170 // Solid color layer. | 173 // Solid color layer. |
171 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 174 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
172 scoped_ptr<WebSolidColorLayer> solidColorLayer(WebSolidColorLayer::create())
; | 175 scoped_ptr<WebSolidColorLayer> solidColorLayer(new WebSolidColorLayerImpl); |
173 m_rootLayer->addChild(solidColorLayer->layer()); | 176 m_rootLayer->addChild(solidColorLayer->layer()); |
174 Mock::VerifyAndClearExpectations(&m_client); | 177 Mock::VerifyAndClearExpectations(&m_client); |
175 | 178 |
176 } | 179 } |
177 | 180 |
178 class MockScrollClient : public WebLayerScrollClient { | 181 class MockScrollClient : public WebLayerScrollClient { |
179 public: | 182 public: |
180 MOCK_METHOD0(didScroll, void()); | 183 MOCK_METHOD0(didScroll, void()); |
181 }; | 184 }; |
182 | 185 |
(...skipping 10 matching lines...) Expand all Loading... |
193 Mock::VerifyAndClearExpectations(&scrollClient); | 196 Mock::VerifyAndClearExpectations(&scrollClient); |
194 | 197 |
195 EXPECT_CALL(scrollClient, didScroll()).Times(0); | 198 EXPECT_CALL(scrollClient, didScroll()).Times(0); |
196 m_rootLayer->setScrollPosition(WebPoint(14, 19)); | 199 m_rootLayer->setScrollPosition(WebPoint(14, 19)); |
197 Mock::VerifyAndClearExpectations(&scrollClient); | 200 Mock::VerifyAndClearExpectations(&scrollClient); |
198 | 201 |
199 m_rootLayer->setScrollClient(0); | 202 m_rootLayer->setScrollClient(0); |
200 } | 203 } |
201 | 204 |
202 } | 205 } |
OLD | NEW |