Move a MediaCodecBridge log
[chromium-blink-merge.git] / cc / test / layer_tree_json_parser_unittest.cc
blob73aace83c1615c27155fd4c826436367163840d0
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
3 // found in the LICENSE file.
5 #include "cc/test/layer_tree_json_parser.h"
7 #include "cc/layers/layer.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host.h"
10 #include "cc/test/fake_layer_tree_host_impl.h"
11 #include "cc/test/geometry_test_utils.h"
12 #include "cc/test/test_task_graph_runner.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace cc {
17 namespace {
19 bool LayerTreesMatch(LayerImpl* const layer_impl,
20 Layer* const layer) {
21 #define RETURN_IF_EXPECTATION_FAILS(exp) \
22 do { \
23 exp; \
24 if (testing::UnitTest::GetInstance()->current_test_info()-> \
25 result()->Failed()) \
26 return false; \
27 } while (0)
29 RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->children().size(),
30 layer->children().size()));
31 RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->bounds(), layer->bounds()));
32 RETURN_IF_EXPECTATION_FAILS(
33 EXPECT_EQ(layer_impl->position(), layer->position()));
34 RETURN_IF_EXPECTATION_FAILS(
35 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_impl->draw_transform(),
36 layer->draw_transform()));
37 RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->contents_opaque(),
38 layer->contents_opaque()));
39 RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->scrollable(),
40 layer->scrollable()));
41 RETURN_IF_EXPECTATION_FAILS(EXPECT_FLOAT_EQ(layer_impl->opacity(),
42 layer->opacity()));
43 RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->have_wheel_event_handlers(),
44 layer->have_wheel_event_handlers()));
45 RETURN_IF_EXPECTATION_FAILS(
46 EXPECT_EQ(layer_impl->have_scroll_event_handlers(),
47 layer->have_scroll_event_handlers()));
48 RETURN_IF_EXPECTATION_FAILS(
49 EXPECT_EQ(layer_impl->touch_event_handler_region(),
50 layer->touch_event_handler_region()));
52 for (size_t i = 0; i < layer_impl->children().size(); ++i) {
53 RETURN_IF_EXPECTATION_FAILS(EXPECT_TRUE(LayerTreesMatch(
54 layer_impl->children()[i], layer->children()[i].get())));
57 return true;
58 #undef RETURN_IF_EXPECTATION_FAILS
61 } // namespace
63 class LayerTreeJsonParserSanityCheck : public testing::Test {
66 TEST_F(LayerTreeJsonParserSanityCheck, Basic) {
67 FakeImplProxy proxy;
68 TestSharedBitmapManager shared_bitmap_manager;
69 TestTaskGraphRunner task_graph_runner;
70 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
71 &task_graph_runner);
72 LayerTreeImpl* tree = host_impl.active_tree();
74 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1));
75 scoped_ptr<LayerImpl> parent(LayerImpl::Create(tree, 2));
76 scoped_ptr<LayerImpl> child(LayerImpl::Create(tree, 3));
78 root_impl->SetBounds(gfx::Size(100, 100));
79 parent->SetBounds(gfx::Size(50, 50));
80 child->SetBounds(gfx::Size(40, 40));
82 parent->SetPosition(gfx::Point(25, 25));
84 child->SetHaveWheelEventHandlers(true);
85 child->SetHaveScrollEventHandlers(true);
87 parent->AddChild(child.Pass());
88 root_impl->AddChild(parent.Pass());
89 tree->SetRootLayer(root_impl.Pass());
91 std::string json = host_impl.LayerTreeAsJson();
92 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL);
93 ASSERT_TRUE(root.get());
94 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get()));
97 TEST_F(LayerTreeJsonParserSanityCheck, EventHandlerRegions) {
98 FakeImplProxy proxy;
99 TestSharedBitmapManager shared_bitmap_manager;
100 TestTaskGraphRunner task_graph_runner;
101 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
102 &task_graph_runner);
103 LayerTreeImpl* tree = host_impl.active_tree();
105 scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1));
106 scoped_ptr<LayerImpl> touch_layer(LayerImpl::Create(tree, 2));
108 root_impl->SetBounds(gfx::Size(100, 100));
109 touch_layer->SetBounds(gfx::Size(50, 50));
111 Region touch_region;
112 touch_region.Union(gfx::Rect(10, 10, 20, 30));
113 touch_region.Union(gfx::Rect(40, 10, 20, 20));
114 touch_layer->SetTouchEventHandlerRegion(touch_region);
116 root_impl->AddChild(touch_layer.Pass());
117 tree->SetRootLayer(root_impl.Pass());
119 std::string json = host_impl.LayerTreeAsJson();
120 scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL);
121 ASSERT_TRUE(root.get());
122 EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get()));
125 } // namespace cc