Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: webkit/compositor_bindings/WebLayerTest.cpp

Issue 11192050: Rename compositor bindings filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include <public/WebLayer.h>
7
8 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
9 #include "cc/test/web_compositor_initializer.h"
10 #include "WebLayerImpl.h"
11 #include "WebLayerTreeViewTestCommon.h"
12 #include <public/WebContentLayer.h>
13 #include <public/WebContentLayerClient.h>
14 #include <public/WebExternalTextureLayer.h>
15 #include <public/WebFloatPoint.h>
16 #include <public/WebFloatRect.h>
17 #include <public/WebLayerScrollClient.h>
18 #include <public/WebLayerTreeView.h>
19 #include <public/WebLayerTreeViewClient.h>
20 #include <public/WebRect.h>
21 #include <public/WebSize.h>
22 #include <public/WebSolidColorLayer.h>
23
24 #include <gmock/gmock.h>
25
26 using namespace WebKit;
27 using testing::AnyNumber;
28 using testing::AtLeast;
29 using testing::Mock;
30 using testing::Test;
31 using testing::_;
32
33 namespace {
34
35 class MockWebContentLayerClient : public WebContentLayerClient {
36 public:
37 MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebFloatRe ct& opaque));
38 };
39
40 class WebLayerTest : public Test {
41 public:
42 WebLayerTest()
43 : m_compositorInitializer(0)
44 {
45 }
46
47 virtual void SetUp()
48 {
49 m_rootLayer = adoptPtr(WebLayer::create());
50 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber());
51 EXPECT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(&m_client, *m_roo tLayer, WebLayerTreeView::Settings())));
52 Mock::VerifyAndClearExpectations(&m_client);
53 }
54
55 virtual void TearDown()
56 {
57 // We may get any number of scheduleComposite calls during shutdown.
58 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber());
59 m_rootLayer.clear();
60 m_view.clear();
61 }
62
63 protected:
64 WebKitTests::WebCompositorInitializer m_compositorInitializer;
65 MockWebLayerTreeViewClient m_client;
66 OwnPtr<WebLayer> m_rootLayer;
67 OwnPtr<WebLayerTreeView> m_view;
68 };
69
70 // Tests that the client gets called to ask for a composite if we change the
71 // fields.
72 TEST_F(WebLayerTest, Client)
73 {
74 // Base layer.
75 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber());
76 OwnPtr<WebLayer> layer = adoptPtr(WebLayer::create());
77 m_rootLayer->addChild(layer.get());
78 Mock::VerifyAndClearExpectations(&m_client);
79
80 WebFloatPoint point(3, 4);
81 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
82 layer->setAnchorPoint(point);
83 Mock::VerifyAndClearExpectations(&m_client);
84 EXPECT_EQ(point, layer->anchorPoint());
85
86 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
87 float anchorZ = 5;
88 layer->setAnchorPointZ(anchorZ);
89 Mock::VerifyAndClearExpectations(&m_client);
90 EXPECT_EQ(anchorZ, layer->anchorPointZ());
91
92 WebSize size(7, 8);
93 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
94 layer->setBounds(size);
95 Mock::VerifyAndClearExpectations(&m_client);
96 EXPECT_EQ(size, layer->bounds());
97
98 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
99 layer->setMasksToBounds(true);
100 Mock::VerifyAndClearExpectations(&m_client);
101 EXPECT_TRUE(layer->masksToBounds());
102
103 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber());
104 OwnPtr<WebLayer> otherLayer = adoptPtr(WebLayer::create());
105 m_rootLayer->addChild(otherLayer.get());
106 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
107 layer->setMaskLayer(otherLayer.get());
108 Mock::VerifyAndClearExpectations(&m_client);
109
110 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
111 float opacity = 0.123f;
112 layer->setOpacity(opacity);
113 Mock::VerifyAndClearExpectations(&m_client);
114 EXPECT_EQ(opacity, layer->opacity());
115
116 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
117 layer->setOpaque(true);
118 Mock::VerifyAndClearExpectations(&m_client);
119 EXPECT_TRUE(layer->opaque());
120
121 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
122 layer->setPosition(point);
123 Mock::VerifyAndClearExpectations(&m_client);
124 EXPECT_EQ(point, layer->position());
125
126 // Texture layer.
127 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
128 OwnPtr<WebExternalTextureLayer> textureLayer = adoptPtr(WebExternalTextureLa yer::create());
129 m_rootLayer->addChild(textureLayer->layer());
130 Mock::VerifyAndClearExpectations(&m_client);
131
132 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
133 textureLayer->setTextureId(3);
134 Mock::VerifyAndClearExpectations(&m_client);
135
136 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
137 textureLayer->setFlipped(true);
138 Mock::VerifyAndClearExpectations(&m_client);
139
140 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
141 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f);
142 textureLayer->setUVRect(uvRect);
143 Mock::VerifyAndClearExpectations(&m_client);
144
145
146 // Content layer.
147 MockWebContentLayerClient contentClient;
148 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber());
149 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber());
150 OwnPtr<WebContentLayer> contentLayer = adoptPtr(WebContentLayer::create(&con tentClient));
151 m_rootLayer->addChild(contentLayer->layer());
152 Mock::VerifyAndClearExpectations(&m_client);
153
154 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
155 contentLayer->layer()->setDrawsContent(false);
156 Mock::VerifyAndClearExpectations(&m_client);
157 EXPECT_FALSE(contentLayer->layer()->drawsContent());
158
159 // Solid color layer.
160 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1));
161 OwnPtr<WebSolidColorLayer> solidColorLayer = adoptPtr(WebSolidColorLayer::cr eate());
162 m_rootLayer->addChild(solidColorLayer->layer());
163 Mock::VerifyAndClearExpectations(&m_client);
164
165 }
166
167 class MockScrollClient : public WebLayerScrollClient {
168 public:
169 MOCK_METHOD0(didScroll, void());
170 };
171
172 TEST_F(WebLayerTest, notifyScrollClient)
173 {
174 MockScrollClient scrollClient;
175
176 EXPECT_CALL(scrollClient, didScroll()).Times(0);
177 m_rootLayer->setScrollClient(&scrollClient);
178 Mock::VerifyAndClearExpectations(&scrollClient);
179
180 EXPECT_CALL(scrollClient, didScroll()).Times(1);
181 m_rootLayer->setScrollPosition(WebPoint(14, 19));
182 Mock::VerifyAndClearExpectations(&scrollClient);
183
184 EXPECT_CALL(scrollClient, didScroll()).Times(0);
185 m_rootLayer->setScrollPosition(WebPoint(14, 19));
186 Mock::VerifyAndClearExpectations(&scrollClient);
187
188 m_rootLayer->setScrollClient(0);
189 }
190
191 }
OLDNEW
« no previous file with comments | « webkit/compositor_bindings/WebLayerImpl.cpp ('k') | webkit/compositor_bindings/WebLayerTreeViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698