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

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

Issue 1702473002: Make SingleSplitView take borders into account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adapted unittest Created 4 years, 10 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
« no previous file with comments | « ui/views/controls/single_split_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/single_split_view.h" 5 #include "ui/views/controls/single_split_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/events/event_utils.h" 12 #include "ui/events/event_utils.h"
13 #include "ui/views/border.h"
13 #include "ui/views/controls/single_split_view_listener.h" 14 #include "ui/views/controls/single_split_view_listener.h"
14 15
15 namespace { 16 namespace {
16 17
17 static void VerifySplitViewLayout(const views::SingleSplitView& split) { 18 static void VerifySplitViewLayout(const views::SingleSplitView& split) {
18 ASSERT_EQ(2, split.child_count()); 19 ASSERT_EQ(2, split.child_count());
19 20
20 const views::View* leading = split.child_at(0); 21 const views::View* leading = split.child_at(0);
21 const views::View* trailing = split.child_at(1); 22 const views::View* trailing = split.child_at(1);
22 23
23 if (split.bounds().IsEmpty()) { 24 if (split.bounds().IsEmpty()) {
24 EXPECT_TRUE(leading->bounds().IsEmpty()); 25 EXPECT_TRUE(leading->bounds().IsEmpty());
25 EXPECT_TRUE(trailing->bounds().IsEmpty()); 26 EXPECT_TRUE(trailing->bounds().IsEmpty());
26 return; 27 return;
27 } 28 }
28 29
29 EXPECT_FALSE(leading->bounds().IsEmpty()); 30 EXPECT_FALSE(leading->bounds().IsEmpty());
30 EXPECT_FALSE(trailing->bounds().IsEmpty()); 31 EXPECT_FALSE(trailing->bounds().IsEmpty());
31 EXPECT_FALSE(leading->bounds().Intersects(trailing->bounds())); 32 EXPECT_FALSE(leading->bounds().Intersects(trailing->bounds()));
32 33
33 if (split.orientation() == views::SingleSplitView::HORIZONTAL_SPLIT) { 34 if (split.orientation() == views::SingleSplitView::HORIZONTAL_SPLIT) {
34 EXPECT_EQ(leading->bounds().height(), split.bounds().height()); 35 EXPECT_EQ(leading->bounds().height(),
35 EXPECT_EQ(trailing->bounds().height(), split.bounds().height()); 36 split.bounds().height() - split.GetInsets().height());
37 EXPECT_EQ(trailing->bounds().height(),
38 split.bounds().height() - split.GetInsets().height());
36 EXPECT_LT(leading->bounds().width() + trailing->bounds().width(), 39 EXPECT_LT(leading->bounds().width() + trailing->bounds().width(),
37 split.bounds().width()); 40 split.bounds().width() - split.GetInsets().width());
38 } else if (split.orientation() == views::SingleSplitView::VERTICAL_SPLIT) { 41 } else if (split.orientation() == views::SingleSplitView::VERTICAL_SPLIT) {
39 EXPECT_EQ(leading->bounds().width(), split.bounds().width()); 42 EXPECT_EQ(leading->bounds().width(),
40 EXPECT_EQ(trailing->bounds().width(), split.bounds().width()); 43 split.bounds().width() - split.GetInsets().width());
44 EXPECT_EQ(trailing->bounds().width(),
45 split.bounds().width() - split.GetInsets().width());
41 EXPECT_LT(leading->bounds().height() + trailing->bounds().height(), 46 EXPECT_LT(leading->bounds().height() + trailing->bounds().height(),
42 split.bounds().height()); 47 split.bounds().height() - split.GetInsets().height());
43 } else { 48 } else {
44 NOTREACHED(); 49 NOTREACHED();
45 } 50 }
46 } 51 }
47 52
48 class SingleSplitViewListenerImpl : public views::SingleSplitViewListener { 53 class SingleSplitViewListenerImpl : public views::SingleSplitViewListener {
49 public: 54 public:
50 SingleSplitViewListenerImpl() : count_(0) {} 55 SingleSplitViewListenerImpl() : count_(0) {}
51 56
52 bool SplitHandleMoved(views::SingleSplitView* sender) override { 57 bool SplitHandleMoved(views::SingleSplitView* sender) override {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 { false, 500, 100, 133 }, 107 { false, 500, 100, 133 },
103 // Resize the split view by secondary axis, divider should not move. 108 // Resize the split view by secondary axis, divider should not move.
104 { false, 500, 600, 133 } 109 { false, 500, 600, 133 }
105 }; 110 };
106 111
107 SingleSplitView::Orientation orientations[] = { 112 SingleSplitView::Orientation orientations[] = {
108 SingleSplitView::HORIZONTAL_SPLIT, 113 SingleSplitView::HORIZONTAL_SPLIT,
109 SingleSplitView::VERTICAL_SPLIT 114 SingleSplitView::VERTICAL_SPLIT
110 }; 115 };
111 116
117 int borders[][4] = {
118 {0, 0, 0, 0}, {5, 5, 5, 5}, {10, 5, 5, 0},
119 };
120
112 for (size_t orientation = 0; orientation < arraysize(orientations); 121 for (size_t orientation = 0; orientation < arraysize(orientations);
113 ++orientation) { 122 ++orientation) {
114 // Create a split view. 123 for (size_t border = 0; border < arraysize(borders); ++border) {
115 SingleSplitView split( 124 // Create a split view.
116 new View(), new View(), orientations[orientation], NULL); 125 SingleSplitView split(new View(), new View(), orientations[orientation],
126 NULL);
117 127
118 // Set initial size and divider offset. 128 // Set initial size and divider offset.
119 EXPECT_EQ(test_cases[0].primary_axis_size, 129 EXPECT_EQ(test_cases[0].primary_axis_size,
120 test_cases[0].secondary_axis_size); 130 test_cases[0].secondary_axis_size);
121 split.SetBounds(0, 0, test_cases[0].primary_axis_size, 131 split.SetBounds(0, 0, test_cases[0].primary_axis_size,
122 test_cases[0].secondary_axis_size); 132 test_cases[0].secondary_axis_size);
123 split.set_divider_offset(test_cases[0].divider_offset);
124 split.Layout();
125 133
126 // Run all test cases. 134 if (border != 0)
127 for (size_t i = 0; i < arraysize(test_cases); ++i) { 135 split.SetBorder(
128 split.set_resize_leading_on_bounds_change( 136 Border::CreateEmptyBorder(borders[border][0], borders[border][1],
129 test_cases[i].resize_leading_on_bounds_change); 137 borders[border][2], borders[border][3]));
130 if (split.orientation() == SingleSplitView::HORIZONTAL_SPLIT) { 138
131 split.SetBounds(0, 0, test_cases[i].primary_axis_size, 139 split.set_divider_offset(test_cases[0].divider_offset);
132 test_cases[i].secondary_axis_size); 140 split.Layout();
133 } else { 141
134 split.SetBounds(0, 0, test_cases[i].secondary_axis_size, 142 // Run all test cases.
135 test_cases[i].primary_axis_size); 143 for (size_t i = 0; i < arraysize(test_cases); ++i) {
144 split.set_resize_leading_on_bounds_change(
145 test_cases[i].resize_leading_on_bounds_change);
146 if (split.orientation() == SingleSplitView::HORIZONTAL_SPLIT) {
147 split.SetBounds(0, 0, test_cases[i].primary_axis_size,
148 test_cases[i].secondary_axis_size);
149 } else {
150 split.SetBounds(0, 0, test_cases[i].secondary_axis_size,
151 test_cases[i].primary_axis_size);
152 }
153
154 EXPECT_EQ(test_cases[i].divider_offset, split.divider_offset());
155 VerifySplitViewLayout(split);
136 } 156 }
137 157
138 EXPECT_EQ(test_cases[i].divider_offset, split.divider_offset()); 158 // Special cases, one of the child views is hidden.
139 VerifySplitViewLayout(split); 159 split.child_at(0)->SetVisible(false);
160 split.Layout();
161
162 EXPECT_EQ(split.GetContentsBounds().size(), split.child_at(1)->size());
163
164 split.child_at(0)->SetVisible(true);
165 split.child_at(1)->SetVisible(false);
166 split.Layout();
167
168 EXPECT_EQ(split.GetContentsBounds().size(), split.child_at(0)->size());
140 } 169 }
141
142 // Special cases, one of the child views is hidden.
143 split.child_at(0)->SetVisible(false);
144 split.Layout();
145
146 EXPECT_EQ(split.size(), split.child_at(1)->size());
147
148 split.child_at(0)->SetVisible(true);
149 split.child_at(1)->SetVisible(false);
150 split.Layout();
151
152 EXPECT_EQ(split.size(), split.child_at(0)->size());
153 } 170 }
154 } 171 }
155 172
156 TEST(SingleSplitViewTest, MouseDrag) { 173 TEST(SingleSplitViewTest, MouseDrag) {
157 const int kMinimumChildSize = 25; 174 const int kMinimumChildSize = 25;
158 MinimumSizedView *child0 = 175 MinimumSizedView *child0 =
159 new MinimumSizedView(gfx::Size(5, kMinimumChildSize)); 176 new MinimumSizedView(gfx::Size(5, kMinimumChildSize));
160 MinimumSizedView *child1 = 177 MinimumSizedView *child1 =
161 new MinimumSizedView(gfx::Size(5, kMinimumChildSize)); 178 new MinimumSizedView(gfx::Size(5, kMinimumChildSize));
162 SingleSplitViewListenerImpl listener; 179 SingleSplitViewListenerImpl listener;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 split.divider_offset()); 242 split.divider_offset());
226 243
227 // Expect intial offset after a system/user gesture cancels the drag. 244 // Expect intial offset after a system/user gesture cancels the drag.
228 // This shouldn't occur after mouse release, but it's sufficient for testing. 245 // This shouldn't occur after mouse release, but it's sufficient for testing.
229 split.OnMouseCaptureLost(); 246 split.OnMouseCaptureLost();
230 EXPECT_EQ(kInitialDividerOffset, split.divider_offset()); 247 EXPECT_EQ(kInitialDividerOffset, split.divider_offset());
231 EXPECT_EQ(5, listener.count()); 248 EXPECT_EQ(5, listener.count());
232 } 249 }
233 250
234 } // namespace views 251 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/single_split_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698