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

Side by Side Diff: cc/layers/layer_proto_converter_unittest.cc

Issue 2493523003: cc: Remove unused proto conversion code. (Closed)
Patch Set: test Created 4 years, 1 month 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
« no previous file with comments | « cc/layers/layer_proto_converter.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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/layers/layer_proto_converter.h"
6
7 #include "cc/animation/animation_host.h"
8 #include "cc/layers/empty_content_layer_client.h"
9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/picture_layer.h"
12 #include "cc/proto/layer.pb.h"
13 #include "cc/test/fake_layer_tree_host.h"
14 #include "cc/test/fake_layer_tree_host_client.h"
15 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/trees/layer_tree_settings.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace cc {
20 namespace {
21 class LayerProtoConverterTest : public testing::Test {
22 protected:
23 void SetUp() override {
24 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
25 layer_tree_host_ = FakeLayerTreeHost::Create(
26 &fake_client_, &task_graph_runner_, animation_host_.get());
27 }
28
29 void TearDown() override {
30 layer_tree_host_->SetRootLayer(nullptr);
31 layer_tree_host_ = nullptr;
32 }
33
34 TestTaskGraphRunner task_graph_runner_;
35 FakeLayerTreeHostClient fake_client_;
36 std::unique_ptr<AnimationHost> animation_host_;
37 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
38 };
39
40 TEST_F(LayerProtoConverterTest, TestKeepingRoot) {
41 /* Test deserialization of a tree that looks like:
42 root
43 / \
44 a b
45 \
46 c
47 The old root node will be reused during deserialization.
48 */
49 scoped_refptr<Layer> old_root = Layer::Create();
50 proto::LayerNode root_node;
51 root_node.set_id(old_root->id());
52 root_node.set_type(proto::LayerNode::LAYER);
53
54 proto::LayerNode* child_a_node = root_node.add_children();
55 child_a_node->set_id(442);
56 child_a_node->set_type(proto::LayerNode::LAYER);
57 child_a_node->set_parent_id(old_root->id()); // root_node
58
59 proto::LayerNode* child_b_node = root_node.add_children();
60 child_b_node->set_id(443);
61 child_b_node->set_type(proto::LayerNode::LAYER);
62 child_b_node->set_parent_id(old_root->id()); // root_node
63
64 proto::LayerNode* child_c_node = child_b_node->add_children();
65 child_c_node->set_id(444);
66 child_c_node->set_type(proto::LayerNode::LAYER);
67 child_c_node->set_parent_id(child_b_node->id());
68
69 scoped_refptr<Layer> new_root =
70 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node,
71 layer_tree_host_.get());
72
73 // The new root should not be the same as the old root.
74 EXPECT_EQ(old_root->id(), new_root->id());
75 ASSERT_EQ(2u, new_root->children().size());
76 scoped_refptr<Layer> child_a = new_root->children()[0];
77 scoped_refptr<Layer> child_b = new_root->children()[1];
78
79 EXPECT_EQ(child_a_node->id(), child_a->id());
80 EXPECT_EQ(child_b_node->id(), child_b->id());
81
82 EXPECT_EQ(0u, child_a->children().size());
83 ASSERT_EQ(1u, child_b->children().size());
84
85 scoped_refptr<Layer> child_c = child_b->children()[0];
86 EXPECT_EQ(child_c_node->id(), child_c->id());
87
88 new_root->SetLayerTreeHost(nullptr);
89 }
90
91 TEST_F(LayerProtoConverterTest, TestNoExistingRoot) {
92 /* Test deserialization of a tree that looks like:
93 root
94 /
95 a
96 There is no existing root node before serialization.
97 */
98 int new_root_id = 244;
99 proto::LayerNode root_node;
100 root_node.set_id(new_root_id);
101 root_node.set_type(proto::LayerNode::LAYER);
102
103 proto::LayerNode* child_a_node = root_node.add_children();
104 child_a_node->set_id(442);
105 child_a_node->set_type(proto::LayerNode::LAYER);
106 child_a_node->set_parent_id(new_root_id); // root_node
107
108 scoped_refptr<Layer> new_root =
109 LayerProtoConverter::DeserializeLayerHierarchy(nullptr, root_node,
110 layer_tree_host_.get());
111
112 // The new root should not be the same as the old root.
113 EXPECT_EQ(new_root_id, new_root->id());
114 ASSERT_EQ(1u, new_root->children().size());
115 scoped_refptr<Layer> child_a = new_root->children()[0];
116
117 EXPECT_EQ(child_a_node->id(), child_a->id());
118 EXPECT_EQ(0u, child_a->children().size());
119
120 new_root->SetLayerTreeHost(nullptr);
121 }
122
123 TEST_F(LayerProtoConverterTest, TestSwappingRoot) {
124 /* Test deserialization of a tree that looks like:
125 root
126 / \
127 a b
128 \
129 c
130 The old root node will be swapped out during deserialization.
131 */
132 proto::LayerNode root_node;
133 root_node.set_id(441);
134 root_node.set_type(proto::LayerNode::LAYER);
135
136 proto::LayerNode* child_a_node = root_node.add_children();
137 child_a_node->set_id(442);
138 child_a_node->set_type(proto::LayerNode::LAYER);
139 child_a_node->set_parent_id(root_node.id());
140
141 proto::LayerNode* child_b_node = root_node.add_children();
142 child_b_node->set_id(443);
143 child_b_node->set_type(proto::LayerNode::LAYER);
144 child_b_node->set_parent_id(root_node.id());
145
146 proto::LayerNode* child_c_node = child_b_node->add_children();
147 child_c_node->set_id(444);
148 child_c_node->set_type(proto::LayerNode::LAYER);
149 child_c_node->set_parent_id(child_b_node->id());
150
151 scoped_refptr<Layer> old_root = Layer::Create();
152 scoped_refptr<Layer> new_root =
153 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node,
154 layer_tree_host_.get());
155
156 // The new root should not be the same as the old root.
157 EXPECT_EQ(root_node.id(), new_root->id());
158 ASSERT_EQ(2u, new_root->children().size());
159 scoped_refptr<Layer> child_a = new_root->children()[0];
160 scoped_refptr<Layer> child_b = new_root->children()[1];
161
162 EXPECT_EQ(child_a_node->id(), child_a->id());
163 EXPECT_EQ(child_b_node->id(), child_b->id());
164
165 EXPECT_EQ(0u, child_a->children().size());
166 ASSERT_EQ(1u, child_b->children().size());
167
168 scoped_refptr<Layer> child_c = child_b->children()[0];
169 EXPECT_EQ(child_c_node->id(), child_c->id());
170
171 new_root->SetLayerTreeHost(nullptr);
172 }
173
174 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerialization) {
175 /* Testing serialization of properties for a tree that looks like this:
176 root+
177 / \
178 a* b*+[mask:*]
179 / \
180 c d*
181 Layers marked with * have changed properties.
182 Layers marked with + have descendants with changed properties.
183 Layer b also has a mask layer layer.
184 */
185 scoped_refptr<Layer> layer_src_root = Layer::Create();
186 scoped_refptr<Layer> layer_src_a = Layer::Create();
187 scoped_refptr<Layer> layer_src_b = Layer::Create();
188 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
189 scoped_refptr<Layer> layer_src_c = Layer::Create();
190 scoped_refptr<Layer> layer_src_d = Layer::Create();
191 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
192 layer_src_root->AddChild(layer_src_a);
193 layer_src_root->AddChild(layer_src_b);
194 layer_src_a->AddChild(layer_src_c);
195 layer_src_b->AddChild(layer_src_d);
196 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
197
198 proto::LayerUpdate layer_update;
199 LayerProtoConverter::SerializeLayerProperties(
200 layer_src_root->GetLayerTreeHostForTesting(), &layer_update);
201
202 // All flags for pushing properties should have been cleared.
203 EXPECT_FALSE(
204 layer_src_root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
205 layer_src_root.get()));
206 EXPECT_FALSE(layer_src_a->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
207 layer_src_a.get()));
208 EXPECT_FALSE(layer_src_b->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
209 layer_src_b.get()));
210 EXPECT_FALSE(
211 layer_src_b_mask->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
212 layer_src_b_mask.get()));
213 EXPECT_FALSE(layer_src_c->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
214 layer_src_c.get()));
215 EXPECT_FALSE(layer_src_d->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
216 layer_src_d.get()));
217
218 // All layers needs to push properties as their layer tree host changed.
219 ASSERT_EQ(6, layer_update.layers_size());
220 layer_update.Clear();
221
222 std::unordered_set<int> dirty_layer_ids;
223 layer_src_a->SetNeedsPushProperties();
224 dirty_layer_ids.insert(layer_src_a->id());
225 layer_src_b->SetNeedsPushProperties();
226 dirty_layer_ids.insert(layer_src_b->id());
227 layer_src_b_mask->SetNeedsPushProperties();
228 dirty_layer_ids.insert(layer_src_b_mask->id());
229 layer_src_d->SetNeedsPushProperties();
230 dirty_layer_ids.insert(layer_src_d->id());
231
232 LayerProtoConverter::SerializeLayerProperties(
233 layer_src_root->GetLayerTreeHostForTesting(), &layer_update);
234
235 // All flags for pushing properties should have been cleared.
236 EXPECT_FALSE(
237 layer_src_root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
238 layer_src_root.get()));
239 EXPECT_FALSE(layer_src_a->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
240 layer_src_a.get()));
241 EXPECT_FALSE(layer_src_b->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
242 layer_src_b.get()));
243 EXPECT_FALSE(
244 layer_src_b_mask->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
245 layer_src_b_mask.get()));
246 EXPECT_FALSE(layer_src_c->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
247 layer_src_c.get()));
248 EXPECT_FALSE(layer_src_d->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
249 layer_src_d.get()));
250
251 // Only 4 of the layers should have been serialized.
252 ASSERT_EQ(4, layer_update.layers_size());
253 for (int index = 0; index < layer_update.layers_size(); index++)
254 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
255 dirty_layer_ids.end());
256 layer_src_root->SetLayerTreeHost(nullptr);
257 }
258
259 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) {
260 /* Testing serialization of properties for a tree that looks like this:
261 root+
262 \
263 b*+[mask:*]
264 \
265 c
266 Layers marked with * have changed properties.
267 Layers marked with + have descendants with changed properties.
268 Layer b also has a mask layer.
269 */
270 scoped_refptr<Layer> layer_src_root = Layer::Create();
271 scoped_refptr<Layer> layer_src_b = Layer::Create();
272 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
273 scoped_refptr<Layer> layer_src_c = Layer::Create();
274 layer_src_root->AddChild(layer_src_b);
275 layer_src_b->AddChild(layer_src_c);
276 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
277 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
278
279 proto::LayerUpdate layer_update;
280 LayerProtoConverter::SerializeLayerProperties(
281 layer_src_root->GetLayerTreeHostForTesting(), &layer_update);
282 // All layers need to push properties as their layer tree host changed.
283 ASSERT_EQ(4, layer_update.layers_size());
284 layer_update.Clear();
285
286 std::unordered_set<int> dirty_layer_ids;
287 layer_src_b->SetNeedsPushProperties();
288 dirty_layer_ids.insert(layer_src_b->id());
289 layer_src_b_mask->SetNeedsPushProperties();
290 dirty_layer_ids.insert(layer_src_b_mask->id());
291
292 LayerProtoConverter::SerializeLayerProperties(
293 layer_src_root->GetLayerTreeHostForTesting(), &layer_update);
294
295 // All flags for pushing properties should have been cleared.
296 EXPECT_FALSE(
297 layer_src_root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
298 layer_src_root.get()));
299 EXPECT_FALSE(layer_src_b->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
300 layer_src_b.get()));
301 EXPECT_FALSE(
302 layer_src_b_mask->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
303 layer_src_b_mask.get()));
304 EXPECT_FALSE(layer_src_c->GetLayerTree()->LayerNeedsPushPropertiesForTesting(
305 layer_src_c.get()));
306
307 // Only 2 of the layers should have been serialized.
308 ASSERT_EQ(2, layer_update.layers_size());
309 for (int index = 0; index < layer_update.layers_size(); index++)
310 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
311 dirty_layer_ids.end());
312 layer_src_root->SetLayerTreeHost(nullptr);
313 }
314
315 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) {
316 // Make sure that PictureLayers serialize to the
317 // proto::LayerType::PICTURE_LAYER type.
318 scoped_refptr<PictureLayer> layer =
319 PictureLayer::Create(EmptyContentLayerClient::GetInstance());
320
321 proto::LayerNode layer_hierarchy;
322 layer->ToLayerNodeProto(&layer_hierarchy);
323 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_hierarchy.type());
324 }
325
326 TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) {
327 // Make sure that proto::LayerType::PICTURE_LAYER ends up building a
328 // PictureLayer.
329 scoped_refptr<Layer> old_root =
330 PictureLayer::Create(EmptyContentLayerClient::GetInstance());
331 proto::LayerNode root_node;
332 root_node.set_id(old_root->id());
333 root_node.set_type(proto::LayerNode::PICTURE_LAYER);
334
335 scoped_refptr<Layer> new_root =
336 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node,
337 layer_tree_host_.get());
338
339 // Validate that the ids are equal.
340 EXPECT_EQ(old_root->id(), new_root->id());
341
342 // Check that the layer type is equal by using the type this layer would
343 // serialize to.
344 proto::LayerNode layer_node;
345 new_root->SetTypeForProtoSerialization(&layer_node);
346 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_node.type());
347
348 new_root->SetLayerTreeHost(nullptr);
349 }
350
351 TEST_F(LayerProtoConverterTest, HudLayerTypeSerialization) {
352 // Make sure that PictureLayers serialize to the
353 // proto::LayerType::HEADS_UP_DISPLAY_LAYER type.
354 scoped_refptr<HeadsUpDisplayLayer> layer = HeadsUpDisplayLayer::Create();
355
356 proto::LayerNode layer_hierarchy;
357 layer->ToLayerNodeProto(&layer_hierarchy);
358 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_hierarchy.type());
359 }
360
361 TEST_F(LayerProtoConverterTest, HudLayerTypeDeserialization) {
362 // Make sure that proto::LayerType::HEADS_UP_DISPLAY_LAYER ends up building a
363 // HeadsUpDisplayLayer.
364 scoped_refptr<Layer> old_root = HeadsUpDisplayLayer::Create();
365 proto::LayerNode root_node;
366 root_node.set_id(old_root->id());
367 root_node.set_type(proto::LayerNode::HEADS_UP_DISPLAY_LAYER);
368
369 scoped_refptr<Layer> new_root =
370 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node,
371 layer_tree_host_.get());
372
373 // Validate that the ids are equal.
374 EXPECT_EQ(old_root->id(), new_root->id());
375
376 // Check that the layer type is equal by using the type this layer would
377 // serialize to.
378 proto::LayerNode layer_node;
379 new_root->SetTypeForProtoSerialization(&layer_node);
380 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type());
381
382 new_root->SetLayerTreeHost(nullptr);
383 }
384
385 } // namespace
386 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_proto_converter.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698