Index: cc/layers/layer_deserializer_unittest.cc |
diff --git a/cc/layers/layer_deserializer_unittest.cc b/cc/layers/layer_deserializer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c1bcc84e8cffb8b1654bc1945bf490b0b54cb074 |
--- /dev/null |
+++ b/cc/layers/layer_deserializer_unittest.cc |
@@ -0,0 +1,92 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/layers/layer_deserializer.h" |
+ |
+#include "cc/layers/layer.h" |
+#include "cc/proto/layer.pb.h" |
+#include "cc/trees/layer_tree_settings.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace cc { |
+namespace { |
+ |
+class LayerDeserializerTest : public testing::Test { |
vmpstr
2015/10/21 22:34:14
Do you need this? Can you just do TEST(LayerDeseri
nyquist
2015/10/23 00:12:31
Done.
|
+ public: |
+ LayerDeserializerTest() {} |
+}; |
+ |
+} // namespace |
+ |
+TEST_F(LayerDeserializerTest, TestKeepingRoot) { |
+ // Test deserialization of a tree that looks like: |
+ // root |
+ // / \ |
+ // a b |
+ // \ |
+ // c |
+ // The old root node will be reused during deserialization. |
+ scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
+ proto::LayerNode root_node; |
+ root_node.set_id(old_root->id()); |
+ root_node.set_type(proto::LayerType::Base); |
+ |
+ proto::LayerNode child_a_node; |
+ child_a_node.set_id(442); |
vmpstr
2015/10/21 22:34:14
Same ids for a and b?
nyquist
2015/10/23 00:12:30
Doh! Fixed.
|
+ child_a_node.set_type(proto::LayerType::Base); |
+ child_a_node.set_parent_id(old_root->id()); // root_node |
+ |
+ proto::LayerNode child_b_node; |
+ child_b_node.set_id(442); |
+ child_b_node.set_type(proto::LayerType::Base); |
+ child_b_node.set_parent_id(old_root->id()); // root_node |
+ |
+ proto::LayerNode child_c_node; |
+ child_c_node.set_id(443); |
+ child_c_node.set_type(proto::LayerType::Base); |
+ child_c_node.set_parent_id(442); // child_b_node |
+ |
+ scoped_refptr<Layer> new_root = |
+ LayerDeserializer::DeserializeLayerHierarchy(old_root, root_node); |
+ |
+ // The new root should not be the same as the old root. |
+ EXPECT_EQ(old_root->id(), new_root->id()); |
vmpstr
2015/10/21 22:34:14
Can you verify the full structure here?
nyquist
2015/10/23 00:12:30
Done here and below. Also updated how the structur
|
+} |
+ |
+TEST_F(LayerDeserializerTest, TestSwappingRoot) { |
+ // Test deserialization of a tree that looks like: |
+ // root |
+ // / \ |
+ // a b |
+ // \ |
+ // c |
+ // The old root node will be swapped out during deserialization. |
+ proto::LayerNode root_node; |
+ root_node.set_id(441); |
+ root_node.set_type(proto::LayerType::Base); |
+ |
+ proto::LayerNode child_a_node; |
+ child_a_node.set_id(442); |
+ child_a_node.set_type(proto::LayerType::Base); |
+ child_a_node.set_parent_id(441); // root_node |
+ |
+ proto::LayerNode child_b_node; |
+ child_b_node.set_id(442); |
+ child_b_node.set_type(proto::LayerType::Base); |
+ child_b_node.set_parent_id(441); // root_node |
+ |
+ proto::LayerNode child_c_node; |
+ child_c_node.set_id(443); |
+ child_c_node.set_type(proto::LayerType::Base); |
+ child_c_node.set_parent_id(442); // child_b_node |
+ |
+ scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
+ scoped_refptr<Layer> new_root = |
+ LayerDeserializer::DeserializeLayerHierarchy(old_root, root_node); |
+ |
+ // The new root should not be the same as the old root. |
+ EXPECT_EQ(441, new_root->id()); |
+} |
+ |
+} // namespace cc |