OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "cc/layers/layer_proto_converter.h" | 5 #include "cc/layers/layer_proto_converter.h" |
6 | 6 |
| 7 #include "cc/layers/empty_content_layer_client.h" |
7 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
8 #include "cc/layers/layer_settings.h" | 9 #include "cc/layers/layer_settings.h" |
| 10 #include "cc/layers/picture_layer.h" |
9 #include "cc/proto/layer.pb.h" | 11 #include "cc/proto/layer.pb.h" |
10 #include "cc/trees/layer_tree_settings.h" | 12 #include "cc/trees/layer_tree_settings.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace cc { | 15 namespace cc { |
14 | 16 |
15 TEST(LayerProtoConverterTest, TestKeepingRoot) { | 17 TEST(LayerProtoConverterTest, TestKeepingRoot) { |
16 /* Test deserialization of a tree that looks like: | 18 /* Test deserialization of a tree that looks like: |
17 root | 19 root |
18 / \ | 20 / \ |
19 a b | 21 a b |
20 \ | 22 \ |
21 c | 23 c |
22 The old root node will be reused during deserialization. | 24 The old root node will be reused during deserialization. |
23 */ | 25 */ |
24 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); | 26 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
25 proto::LayerNode root_node; | 27 proto::LayerNode root_node; |
26 root_node.set_id(old_root->id()); | 28 root_node.set_id(old_root->id()); |
27 root_node.set_type(proto::LayerType::Base); | 29 root_node.set_type(proto::LayerType::LAYER); |
28 | 30 |
29 proto::LayerNode* child_a_node = root_node.add_children(); | 31 proto::LayerNode* child_a_node = root_node.add_children(); |
30 child_a_node->set_id(442); | 32 child_a_node->set_id(442); |
31 child_a_node->set_type(proto::LayerType::Base); | 33 child_a_node->set_type(proto::LayerType::LAYER); |
32 child_a_node->set_parent_id(old_root->id()); // root_node | 34 child_a_node->set_parent_id(old_root->id()); // root_node |
33 | 35 |
34 proto::LayerNode* child_b_node = root_node.add_children(); | 36 proto::LayerNode* child_b_node = root_node.add_children(); |
35 child_b_node->set_id(443); | 37 child_b_node->set_id(443); |
36 child_b_node->set_type(proto::LayerType::Base); | 38 child_b_node->set_type(proto::LayerType::LAYER); |
37 child_b_node->set_parent_id(old_root->id()); // root_node | 39 child_b_node->set_parent_id(old_root->id()); // root_node |
38 | 40 |
39 proto::LayerNode* child_c_node = child_b_node->add_children(); | 41 proto::LayerNode* child_c_node = child_b_node->add_children(); |
40 child_c_node->set_id(444); | 42 child_c_node->set_id(444); |
41 child_c_node->set_type(proto::LayerType::Base); | 43 child_c_node->set_type(proto::LayerType::LAYER); |
42 child_c_node->set_parent_id(child_b_node->id()); | 44 child_c_node->set_parent_id(child_b_node->id()); |
43 | 45 |
44 scoped_refptr<Layer> new_root = | 46 scoped_refptr<Layer> new_root = |
45 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); | 47 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
46 | 48 |
47 // The new root should not be the same as the old root. | 49 // The new root should not be the same as the old root. |
48 EXPECT_EQ(old_root->id(), new_root->id()); | 50 EXPECT_EQ(old_root->id(), new_root->id()); |
49 ASSERT_EQ(2u, new_root->children().size()); | 51 ASSERT_EQ(2u, new_root->children().size()); |
50 scoped_refptr<Layer> child_a = new_root->children()[0]; | 52 scoped_refptr<Layer> child_a = new_root->children()[0]; |
51 scoped_refptr<Layer> child_b = new_root->children()[1]; | 53 scoped_refptr<Layer> child_b = new_root->children()[1]; |
(...skipping 12 matching lines...) Expand all Loading... |
64 /* Test deserialization of a tree that looks like: | 66 /* Test deserialization of a tree that looks like: |
65 root | 67 root |
66 / \ | 68 / \ |
67 a b | 69 a b |
68 \ | 70 \ |
69 c | 71 c |
70 The old root node will be swapped out during deserialization. | 72 The old root node will be swapped out during deserialization. |
71 */ | 73 */ |
72 proto::LayerNode root_node; | 74 proto::LayerNode root_node; |
73 root_node.set_id(441); | 75 root_node.set_id(441); |
74 root_node.set_type(proto::LayerType::Base); | 76 root_node.set_type(proto::LayerType::LAYER); |
75 | 77 |
76 proto::LayerNode* child_a_node = root_node.add_children(); | 78 proto::LayerNode* child_a_node = root_node.add_children(); |
77 child_a_node->set_id(442); | 79 child_a_node->set_id(442); |
78 child_a_node->set_type(proto::LayerType::Base); | 80 child_a_node->set_type(proto::LayerType::LAYER); |
79 child_a_node->set_parent_id(root_node.id()); | 81 child_a_node->set_parent_id(root_node.id()); |
80 | 82 |
81 proto::LayerNode* child_b_node = root_node.add_children(); | 83 proto::LayerNode* child_b_node = root_node.add_children(); |
82 child_b_node->set_id(443); | 84 child_b_node->set_id(443); |
83 child_b_node->set_type(proto::LayerType::Base); | 85 child_b_node->set_type(proto::LayerType::LAYER); |
84 child_b_node->set_parent_id(root_node.id()); | 86 child_b_node->set_parent_id(root_node.id()); |
85 | 87 |
86 proto::LayerNode* child_c_node = child_b_node->add_children(); | 88 proto::LayerNode* child_c_node = child_b_node->add_children(); |
87 child_c_node->set_id(444); | 89 child_c_node->set_id(444); |
88 child_c_node->set_type(proto::LayerType::Base); | 90 child_c_node->set_type(proto::LayerType::LAYER); |
89 child_c_node->set_parent_id(child_b_node->id()); | 91 child_c_node->set_parent_id(child_b_node->id()); |
90 | 92 |
91 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); | 93 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
92 scoped_refptr<Layer> new_root = | 94 scoped_refptr<Layer> new_root = |
93 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); | 95 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
94 | 96 |
95 // The new root should not be the same as the old root. | 97 // The new root should not be the same as the old root. |
96 EXPECT_EQ(root_node.id(), new_root->id()); | 98 EXPECT_EQ(root_node.id(), new_root->id()); |
97 ASSERT_EQ(2u, new_root->children().size()); | 99 ASSERT_EQ(2u, new_root->children().size()); |
98 scoped_refptr<Layer> child_a = new_root->children()[0]; | 100 scoped_refptr<Layer> child_a = new_root->children()[0]; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 EXPECT_FALSE(a->needs_push_properties()); | 303 EXPECT_FALSE(a->needs_push_properties()); |
302 EXPECT_FALSE(a->descendant_needs_push_properties()); | 304 EXPECT_FALSE(a->descendant_needs_push_properties()); |
303 | 305 |
304 EXPECT_FALSE(b->needs_push_properties()); | 306 EXPECT_FALSE(b->needs_push_properties()); |
305 EXPECT_TRUE(b->descendant_needs_push_properties()); | 307 EXPECT_TRUE(b->descendant_needs_push_properties()); |
306 | 308 |
307 EXPECT_TRUE(c->needs_push_properties()); | 309 EXPECT_TRUE(c->needs_push_properties()); |
308 EXPECT_FALSE(c->descendant_needs_push_properties()); | 310 EXPECT_FALSE(c->descendant_needs_push_properties()); |
309 } | 311 } |
310 | 312 |
| 313 TEST(LayerProtoConverterTest, PictureLayerTypeSerialization) { |
| 314 // Make sure that PictureLayers serialize to the |
| 315 // proto::LayerType::PICTURE_LAYER type. |
| 316 scoped_refptr<PictureLayer> layer = PictureLayer::Create( |
| 317 LayerSettings(), EmptyContentLayerClient::GetInstance()); |
| 318 |
| 319 proto::LayerNode layer_hierarchy; |
| 320 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); |
| 321 EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_hierarchy.type()); |
| 322 } |
| 323 |
| 324 TEST(LayerProtoConverterTest, PictureLayerTypeDeserialization) { |
| 325 // Make sure that proto::LayerType::PICTURE_LAYER ends up building a |
| 326 // PictureLayer. |
| 327 scoped_refptr<Layer> old_root = PictureLayer::Create( |
| 328 LayerSettings(), EmptyContentLayerClient::GetInstance()); |
| 329 proto::LayerNode root_node; |
| 330 root_node.set_id(old_root->id()); |
| 331 root_node.set_type(proto::LayerType::PICTURE_LAYER); |
| 332 |
| 333 scoped_refptr<Layer> new_root = |
| 334 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
| 335 |
| 336 // Validate that the ids are equal. |
| 337 EXPECT_EQ(old_root->id(), new_root->id()); |
| 338 |
| 339 // Check that the layer type is equal by using the type this layer would |
| 340 // serialize to. |
| 341 proto::LayerNode layer_node; |
| 342 new_root->SetTypeForProtoSerialization(&layer_node); |
| 343 EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_node.type()); |
| 344 } |
| 345 |
311 } // namespace cc | 346 } // namespace cc |
OLD | NEW |