OLD | NEW |
(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/layers/layer.h" |
| 8 #include "cc/proto/layer.pb.h" |
| 9 #include "cc/trees/layer_tree_settings.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 TEST(LayerProtoConverterTest, TestKeepingRoot) { |
| 15 /* Test deserialization of a tree that looks like: |
| 16 root |
| 17 / \ |
| 18 a b |
| 19 \ |
| 20 c |
| 21 The old root node will be reused during deserialization. |
| 22 */ |
| 23 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
| 24 proto::LayerNode root_node; |
| 25 root_node.set_id(old_root->id()); |
| 26 root_node.set_type(proto::LayerType::Base); |
| 27 |
| 28 proto::LayerNode* child_a_node = root_node.add_children(); |
| 29 child_a_node->set_id(442); |
| 30 child_a_node->set_type(proto::LayerType::Base); |
| 31 child_a_node->set_parent_id(old_root->id()); // root_node |
| 32 |
| 33 proto::LayerNode* child_b_node = root_node.add_children(); |
| 34 child_b_node->set_id(443); |
| 35 child_b_node->set_type(proto::LayerType::Base); |
| 36 child_b_node->set_parent_id(old_root->id()); // root_node |
| 37 |
| 38 proto::LayerNode* child_c_node = child_b_node->add_children(); |
| 39 child_c_node->set_id(444); |
| 40 child_c_node->set_type(proto::LayerType::Base); |
| 41 child_c_node->set_parent_id(child_b_node->id()); |
| 42 |
| 43 scoped_refptr<Layer> new_root = |
| 44 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
| 45 |
| 46 // The new root should not be the same as the old root. |
| 47 EXPECT_EQ(old_root->id(), new_root->id()); |
| 48 ASSERT_EQ(2u, new_root->children().size()); |
| 49 scoped_refptr<Layer> child_a = new_root->children()[0]; |
| 50 scoped_refptr<Layer> child_b = new_root->children()[1]; |
| 51 |
| 52 EXPECT_EQ(child_a_node->id(), child_a->id()); |
| 53 EXPECT_EQ(child_b_node->id(), child_b->id()); |
| 54 |
| 55 EXPECT_EQ(0u, child_a->children().size()); |
| 56 ASSERT_EQ(1u, child_b->children().size()); |
| 57 |
| 58 scoped_refptr<Layer> child_c = child_b->children()[0]; |
| 59 EXPECT_EQ(child_c_node->id(), child_c->id()); |
| 60 } |
| 61 |
| 62 TEST(LayerProtoConverterTest, TestSwappingRoot) { |
| 63 /* Test deserialization of a tree that looks like: |
| 64 root |
| 65 / \ |
| 66 a b |
| 67 \ |
| 68 c |
| 69 The old root node will be swapped out during deserialization. |
| 70 */ |
| 71 proto::LayerNode root_node; |
| 72 root_node.set_id(441); |
| 73 root_node.set_type(proto::LayerType::Base); |
| 74 |
| 75 proto::LayerNode* child_a_node = root_node.add_children(); |
| 76 child_a_node->set_id(442); |
| 77 child_a_node->set_type(proto::LayerType::Base); |
| 78 child_a_node->set_parent_id(root_node.id()); |
| 79 |
| 80 proto::LayerNode* child_b_node = root_node.add_children(); |
| 81 child_b_node->set_id(443); |
| 82 child_b_node->set_type(proto::LayerType::Base); |
| 83 child_b_node->set_parent_id(root_node.id()); |
| 84 |
| 85 proto::LayerNode* child_c_node = child_b_node->add_children(); |
| 86 child_c_node->set_id(444); |
| 87 child_c_node->set_type(proto::LayerType::Base); |
| 88 child_c_node->set_parent_id(child_b_node->id()); |
| 89 |
| 90 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
| 91 scoped_refptr<Layer> new_root = |
| 92 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
| 93 |
| 94 // The new root should not be the same as the old root. |
| 95 EXPECT_EQ(root_node.id(), new_root->id()); |
| 96 ASSERT_EQ(2u, new_root->children().size()); |
| 97 scoped_refptr<Layer> child_a = new_root->children()[0]; |
| 98 scoped_refptr<Layer> child_b = new_root->children()[1]; |
| 99 |
| 100 EXPECT_EQ(child_a_node->id(), child_a->id()); |
| 101 EXPECT_EQ(child_b_node->id(), child_b->id()); |
| 102 |
| 103 EXPECT_EQ(0u, child_a->children().size()); |
| 104 ASSERT_EQ(1u, child_b->children().size()); |
| 105 |
| 106 scoped_refptr<Layer> child_c = child_b->children()[0]; |
| 107 EXPECT_EQ(child_c_node->id(), child_c->id()); |
| 108 } |
| 109 |
| 110 } // namespace cc |
OLD | NEW |