Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: views/controls/single_split_view_unittest.cc

Issue 5606012: Streamline the layout of the BrowserView's children TabContents views.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/single_split_view.cc ('k') | views/examples/single_split_view_example.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "base/logging.h"
6 #include "testing/gmock/include/gmock/gmock.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "views/controls/single_split_view.h"
9
10 using ::testing::_;
11 using ::testing::Return;
12
13 namespace {
14
15 static void VerifySplitViewLayout(const views::SingleSplitView& split) {
16 ASSERT_EQ(2, split.GetChildViewCount());
17
18 views::View* leading = split.GetChildViewAt(0);
19 views::View* trailing = split.GetChildViewAt(1);
20
21 if (split.bounds().IsEmpty()) {
22 EXPECT_TRUE(leading->bounds().IsEmpty());
23 EXPECT_TRUE(trailing->bounds().IsEmpty());
24 return;
25 }
26
27 EXPECT_FALSE(leading->bounds().IsEmpty());
28 EXPECT_FALSE(trailing->bounds().IsEmpty());
29 EXPECT_FALSE(leading->bounds().Intersects(trailing->bounds()));
30
31 if (split.orientation() == views::SingleSplitView::HORIZONTAL_SPLIT) {
32 EXPECT_EQ(leading->bounds().height(), split.bounds().height());
33 EXPECT_EQ(trailing->bounds().height(), split.bounds().height());
34 EXPECT_LT(leading->bounds().width() + trailing->bounds().width(),
35 split.bounds().width());
36 } else if (split.orientation() == views::SingleSplitView::VERTICAL_SPLIT) {
37 EXPECT_EQ(leading->bounds().width(), split.bounds().width());
38 EXPECT_EQ(trailing->bounds().width(), split.bounds().width());
39 EXPECT_LT(leading->bounds().height() + trailing->bounds().height(),
40 split.bounds().height());
41 } else {
42 NOTREACHED();
43 }
44 }
45
46 class MockObserver : public views::SingleSplitView::Observer {
47 public:
48 MOCK_METHOD1(SplitHandleMoved, bool(views::SingleSplitView*));
49 };
50
51 } // namespace
52
53 namespace views {
54
55 TEST(SingleSplitViewTest, Resize) {
56 // Test cases to iterate through for horizontal and vertical split views.
57 struct TestCase {
58 // Split view resize policy for this test case.
59 bool resize_leading_on_bounds_change;
60 // Split view size to set.
61 int primary_axis_size;
62 int secondary_axis_size;
63 // Expected divider offset.
64 int divider_offset;
65 } test_cases[] = {
66 // The initial split size is 100x100, divider at 33.
67 { true, 100, 100, 33 },
68 // Grow the split view, leading view should grow.
69 { true, 1000, 100, 933 },
70 // Shrink the split view, leading view should shrink.
71 { true, 200, 100, 133 },
72 // Minimize the split view, divider should not move.
73 { true, 0, 0, 133 },
74 // Restore the split view, divider should not move.
75 { false, 500, 100, 133 },
76 // Resize the split view by secondary axis, divider should not move.
77 { false, 500, 600, 133 }
78 };
79
80 SingleSplitView::Orientation orientations[] = {
81 SingleSplitView::HORIZONTAL_SPLIT,
82 SingleSplitView::VERTICAL_SPLIT
83 };
84
85 for (int orientation = 0; orientation < arraysize(orientations);
86 ++orientation) {
87 // Create a split view.
88 SingleSplitView split(
89 new View(), new View(), orientations[orientation], NULL);
90
91 // Set initial size and divider offset.
92 split.SetBounds(0, 0, 100, 100);
93 split.set_divider_offset(33);
94 split.Layout();
95
96 // Run all test cases.
97 for (int i = 0; i < arraysize(test_cases); ++i) {
98 split.set_resize_leading_on_bounds_change(
99 test_cases[i].resize_leading_on_bounds_change);
100 if (split.orientation() == SingleSplitView::HORIZONTAL_SPLIT) {
101 split.SetBounds(0, 0, test_cases[i].primary_axis_size,
102 test_cases[i].secondary_axis_size);
103 } else {
104 split.SetBounds(0, 0, test_cases[i].secondary_axis_size,
105 test_cases[i].primary_axis_size);
106 }
107
108 EXPECT_EQ(test_cases[i].divider_offset, split.divider_offset());
109 VerifySplitViewLayout(split);
110 }
111
112 // Special cases, one of the child views is hidden.
113 split.GetChildViewAt(0)->SetVisible(false);
114 split.Layout();
115
116 EXPECT_EQ(split.bounds().size(),
117 split.GetChildViewAt(1)->bounds().size());
118
119 split.GetChildViewAt(0)->SetVisible(true);
120 split.GetChildViewAt(1)->SetVisible(false);
121 split.Layout();
122
123 EXPECT_EQ(split.bounds().size(),
124 split.GetChildViewAt(0)->bounds().size());
125 }
126 }
127
128 TEST(SingleSplitViewTest, MouseDrag) {
129 MockObserver observer;
130 SingleSplitView split(
131 new View(), new View(), SingleSplitView::VERTICAL_SPLIT, &observer);
132
133 ON_CALL(observer, SplitHandleMoved(_))
134 .WillByDefault(Return(true));
135 // SplitHandleMoved is expected to be called once for every mouse move.
136 EXPECT_CALL(observer, SplitHandleMoved(_))
137 .Times(2);
138
139 split.SetBounds(0, 0, 10, 100);
140 const int kInitialDividerOffset = 33;
141 const int kMouseOffset = 2; // Mouse offset in the divider.
142 const int kMouseMoveDelta = 7;
143 split.set_divider_offset(kInitialDividerOffset);
144 split.Layout();
145
146 // Drag divider to the right, in 2 steps.
147 ASSERT_TRUE(split.OnMousePressed(MouseEvent(
148 Event::ET_MOUSE_PRESSED, 7,
149 kInitialDividerOffset + kMouseOffset, 0)));
150 EXPECT_EQ(kInitialDividerOffset, split.divider_offset());
151
152 ASSERT_TRUE(split.OnMouseDragged(MouseEvent(
153 Event::ET_MOUSE_DRAGGED, 5,
154 kInitialDividerOffset + kMouseOffset + kMouseMoveDelta, 0)));
155 EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta, split.divider_offset());
156
157 ASSERT_TRUE(split.OnMouseDragged(MouseEvent(
158 Event::ET_MOUSE_DRAGGED, 6,
159 kInitialDividerOffset + kMouseOffset + kMouseMoveDelta * 2, 0)));
160 EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta * 2,
161 split.divider_offset());
162
163 split.OnMouseReleased(MouseEvent(
164 Event::ET_MOUSE_RELEASED, 7,
165 kInitialDividerOffset + kMouseOffset + kMouseMoveDelta * 2, 0), false);
166 EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta * 2,
167 split.divider_offset());
168 }
169
170 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/single_split_view.cc ('k') | views/examples/single_split_view_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698