- add third_party src.
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / ui / top_view_layout_views_unittest.cc
1 // Copyright (c) 2013 Intel Corporation. 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 "xwalk/runtime/browser/ui/top_view_layout_views.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/view.h"
9
10 using views::View;
11 using xwalk::TopViewLayout;
12
13 namespace {
14
15 class TopViewLayoutTest : public testing::Test {
16  public:
17   virtual void SetUp() OVERRIDE {
18     host_.reset(new View);
19   }
20
21   scoped_ptr<View> host_;
22   scoped_ptr<TopViewLayout> layout_;
23 };
24
25 class ViewWithPreferredSize : public View {
26  public:
27   explicit ViewWithPreferredSize(const gfx::Size& preferred_size)
28       : preferred_size_(preferred_size) {}
29
30   void set_preferred_size(const gfx::Size& preferred_size) {
31     preferred_size_ = preferred_size;
32   }
33
34   // View implementation.
35   virtual gfx::Size GetPreferredSize() OVERRIDE { return preferred_size_; }
36
37  private:
38   gfx::Size preferred_size_;
39 };
40
41 }  // namespace
42
43 TEST_F(TopViewLayoutTest, OnlyContentView) {
44   layout_.reset(new TopViewLayout);
45   View* content = new View();
46   host_->AddChildView(content);
47   layout_->set_content_view(content);
48
49   host_->SetSize(gfx::Size(200, 150));
50   layout_->Layout(host_.get());
51   EXPECT_EQ(gfx::Rect(0, 0, 200, 150), content->bounds());
52
53   host_->SetSize(gfx::Size(300, 400));
54   layout_->Layout(host_.get());
55   EXPECT_EQ(gfx::Rect(0, 0, 300, 400), content->bounds());
56 }
57
58 TEST_F(TopViewLayoutTest, BothViews) {
59   layout_.reset(new TopViewLayout);
60
61   View* content = new View();
62   host_->AddChildView(content);
63   layout_->set_content_view(content);
64
65   View* top_view = new ViewWithPreferredSize(gfx::Size(200, 20));
66   host_->AddChildView(top_view);
67   layout_->set_top_view(top_view);
68
69   host_->SetSize(gfx::Size(200, 150));
70   layout_->Layout(host_.get());
71   EXPECT_EQ(gfx::Rect(0, 20, 200, 130), content->bounds());
72   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
73
74   host_->SetSize(gfx::Size(300, 400));
75   layout_->Layout(host_.get());
76   EXPECT_EQ(gfx::Rect(0, 20, 300, 380), content->bounds());
77   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
78 }
79
80 TEST_F(TopViewLayoutTest, ChangingTopViewHeight) {
81   layout_.reset(new TopViewLayout);
82
83   View* content = new View();
84   host_->AddChildView(content);
85   layout_->set_content_view(content);
86
87   ViewWithPreferredSize* top_view =
88       new ViewWithPreferredSize(gfx::Size(200, 20));
89   host_->AddChildView(top_view);
90   layout_->set_top_view(top_view);
91
92   host_->SetSize(gfx::Size(200, 150));
93   layout_->Layout(host_.get());
94   EXPECT_EQ(gfx::Rect(0, 20, 200, 130), content->bounds());
95   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
96
97   top_view->set_preferred_size(gfx::Size(100, 100));
98   layout_->Layout(host_.get());
99   EXPECT_EQ(gfx::Rect(0, 100, 200, 50), content->bounds());
100   EXPECT_EQ(gfx::Rect(0, 0, 100, 100), top_view->bounds());
101
102   host_->SetSize(gfx::Size(300, 400));
103   layout_->Layout(host_.get());
104   EXPECT_EQ(gfx::Rect(0, 100, 300, 300), content->bounds());
105   EXPECT_EQ(gfx::Rect(0, 0, 100, 100), top_view->bounds());
106
107   top_view->set_preferred_size(gfx::Size(200, 20));
108   layout_->Layout(host_.get());
109   EXPECT_EQ(gfx::Rect(0, 20, 300, 380), content->bounds());
110   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
111 }
112
113 TEST_F(TopViewLayoutTest, ChangingTopViewOverlay) {
114   layout_.reset(new TopViewLayout);
115
116   View* content = new View();
117   host_->AddChildView(content);
118   layout_->set_content_view(content);
119
120   View* top_view = new ViewWithPreferredSize(gfx::Size(200, 20));
121   host_->AddChildView(top_view);
122   layout_->set_top_view(top_view);
123
124   host_->SetSize(gfx::Size(200, 150));
125   layout_->Layout(host_.get());
126   EXPECT_EQ(gfx::Rect(0, 20, 200, 130), content->bounds());
127   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
128
129   EXPECT_FALSE(layout_->IsUsingOverlay());
130   layout_->SetUseOverlay(true);
131   EXPECT_TRUE(layout_->IsUsingOverlay());
132
133   layout_->Layout(host_.get());
134   EXPECT_EQ(gfx::Rect(0, 0, 200, 150), content->bounds());
135   EXPECT_EQ(gfx::Rect(0, 0, 200, 20), top_view->bounds());
136 }