| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/layer_tree_json_parser.h" | 5 #include "cc/test/layer_tree_json_parser.h" |
| 6 | 6 |
| 7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "cc/test/fake_impl_proxy.h" | 8 #include "cc/test/fake_impl_proxy.h" |
| 9 #include "cc/test/fake_layer_tree_host.h" | 9 #include "cc/test/fake_layer_tree_host.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
| 12 #include "cc/test/test_task_graph_runner.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 bool LayerTreesMatch(LayerImpl* const layer_impl, | 19 bool LayerTreesMatch(LayerImpl* const layer_impl, |
| 19 Layer* const layer) { | 20 Layer* const layer) { |
| 20 #define RETURN_IF_EXPECTATION_FAILS(exp) \ | 21 #define RETURN_IF_EXPECTATION_FAILS(exp) \ |
| 21 do { \ | 22 do { \ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 class LayerTreeJsonParserSanityCheck : public testing::Test { | 63 class LayerTreeJsonParserSanityCheck : public testing::Test { |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 TEST_F(LayerTreeJsonParserSanityCheck, Basic) { | 66 TEST_F(LayerTreeJsonParserSanityCheck, Basic) { |
| 66 FakeImplProxy proxy; | 67 FakeImplProxy proxy; |
| 67 TestSharedBitmapManager shared_bitmap_manager; | 68 TestSharedBitmapManager shared_bitmap_manager; |
| 68 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | 69 TestTaskGraphRunner task_graph_runner; |
| 70 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, |
| 71 &task_graph_runner); |
| 69 LayerTreeImpl* tree = host_impl.active_tree(); | 72 LayerTreeImpl* tree = host_impl.active_tree(); |
| 70 | 73 |
| 71 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1)); | 74 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1)); |
| 72 scoped_ptr<LayerImpl> parent(LayerImpl::Create(tree, 2)); | 75 scoped_ptr<LayerImpl> parent(LayerImpl::Create(tree, 2)); |
| 73 scoped_ptr<LayerImpl> child(LayerImpl::Create(tree, 3)); | 76 scoped_ptr<LayerImpl> child(LayerImpl::Create(tree, 3)); |
| 74 | 77 |
| 75 root_impl->SetBounds(gfx::Size(100, 100)); | 78 root_impl->SetBounds(gfx::Size(100, 100)); |
| 76 parent->SetBounds(gfx::Size(50, 50)); | 79 parent->SetBounds(gfx::Size(50, 50)); |
| 77 child->SetBounds(gfx::Size(40, 40)); | 80 child->SetBounds(gfx::Size(40, 40)); |
| 78 | 81 |
| 79 parent->SetPosition(gfx::Point(25, 25)); | 82 parent->SetPosition(gfx::Point(25, 25)); |
| 80 | 83 |
| 81 child->SetHaveWheelEventHandlers(true); | 84 child->SetHaveWheelEventHandlers(true); |
| 82 child->SetHaveScrollEventHandlers(true); | 85 child->SetHaveScrollEventHandlers(true); |
| 83 | 86 |
| 84 parent->AddChild(child.Pass()); | 87 parent->AddChild(child.Pass()); |
| 85 root_impl->AddChild(parent.Pass()); | 88 root_impl->AddChild(parent.Pass()); |
| 86 tree->SetRootLayer(root_impl.Pass()); | 89 tree->SetRootLayer(root_impl.Pass()); |
| 87 | 90 |
| 88 std::string json = host_impl.LayerTreeAsJson(); | 91 std::string json = host_impl.LayerTreeAsJson(); |
| 89 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL); | 92 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL); |
| 90 ASSERT_TRUE(root.get()); | 93 ASSERT_TRUE(root.get()); |
| 91 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get())); | 94 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get())); |
| 92 } | 95 } |
| 93 | 96 |
| 94 TEST_F(LayerTreeJsonParserSanityCheck, EventHandlerRegions) { | 97 TEST_F(LayerTreeJsonParserSanityCheck, EventHandlerRegions) { |
| 95 FakeImplProxy proxy; | 98 FakeImplProxy proxy; |
| 96 TestSharedBitmapManager shared_bitmap_manager; | 99 TestSharedBitmapManager shared_bitmap_manager; |
| 97 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | 100 TestTaskGraphRunner task_graph_runner; |
| 101 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, |
| 102 &task_graph_runner); |
| 98 LayerTreeImpl* tree = host_impl.active_tree(); | 103 LayerTreeImpl* tree = host_impl.active_tree(); |
| 99 | 104 |
| 100 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1)); | 105 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1)); |
| 101 scoped_ptr<LayerImpl> touch_layer(LayerImpl::Create(tree, 2)); | 106 scoped_ptr<LayerImpl> touch_layer(LayerImpl::Create(tree, 2)); |
| 102 | 107 |
| 103 root_impl->SetBounds(gfx::Size(100, 100)); | 108 root_impl->SetBounds(gfx::Size(100, 100)); |
| 104 touch_layer->SetBounds(gfx::Size(50, 50)); | 109 touch_layer->SetBounds(gfx::Size(50, 50)); |
| 105 | 110 |
| 106 Region touch_region; | 111 Region touch_region; |
| 107 touch_region.Union(gfx::Rect(10, 10, 20, 30)); | 112 touch_region.Union(gfx::Rect(10, 10, 20, 30)); |
| 108 touch_region.Union(gfx::Rect(40, 10, 20, 20)); | 113 touch_region.Union(gfx::Rect(40, 10, 20, 20)); |
| 109 touch_layer->SetTouchEventHandlerRegion(touch_region); | 114 touch_layer->SetTouchEventHandlerRegion(touch_region); |
| 110 | 115 |
| 111 root_impl->AddChild(touch_layer.Pass()); | 116 root_impl->AddChild(touch_layer.Pass()); |
| 112 tree->SetRootLayer(root_impl.Pass()); | 117 tree->SetRootLayer(root_impl.Pass()); |
| 113 | 118 |
| 114 std::string json = host_impl.LayerTreeAsJson(); | 119 std::string json = host_impl.LayerTreeAsJson(); |
| 115 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL); | 120 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL); |
| 116 ASSERT_TRUE(root.get()); | 121 ASSERT_TRUE(root.get()); |
| 117 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get())); | 122 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get())); |
| 118 } | 123 } |
| 119 | 124 |
| 120 } // namespace cc | 125 } // namespace cc |
| OLD | NEW |