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

Side by Side Diff: webkit/compositor_bindings/web_layer_unittest.cc

Issue 12377029: Get rid of WebLayerTreeViewClient references in WebLayerTreeViewImplForTesting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 "cc/thread.h"
6 #include "testing/gmock/include/gmock/gmock.h"
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h"
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayerClie nt.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL ayer.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli ent.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer. h"
19 #include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h"
20 #include "webkit/compositor_bindings/web_content_layer_impl.h"
21 #include "webkit/compositor_bindings/web_external_texture_layer_impl.h"
22 #include "webkit/compositor_bindings/web_layer_impl.h"
23 #include "webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h"
24 #include "webkit/compositor_bindings/web_solid_color_layer_impl.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_METHOD4(paintContents,
38 void(WebCanvas*,
39 const WebRect& clip,
40 bool can_paint_lcd_text,
41 WebFloatRect& opaque));
42 };
43
44 class WebLayerTest : public Test {
45 public:
46 WebLayerTest() {}
47
48 virtual void SetUp() {
49 root_layer_.reset(new WebLayerImpl);
50 EXPECT_CALL(client_, scheduleComposite()).Times(AnyNumber());
51 view_.reset(new WebLayerTreeViewImplForTesting(
52 WebLayerTreeViewImplForTesting::FAKE_CONTEXT, &client_));
53 EXPECT_TRUE(view_->initialize(scoped_ptr<cc::Thread>(NULL)));
54 view_->setRootLayer(*root_layer_);
55 EXPECT_TRUE(view_);
56 Mock::VerifyAndClearExpectations(&client_);
57 }
58
59 virtual void TearDown() {
60 // We may get any number of scheduleComposite calls during shutdown.
61 EXPECT_CALL(client_, scheduleComposite()).Times(AnyNumber());
62 root_layer_.reset();
63 view_.reset();
64 }
65
66 protected:
67 MockWebLayerTreeViewClient client_;
68 scoped_ptr<WebLayer> root_layer_;
69 scoped_ptr<WebLayerTreeViewImplForTesting> view_;
70 };
71
72 // Tests that the client gets called to ask for a composite if we change the
73 // fields.
74 TEST_F(WebLayerTest, Client) {
75 // Base layer.
76 EXPECT_CALL(client_, scheduleComposite()).Times(AnyNumber());
77 scoped_ptr<WebLayer> layer(new WebLayerImpl);
78 layer->setDrawsContent(true);
79 root_layer_->addChild(layer.get());
80 Mock::VerifyAndClearExpectations(&client_);
81
82 WebFloatPoint point(3, 4);
83 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
84 layer->setAnchorPoint(point);
85 Mock::VerifyAndClearExpectations(&client_);
86 EXPECT_EQ(point, layer->anchorPoint());
87
88 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
89 float anchorZ = 5;
90 layer->setAnchorPointZ(anchorZ);
91 Mock::VerifyAndClearExpectations(&client_);
92 EXPECT_EQ(anchorZ, layer->anchorPointZ());
93
94 WebSize size(7, 8);
95 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
96 layer->setBounds(size);
97 Mock::VerifyAndClearExpectations(&client_);
98 EXPECT_EQ(size, layer->bounds());
99
100 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
101 layer->setMasksToBounds(true);
102 Mock::VerifyAndClearExpectations(&client_);
103 EXPECT_TRUE(layer->masksToBounds());
104
105 EXPECT_CALL(client_, scheduleComposite()).Times(AnyNumber());
106 scoped_ptr<WebLayer> other_layer_1(new WebLayerImpl);
107 root_layer_->addChild(other_layer_1.get());
108 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
109 scoped_ptr<WebLayer> other_layer_2(new WebLayerImpl);
110 layer->setMaskLayer(other_layer_2.get());
111 Mock::VerifyAndClearExpectations(&client_);
112
113 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
114 float opacity = 0.123f;
115 layer->setOpacity(opacity);
116 Mock::VerifyAndClearExpectations(&client_);
117 EXPECT_EQ(opacity, layer->opacity());
118
119 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
120 layer->setOpaque(true);
121 Mock::VerifyAndClearExpectations(&client_);
122 EXPECT_TRUE(layer->opaque());
123
124 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
125 layer->setPosition(point);
126 Mock::VerifyAndClearExpectations(&client_);
127 EXPECT_EQ(point, layer->position());
128
129 // Texture layer.
130 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
131 scoped_ptr<WebExternalTextureLayer> texture_layer(
132 new WebExternalTextureLayerImpl(NULL));
133 root_layer_->addChild(texture_layer->layer());
134 Mock::VerifyAndClearExpectations(&client_);
135
136 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
137 texture_layer->setTextureId(3);
138 Mock::VerifyAndClearExpectations(&client_);
139
140 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
141 texture_layer->setFlipped(true);
142 Mock::VerifyAndClearExpectations(&client_);
143
144 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
145 WebFloatRect uv_rect(0.1f, 0.1f, 0.9f, 0.9f);
146 texture_layer->setUVRect(uv_rect);
147 Mock::VerifyAndClearExpectations(&client_);
148
149 // Content layer.
150 MockWebContentLayerClient content_client;
151 EXPECT_CALL(content_client, paintContents(_, _, _, _)).Times(AnyNumber());
152
153 EXPECT_CALL(client_, scheduleComposite()).Times(AnyNumber());
154 scoped_ptr<WebContentLayer> content_layer(
155 new WebContentLayerImpl(&content_client));
156 root_layer_->addChild(content_layer->layer());
157 Mock::VerifyAndClearExpectations(&client_);
158
159 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
160 content_layer->layer()->setDrawsContent(false);
161 Mock::VerifyAndClearExpectations(&client_);
162 EXPECT_FALSE(content_layer->layer()->drawsContent());
163
164 // Solid color layer.
165 EXPECT_CALL(client_, scheduleComposite()).Times(AtLeast(1));
166 scoped_ptr<WebSolidColorLayer> solid_color_layer(new WebSolidColorLayerImpl);
167 root_layer_->addChild(solid_color_layer->layer());
168 Mock::VerifyAndClearExpectations(&client_);
169
170 }
171
172 class MockScrollClient : public WebLayerScrollClient {
173 public:
174 MOCK_METHOD0(didScroll, void());
175 };
176
177 TEST_F(WebLayerTest, notify_scroll_client) {
178 MockScrollClient scroll_client;
179
180 EXPECT_CALL(scroll_client, didScroll()).Times(0);
181 root_layer_->setScrollClient(&scroll_client);
182 Mock::VerifyAndClearExpectations(&scroll_client);
183
184 EXPECT_CALL(scroll_client, didScroll()).Times(1);
185 root_layer_->setScrollPosition(WebPoint(14, 19));
186 Mock::VerifyAndClearExpectations(&scroll_client);
187
188 EXPECT_CALL(scroll_client, didScroll()).Times(0);
189 root_layer_->setScrollPosition(WebPoint(14, 19));
190 Mock::VerifyAndClearExpectations(&scroll_client);
191
192 root_layer_->setScrollClient(0);
193 }
194
195 }
OLDNEW
« no previous file with comments | « webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.cc ('k') | webkit/support/test_webkit_platform_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698