Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / message_center / views / bounded_scroll_view_unittest.cc
1 // Copyright 2014 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 "ui/message_center/views/bounded_scroll_view.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/size.h"
10 #include "ui/views/test/test_views.h"
11
12 namespace message_center {
13
14 namespace test {
15
16 const int kMinHeight = 50;
17 const int kMaxHeight = 100;
18
19 const int kWidth = 100;
20
21 class BoundedScrollViewTest : public testing::Test {
22  public:
23   BoundedScrollViewTest() {}
24   virtual ~BoundedScrollViewTest() {}
25
26   virtual void SetUp() OVERRIDE {
27     scroller_.reset(
28         new message_center::BoundedScrollView(kMinHeight, kMaxHeight));
29   }
30
31   virtual void TearDown() OVERRIDE { scroller_.reset(); }
32
33  protected:
34   message_center::BoundedScrollView* scroller() { return scroller_.get(); }
35
36  private:
37   scoped_ptr<message_center::BoundedScrollView> scroller_;
38 };
39
40 TEST_F(BoundedScrollViewTest, NormalSizeContentTest) {
41   const int kNormalContentHeight = 75;
42   scroller()->SetContents(
43       new views::StaticSizedView(gfx::Size(kWidth, kNormalContentHeight)));
44
45   EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight),
46             scroller()->GetPreferredSize());
47
48   scroller()->SizeToPreferredSize();
49   scroller()->Layout();
50
51   EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight),
52             scroller()->contents()->size());
53   EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight), scroller()->size());
54 }
55
56 TEST_F(BoundedScrollViewTest, ShortContentTest) {
57   const int kShortContentHeight = 10;
58   scroller()->SetContents(
59       new views::StaticSizedView(gfx::Size(kWidth, kShortContentHeight)));
60
61   EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroller()->GetPreferredSize());
62
63   scroller()->SizeToPreferredSize();
64   scroller()->Layout();
65
66   EXPECT_EQ(gfx::Size(kWidth, kShortContentHeight),
67             scroller()->contents()->size());
68   EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroller()->size());
69 }
70
71 TEST_F(BoundedScrollViewTest, TallContentTest) {
72   const int kTallContentHeight = 1000;
73   scroller()->SetContents(
74       new views::StaticSizedView(gfx::Size(kWidth, kTallContentHeight)));
75
76   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroller()->GetPreferredSize());
77
78   scroller()->SizeToPreferredSize();
79   scroller()->Layout();
80
81   EXPECT_EQ(gfx::Size(kWidth, kTallContentHeight),
82             scroller()->contents()->size());
83   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroller()->size());
84 }
85
86 TEST_F(BoundedScrollViewTest, NeedsScrollBarTest) {
87   // Create a view that will be much taller than it is high.
88   scroller()->SetContents(new views::ProportionallySizedView(1000));
89
90   // Without any width, it will default to 0,0 but be overridden by min height.
91   scroller()->SizeToPreferredSize();
92   EXPECT_EQ(gfx::Size(0, kMinHeight), scroller()->GetPreferredSize());
93
94   gfx::Size new_size(kWidth, scroller()->GetHeightForWidth(kWidth));
95   scroller()->SetSize(new_size);
96   scroller()->Layout();
97
98   int scroll_bar_width = scroller()->GetScrollBarWidth();
99   int expected_width = kWidth - scroll_bar_width;
100   EXPECT_EQ(scroller()->contents()->size().width(), expected_width);
101   EXPECT_EQ(scroller()->contents()->size().height(), 1000 * expected_width);
102   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroller()->size());
103 }
104
105 }  // namespace test
106
107 }  // namespace message_center