summaryrefslogtreecommitdiffstats
path: root/views/controls/single_split_view_unittest.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-13 00:12:35 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-13 00:12:35 +0000
commit1d4389b306751eba8920a2f54340a75431f8a861 (patch)
treed67f00386f258bd73fc30636c2c0ec7567dbde29 /views/controls/single_split_view_unittest.cc
parent0146711d88cd3a80f802004e00198fc5ec6a1bcd (diff)
downloadchromium_src-1d4389b306751eba8920a2f54340a75431f8a861.zip
chromium_src-1d4389b306751eba8920a2f54340a75431f8a861.tar.gz
chromium_src-1d4389b306751eba8920a2f54340a75431f8a861.tar.bz2
Re-land 71230.
This restores 71230 which was reverted in 71252 by sheriff (to see if it was responsible for a linux test failure -- it was not). Original change by alekseys: Streamline the layout of the BrowserView's children TabContents views. Modify SingleSplitView to calculate its children view's bounds, but do not actually resize them and change BrowserViewLayout accordingly (BrowserViewLayout resizes all views now). Do all reserved contents rect calculations before resizing TabContents views. Rationale: to do all BrowserView layout related actions in the context of BrowserViewLayout::Layout call and to minimize actual contents re-layouts. BUG=51084 TEST=All tests should pass Review URL: http://codereview.chromium.org/5606012 Review URL: http://codereview.chromium.org/6247001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71259 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/single_split_view_unittest.cc')
-rw-r--r--views/controls/single_split_view_unittest.cc176
1 files changed, 176 insertions, 0 deletions
diff --git a/views/controls/single_split_view_unittest.cc b/views/controls/single_split_view_unittest.cc
new file mode 100644
index 0000000..b788a37
--- /dev/null
+++ b/views/controls/single_split_view_unittest.cc
@@ -0,0 +1,176 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "views/controls/single_split_view.h"
+
+using ::testing::_;
+using ::testing::Return;
+
+namespace {
+
+static void VerifySplitViewLayout(const views::SingleSplitView& split) {
+ ASSERT_EQ(2, split.GetChildViewCount());
+
+ views::View* leading = split.GetChildViewAt(0);
+ views::View* trailing = split.GetChildViewAt(1);
+
+ if (split.bounds().IsEmpty()) {
+ EXPECT_TRUE(leading->bounds().IsEmpty());
+ EXPECT_TRUE(trailing->bounds().IsEmpty());
+ return;
+ }
+
+ EXPECT_FALSE(leading->bounds().IsEmpty());
+ EXPECT_FALSE(trailing->bounds().IsEmpty());
+ EXPECT_FALSE(leading->bounds().Intersects(trailing->bounds()));
+
+ if (split.orientation() == views::SingleSplitView::HORIZONTAL_SPLIT) {
+ EXPECT_EQ(leading->bounds().height(), split.bounds().height());
+ EXPECT_EQ(trailing->bounds().height(), split.bounds().height());
+ EXPECT_LT(leading->bounds().width() + trailing->bounds().width(),
+ split.bounds().width());
+ } else if (split.orientation() == views::SingleSplitView::VERTICAL_SPLIT) {
+ EXPECT_EQ(leading->bounds().width(), split.bounds().width());
+ EXPECT_EQ(trailing->bounds().width(), split.bounds().width());
+ EXPECT_LT(leading->bounds().height() + trailing->bounds().height(),
+ split.bounds().height());
+ } else {
+ NOTREACHED();
+ }
+}
+
+class MockObserver : public views::SingleSplitView::Observer {
+ public:
+ MOCK_METHOD1(SplitHandleMoved, bool(views::SingleSplitView*));
+};
+
+} // namespace
+
+namespace views {
+
+TEST(SingleSplitViewTest, Resize) {
+ // Test cases to iterate through for horizontal and vertical split views.
+ struct TestCase {
+ // Split view resize policy for this test case.
+ bool resize_leading_on_bounds_change;
+ // Split view size to set.
+ int primary_axis_size;
+ int secondary_axis_size;
+ // Expected divider offset.
+ int divider_offset;
+ } test_cases[] = {
+ // The initial split size is 100x100, divider at 33.
+ { true, 100, 100, 33 },
+ // Grow the split view, leading view should grow.
+ { true, 1000, 100, 933 },
+ // Shrink the split view, leading view should shrink.
+ { true, 200, 100, 133 },
+ // Minimize the split view, divider should not move.
+ { true, 0, 0, 133 },
+ // Restore the split view, divider should not move.
+ { false, 500, 100, 133 },
+ // Resize the split view by secondary axis, divider should not move.
+ { false, 500, 600, 133 }
+ };
+
+ SingleSplitView::Orientation orientations[] = {
+ SingleSplitView::HORIZONTAL_SPLIT,
+ SingleSplitView::VERTICAL_SPLIT
+ };
+
+ for (size_t orientation = 0; orientation < arraysize(orientations);
+ ++orientation) {
+ // Create a split view.
+ SingleSplitView split(
+ new View(), new View(), orientations[orientation], NULL);
+
+ // Set initial size and divider offset.
+ EXPECT_EQ(test_cases[0].primary_axis_size,
+ test_cases[0].secondary_axis_size);
+ split.SetBounds(0, 0, test_cases[0].primary_axis_size,
+ test_cases[0].secondary_axis_size);
+ split.set_divider_offset(test_cases[0].divider_offset);
+ split.Layout();
+
+ // Run all test cases.
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+ split.set_resize_leading_on_bounds_change(
+ test_cases[i].resize_leading_on_bounds_change);
+ if (split.orientation() == SingleSplitView::HORIZONTAL_SPLIT) {
+ split.SetBounds(0, 0, test_cases[i].primary_axis_size,
+ test_cases[i].secondary_axis_size);
+ } else {
+ split.SetBounds(0, 0, test_cases[i].secondary_axis_size,
+ test_cases[i].primary_axis_size);
+ }
+
+ EXPECT_EQ(test_cases[i].divider_offset, split.divider_offset());
+ VerifySplitViewLayout(split);
+ }
+
+ // Special cases, one of the child views is hidden.
+ split.GetChildViewAt(0)->SetVisible(false);
+ split.Layout();
+
+ EXPECT_EQ(split.bounds().size(),
+ split.GetChildViewAt(1)->bounds().size());
+
+ split.GetChildViewAt(0)->SetVisible(true);
+ split.GetChildViewAt(1)->SetVisible(false);
+ split.Layout();
+
+ EXPECT_EQ(split.bounds().size(),
+ split.GetChildViewAt(0)->bounds().size());
+ }
+}
+
+TEST(SingleSplitViewTest, MouseDrag) {
+ MockObserver observer;
+ SingleSplitView split(
+ new View(), new View(), SingleSplitView::VERTICAL_SPLIT, &observer);
+
+ ON_CALL(observer, SplitHandleMoved(_))
+ .WillByDefault(Return(true));
+ // SplitHandleMoved is expected to be called once for every mouse move.
+ EXPECT_CALL(observer, SplitHandleMoved(_))
+ .Times(2);
+
+ split.SetBounds(0, 0, 10, 100);
+ const int kInitialDividerOffset = 33;
+ const int kMouseOffset = 2; // Mouse offset in the divider.
+ const int kMouseMoveDelta = 7;
+ split.set_divider_offset(kInitialDividerOffset);
+ split.Layout();
+
+ // Drag divider to the right, in 2 steps.
+ MouseEvent mouse_pressed(
+ Event::ET_MOUSE_PRESSED, 7, kInitialDividerOffset + kMouseOffset, 0);
+ ASSERT_TRUE(split.OnMousePressed(mouse_pressed));
+ EXPECT_EQ(kInitialDividerOffset, split.divider_offset());
+
+ MouseEvent mouse_dragged_1(
+ Event::ET_MOUSE_DRAGGED, 5,
+ kInitialDividerOffset + kMouseOffset + kMouseMoveDelta, 0);
+ ASSERT_TRUE(split.OnMouseDragged(mouse_dragged_1));
+ EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta, split.divider_offset());
+
+ MouseEvent mouse_dragged_2(
+ Event::ET_MOUSE_DRAGGED, 6,
+ kInitialDividerOffset + kMouseOffset + kMouseMoveDelta * 2, 0);
+ ASSERT_TRUE(split.OnMouseDragged(mouse_dragged_2));
+ EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta * 2,
+ split.divider_offset());
+
+ MouseEvent mouse_released(
+ Event::ET_MOUSE_RELEASED, 7,
+ kInitialDividerOffset + kMouseOffset + kMouseMoveDelta * 2, 0);
+ split.OnMouseReleased(mouse_released, false);
+ EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta * 2,
+ split.divider_offset());
+}
+
+} // namespace views