summaryrefslogtreecommitdiffstats
path: root/chromium/ui/views/controls/scroll_view_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/controls/scroll_view_unittest.cc')
-rw-r--r--chromium/ui/views/controls/scroll_view_unittest.cc103
1 files changed, 100 insertions, 3 deletions
diff --git a/chromium/ui/views/controls/scroll_view_unittest.cc b/chromium/ui/views/controls/scroll_view_unittest.cc
index f0bdbd5443d..8f34377553f 100644
--- a/chromium/ui/views/controls/scroll_view_unittest.cc
+++ b/chromium/ui/views/controls/scroll_view_unittest.cc
@@ -5,11 +5,17 @@
#include "ui/views/controls/scroll_view.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
+#include "ui/views/test/test_views.h"
namespace views {
namespace {
+const int kWidth = 100;
+const int kMinHeight = 50;
+const int kMaxHeight = 100;
+
// View implementation that allows setting the preferred size.
class CustomView : public View {
public:
@@ -20,7 +26,7 @@ class CustomView : public View {
PreferredSizeChanged();
}
- virtual gfx::Size GetPreferredSize() OVERRIDE {
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
return preferred_size_;
}
@@ -148,7 +154,6 @@ TEST(ScrollViewTest, ScrollBarsWithHeader) {
ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
-
// Size the contents such that horizontal scrollbar is needed.
contents->SetBounds(0, 0, 400, 50);
scroll_view.Layout();
@@ -214,7 +219,6 @@ TEST(ScrollViewTest, HeaderScrollsWithContent) {
EXPECT_EQ("-1,0", header->bounds().origin().ToString());
}
-
// Verifies ScrollRectToVisible() on the child works.
TEST(ScrollViewTest, ScrollRectToVisible) {
ScrollView scroll_view;
@@ -237,4 +241,97 @@ TEST(ScrollViewTest, ScrollRectToVisible) {
EXPECT_EQ(-(415 - viewport_height), contents->y());
}
+// Verifies ClipHeightTo() uses the height of the content when it is between the
+// minimum and maximum height values.
+TEST(ScrollViewTest, ClipHeightToNormalContentHeight) {
+ ScrollView scroll_view;
+
+ scroll_view.ClipHeightTo(kMinHeight, kMaxHeight);
+
+ const int kNormalContentHeight = 75;
+ scroll_view.SetContents(
+ new views::StaticSizedView(gfx::Size(kWidth, kNormalContentHeight)));
+
+ EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight),
+ scroll_view.GetPreferredSize());
+
+ scroll_view.SizeToPreferredSize();
+ scroll_view.Layout();
+
+ EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight),
+ scroll_view.contents()->size());
+ EXPECT_EQ(gfx::Size(kWidth, kNormalContentHeight), scroll_view.size());
+}
+
+// Verifies ClipHeightTo() uses the minimum height when the content is shorter
+// thamn the minimum height value.
+TEST(ScrollViewTest, ClipHeightToShortContentHeight) {
+ ScrollView scroll_view;
+
+ scroll_view.ClipHeightTo(kMinHeight, kMaxHeight);
+
+ const int kShortContentHeight = 10;
+ scroll_view.SetContents(
+ new views::StaticSizedView(gfx::Size(kWidth, kShortContentHeight)));
+
+ EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroll_view.GetPreferredSize());
+
+ scroll_view.SizeToPreferredSize();
+ scroll_view.Layout();
+
+ EXPECT_EQ(gfx::Size(kWidth, kShortContentHeight),
+ scroll_view.contents()->size());
+ EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroll_view.size());
+}
+
+// Verifies ClipHeightTo() uses the maximum height when the content is longer
+// thamn the maximum height value.
+TEST(ScrollViewTest, ClipHeightToTallContentHeight) {
+ ScrollView scroll_view;
+
+ // Use a scrollbar that is disabled by default, so the width of the content is
+ // not affected.
+ scroll_view.SetVerticalScrollBar(new views::OverlayScrollBar(false));
+
+ scroll_view.ClipHeightTo(kMinHeight, kMaxHeight);
+
+ const int kTallContentHeight = 1000;
+ scroll_view.SetContents(
+ new views::StaticSizedView(gfx::Size(kWidth, kTallContentHeight)));
+
+ EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.GetPreferredSize());
+
+ scroll_view.SizeToPreferredSize();
+ scroll_view.Layout();
+
+ EXPECT_EQ(gfx::Size(kWidth, kTallContentHeight),
+ scroll_view.contents()->size());
+ EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size());
+}
+
+// Verifies that when ClipHeightTo() produces a scrollbar, it reduces the width
+// of the inner content of the ScrollView.
+TEST(ScrollViewTest, ClipHeightToScrollbarUsesWidth) {
+ ScrollView scroll_view;
+
+ scroll_view.ClipHeightTo(kMinHeight, kMaxHeight);
+
+ // Create a view that will be much taller than it is wide.
+ scroll_view.SetContents(new views::ProportionallySizedView(1000));
+
+ // Without any width, it will default to 0,0 but be overridden by min height.
+ scroll_view.SizeToPreferredSize();
+ EXPECT_EQ(gfx::Size(0, kMinHeight), scroll_view.GetPreferredSize());
+
+ gfx::Size new_size(kWidth, scroll_view.GetHeightForWidth(kWidth));
+ scroll_view.SetSize(new_size);
+ scroll_view.Layout();
+
+ int scroll_bar_width = scroll_view.GetScrollBarWidth();
+ int expected_width = kWidth - scroll_bar_width;
+ EXPECT_EQ(scroll_view.contents()->size().width(), expected_width);
+ EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width);
+ EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size());
+}
+
} // namespace views