Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / test / layer_tree_json_parser_unittest.cc
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.
4
5 #include "cc/test/layer_tree_json_parser.h"
6
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 "testing/gtest/include/gtest/gtest.h"
13
14 namespace cc {
15
16 namespace {
17
18 bool LayerTreesMatch(LayerImpl* const layer_impl,
19                      Layer* const layer) {
20 #define RETURN_IF_EXPECTATION_FAILS(exp) \
21   do { \
22     exp; \
23     if (testing::UnitTest::GetInstance()->current_test_info()-> \
24             result()->Failed()) \
25       return false; \
26   } while (0)
27
28   RETURN_IF_EXPECTATION_FAILS(EXPECT_EQ(layer_impl->children().size(),
29                                         layer->children().size()));
30   RETURN_IF_EXPECTATION_FAILS(EXPECT_SIZE_EQ(layer_impl->bounds(),
31                                              layer->bounds()));
32   RETURN_IF_EXPECTATION_FAILS(EXPECT_POINT_EQ(layer_impl->position(),
33                                               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()));
51
52   for (size_t i = 0; i < layer_impl->children().size(); ++i) {
53     RETURN_IF_EXPECTATION_FAILS(
54         EXPECT_TRUE(LayerTreesMatch(layer_impl->children()[i],
55                                     layer->children()[i])));
56   }
57
58   return true;
59 #undef RETURN_IF_EXPECTATION_FAILS
60 }
61
62 }  // namespace
63
64 class LayerTreeJsonParserSanityCheck : public testing::Test {
65 };
66
67 TEST_F(LayerTreeJsonParserSanityCheck, Basic) {
68   FakeImplProxy proxy;
69   TestSharedBitmapManager shared_bitmap_manager;
70   FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
71   LayerTreeImpl* tree = host_impl.active_tree();
72
73   scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1));
74   scoped_ptr<LayerImpl> parent(LayerImpl::Create(tree, 2));
75   scoped_ptr<LayerImpl> child(LayerImpl::Create(tree, 3));
76
77   root_impl->SetBounds(gfx::Size(100, 100));
78   parent->SetBounds(gfx::Size(50, 50));
79   child->SetBounds(gfx::Size(40, 40));
80
81   parent->SetPosition(gfx::Point(25, 25));
82
83   child->SetHaveWheelEventHandlers(true);
84   child->SetHaveScrollEventHandlers(true);
85
86   parent->AddChild(child.Pass());
87   root_impl->AddChild(parent.Pass());
88   tree->SetRootLayer(root_impl.Pass());
89
90   std::string json = host_impl.LayerTreeAsJson();
91   scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL);
92   ASSERT_TRUE(root);
93   EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get()));
94 }
95
96 TEST_F(LayerTreeJsonParserSanityCheck, EventHandlerRegions) {
97   FakeImplProxy proxy;
98   TestSharedBitmapManager shared_bitmap_manager;
99   FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
100   LayerTreeImpl* tree = host_impl.active_tree();
101
102   scoped_ptr<LayerImpl> root_impl(LayerImpl::Create(tree, 1));
103   scoped_ptr<LayerImpl> touch_layer(LayerImpl::Create(tree, 2));
104
105   root_impl->SetBounds(gfx::Size(100, 100));
106   touch_layer->SetBounds(gfx::Size(50, 50));
107
108   Region touch_region;
109   touch_region.Union(gfx::Rect(10, 10, 20, 30));
110   touch_region.Union(gfx::Rect(40, 10, 20, 20));
111   touch_layer->SetTouchEventHandlerRegion(touch_region);
112
113   root_impl->AddChild(touch_layer.Pass());
114   tree->SetRootLayer(root_impl.Pass());
115
116   std::string json = host_impl.LayerTreeAsJson();
117   scoped_refptr<Layer> root = ParseTreeFromJson(json, NULL);
118   ASSERT_TRUE(root);
119   EXPECT_TRUE(LayerTreesMatch(host_impl.RootLayer(), root.get()));
120 }
121
122 }  // namespace cc