Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / tabs / stacked_tab_strip_layout_unittest.cc
blob87819b2acf0b20df5c6e81e463f330256b072cb5
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h"
7 #include <string>
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/views/view.h"
15 #include "ui/views/view_model.h"
17 namespace {
19 struct CommonTestData {
20 const int initial_x;
21 const int width;
22 const int tab_size;
23 const int tab_overlap;
24 const int stacked_offset;
25 const int pinned_tab_count;
26 const int active_index;
27 const std::string start_bounds;
28 const std::string expected_bounds;
31 } // namespace
33 class StackedTabStripLayoutTest : public testing::Test {
34 public:
35 StackedTabStripLayoutTest() {}
37 protected:
38 void Reset(StackedTabStripLayout* layout,
39 int x,
40 int width,
41 int pinned_tab_count,
42 int active_index) {
43 layout->Reset(x, width, pinned_tab_count, active_index);
46 void CreateLayout(const CommonTestData& data) {
47 if (!data.start_bounds.empty())
48 PrepareChildViewsFromString(data.start_bounds);
49 else
50 PrepareChildViewsFromString(data.expected_bounds);
51 layout_.reset(new StackedTabStripLayout(
52 gfx::Size(data.tab_size, 10), data.tab_overlap,
53 data.stacked_offset, 4, &view_model_));
54 if (data.start_bounds.empty()) {
55 PrepareChildViewsFromString(data.expected_bounds);
56 layout_->Reset(data.initial_x, data.width, data.pinned_tab_count,
57 data.active_index);
58 } else {
59 ASSERT_NO_FATAL_FAILURE(SetBoundsFromString(data.start_bounds));
60 layout_->Reset(data.initial_x, data.width, data.pinned_tab_count,
61 data.active_index);
62 ASSERT_NO_FATAL_FAILURE(SetBoundsFromString(data.start_bounds));
66 void AddViewToViewModel(int index) {
67 views::View* child_view = new views::View;
68 view_.AddChildView(child_view);
69 view_model_.Add(child_view, index);
72 void PrepareChildViewsFromString(const std::string& bounds) {
73 std::vector<base::StringPiece> positions = base::SplitStringPiece(
74 bounds, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
75 PrepareChildViews(static_cast<int>(positions.size()));
78 void PrepareChildViews(int count) {
79 view_model_.Clear();
80 view_.RemoveAllChildViews(true);
81 for (int i = 0; i < count; ++i)
82 AddViewToViewModel(i);
85 void SetBoundsFromString(const std::string& bounds) {
86 std::vector<base::StringPiece> positions = base::SplitStringPiece(
87 bounds, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
88 PrepareChildViews(static_cast<int>(positions.size()));
89 for (int i = 0; i < view_model_.view_size(); ++i) {
90 int x = 0;
91 gfx::Rect bounds(view_model_.ideal_bounds(i));
92 ASSERT_TRUE(base::StringToInt(positions[i], &x));
93 bounds.set_x(x);
94 view_model_.set_ideal_bounds(i, bounds);
98 std::string BoundsString() const {
99 std::string result;
100 for (int i = 0; i < view_model_.view_size(); ++i) {
101 if (!result.empty())
102 result += " ";
103 result += base::IntToString(view_model_.ideal_bounds(i).x());
105 return result;
108 std::string BoundsString2(int active_index) const {
109 std::string result;
110 for (int i = 0; i < view_model_.view_size(); ++i) {
111 if (!result.empty())
112 result += " ";
113 if (i == active_index)
114 result += "[";
115 result += base::IntToString(view_model_.ideal_bounds(i).x());
116 if (i == active_index)
117 result += "]";
119 return result;
122 void Validate(int active_index, int max_width) {
123 // Make sure none of the tabs are more than 90 apart
124 // (tab_size(100) + padding (-10)).
125 for (int j = 1; j < view_model_.view_size(); ++j)
126 EXPECT_LE(ideal_x(j) - ideal_x(j - 1), max_width - 100);
129 int ideal_x(int index) const {
130 return view_model_.ideal_bounds(index).x();
133 content::TestBrowserThreadBundle thread_bundle_;
134 scoped_ptr<StackedTabStripLayout> layout_;
135 views::ViewModel view_model_;
137 private:
138 views::View view_;
140 DISALLOW_COPY_AND_ASSIGN(StackedTabStripLayoutTest);
143 // Random data.
144 TEST_F(StackedTabStripLayoutTest, ValidateInitialLayout) {
145 StackedTabStripLayout layout(gfx::Size(100, 10), 10, 2, 4, &view_model_);
146 PrepareChildViews(12);
148 for (int i = 120; i < 600; ++i) {
149 for (int j = 0; j < 12; ++j) {
150 Reset(&layout, 0, i, 0, j);
151 Validate(j, i);
152 if (HasNonfatalFailure())
153 return;
158 // Ensure initial layout is correct.
159 TEST_F(StackedTabStripLayoutTest, InitialLayout) {
160 struct CommonTestData test_data[] = {
161 { 0, 198, 100, 10, 1, 0, 9, "",
162 "0 0 0 0 0 0 1 2 3 4 94 95 96 97 98 98 98 98" },
163 { 0, 198, 100, 10, 1, 0, 0, "", "0 90 94 95 96 97 98 98 98" },
164 { 0, 300, 100, 10, 1, 0, 0, "",
165 "0 90 180 196 197 198 199 200 200 200 200" },
166 { 0, 300, 100, 10, 1, 0, 10, "", "0 0 0 0 1 2 3 4 20 110 200" },
167 { 0, 300, 100, 10, 1, 0, 1, "", "0 90 180 196 197 198 199 200 200" },
168 { 0, 643, 160, 27, 6, 0, 0, "", "0 133 266 399" },
169 { 0, 300, 100, 10, 1, 0, 7, "", "0 1 2 3 4 20 110 200" },
170 { 0, 300, 100, 10, 1, 0, 6, "", "0 1 2 3 4 20 110 200" },
171 { 0, 300, 100, 10, 1, 0, 4, "", "0 1 2 3 4 94 184 199 200" },
173 for (size_t i = 0; i < arraysize(test_data); ++i) {
174 CreateLayout(test_data[i]);
175 EXPECT_EQ(test_data[i].expected_bounds, BoundsString()) << " at " << i;
179 // Assertions for dragging from an existing configuration.
180 TEST_F(StackedTabStripLayoutTest, DragActiveTabExisting) {
181 struct TestData {
182 struct CommonTestData common_data;
183 const int delta;
184 } test_data[] = {
186 // The following set of tests create 6 tabs, the first two are pinned and
187 // the 2nd tab is selected.
189 // 1 pixel to the right, should push only pinned tabs and first non-pinned
190 // tab.
191 { { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
192 "1 6 11 101 138 140" }, 1 },
193 // Push enough to collapse the 4th tab.
194 { { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
195 "36 41 46 136 138 140" }, 36 },
196 // 1 past collapsing the 4th.
197 { { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
198 "37 42 47 136 138 140" }, 37 },
199 // Collapse the third.
200 { { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
201 "124 129 134 136 138 140" }, 124 },
202 // One past collapsing the third.
203 { { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
204 "124 129 134 136 138 140" }, 125 },
207 // The following set of tests create 6 tabs, the first two are pinned and
208 // the 5th is selected.
210 // 1 pixel to the right, should expose part of a tab.
211 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140", "0 5 10 90 131 140" },
212 1 },
213 // Push the tab as far to the right as it'll go.
214 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140", "0 5 10 90 138 140" },
215 8 },
216 // One past as far to the right as it'll go. Should expose more of the tab
217 // before it.
218 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140", "0 5 10 91 138 140" },
219 9 },
220 // Enough so that the pinned tabs start pulling in.
221 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140", "1 6 11 101 138 140" },
222 19 },
223 // One more than last.
224 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140", "2 7 12 102 138 140" },
225 20 },
226 // Enough to collapse the fourth as small it can get.
227 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140",
228 "36 41 46 136 138 140" }, 54 },
229 // Enough to collapse the third as small it can get.
230 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140",
231 "124 129 134 136 138 140" }, 142 },
232 // One more than last, shouldn't change anything.
233 { { 10, 240, 100, 10, 2, 2, 4, "0 5 10 90 130 140",
234 "124 129 134 136 138 140" }, 143 },
237 // The following set of tests create 3 tabs with the second selected.
239 // Drags in 2, pulling the rightmost tab along.
240 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "2 92 140" }, 2 },
241 // Drags the rightmost tab as far to right as possible.
242 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "48 138 140" }, 48 },
243 // Drags so much that the left most tabs pulls in.
244 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "135 138 140" }, 135 },
245 // Drags so far that no more tabs pull in.
246 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "136 138 140" }, 200 },
247 // Drags to the left most position before the right tabs start pulling in.
248 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "0 50 140" }, -40 },
249 // Drags 1 beyond the left most position, which should pull in the right
250 // tab slightly.
251 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "0 49 139" }, -41 },
252 // Drags to the left as far as the tab goes.
253 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "0 2 92" }, -88 },
254 // Drags one past as far to the left as the tab goes. Should keep pulling
255 // in the rightmost tab.
256 { { 0, 240, 100, 10, 2, 0, 1, "0 90 140", "0 2 91" }, -89 },
259 for (size_t i = 0; i < arraysize(test_data); ++i) {
260 CreateLayout(test_data[i].common_data);
261 layout_->DragActiveTab(test_data[i].delta);
262 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
263 " at " << i;
267 // Assertions for SizeToFit().
268 TEST_F(StackedTabStripLayoutTest, SizeToFit) {
269 struct CommonTestData test_data[] = {
270 // Dragged to the right.
271 { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140", "1 6 11 101 138 140"},
272 { 10, 240, 100, 10, 2, 2, 1, "0 5 10 100 138 140",
273 "124 129 134 136 138 140" },
275 // Dragged to the left.
276 { 0, 240, 100, 10, 2, 0, 1, "0 50 140", "0 49 139" },
278 // Dragged to the left.
279 { 0, 240, 100, 10, 2, 0, 1, "0 49 89 140", "0 49 89 139" },
282 for (size_t i = 0; i < arraysize(test_data); ++i) {
283 CreateLayout(test_data[i]);
284 SetBoundsFromString(test_data[i].expected_bounds);
285 layout_->SizeToFit();
286 // NOTE: because of the way the code is structured this asserts on
287 // |start_bound|, not |expected_bounds|.
288 EXPECT_EQ(test_data[i].start_bounds, BoundsString()) << " at " << i;
292 // Assertions for AddTab().
293 TEST_F(StackedTabStripLayoutTest, AddTab) {
294 struct TestData {
295 CommonTestData common_data;
296 int add_index;
297 bool add_active;
298 bool add_pinned;
299 } test_data[] = {
300 // Adding a background tab test cases.
301 { { 0, 300, 100, 10, 2, 0, 1, "0 90 180 198 200", "0 16 106 196 198 200"},
302 3, false, false },
303 { { 0, 300, 100, 10, 2, 0, 1, "0 90 180 198 200", "0 2 4 20 110 200"},
304 5, false, false },
305 { { 0, 300, 100, 10, 2, 0, 1, "0 90 180 198 200", "0 90 180 196 198 200"},
306 2, false, false },
307 { { 0, 300, 100, 10, 2, 0, 1, "0 90 180 198 200", "0 2 4 94 184 200"},
308 0, false, false },
310 { { 4, 200, 100, 10, 2, 1, 2, "0 4 10 100", "0 0 8 10 100"},
311 1, false, true },
312 { { 4, 200, 100, 10, 2, 1, 2, "0 4 10 100", "0 0 8 98 100"},
313 1, true, true },
314 { { 4, 200, 100, 10, 2, 1, 2, "0 4 10 100", "0 0 8 98 100"},
315 0, true, true },
316 { { 0, 200, 100, 10, 2, 0, 2, "0 2 10 100", "0 4 94 98 100"},
317 0, true, true },
319 { { 0, 200, 100, 10, 2, 0, 0, "0 90 92 92 94 96 98 100",
320 "0 0 0 2 4 6 8 98 100"},
321 7, true, false },
322 { { 0, 200, 100, 10, 2, 0, 7, "0 2 4 6 8 8 10 100",
323 "0 0 2 4 6 8 96 98 100"},
324 5, true, false },
325 { { 0, 200, 100, 10, 2, 0, 7, "0 2 4 6 8 8 10 100",
326 "0 2 4 6 8 94 96 98 100"},
327 4, true, false },
328 { { 0, 200, 100, 10, 2, 0, 2, "0 2 10 100", "0 2 10 98 100"},
329 2, true, false },
330 { { 0, 200, 100, 10, 2, 0, 2, "0 2 10 100", "0 2 4 10 100"},
331 4, true, false },
332 { { 0, 200, 100, 10, 2, 0, 2, "0 2 10 100", "0 90 96 98 100"},
333 0, true, false },
335 for (size_t i = 0; i < arraysize(test_data); ++i) {
336 CreateLayout(test_data[i].common_data);
337 int add_types = 0;
338 if (test_data[i].add_active)
339 add_types |= StackedTabStripLayout::kAddTypeActive;
340 if (test_data[i].add_pinned)
341 add_types |= StackedTabStripLayout::kAddTypePinned;
342 AddViewToViewModel(test_data[i].add_index);
343 layout_->AddTab(test_data[i].add_index, add_types,
344 test_data[i].common_data.initial_x +
345 (test_data[i].add_pinned ? 4 : 0));
346 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
347 " at " << i;
351 // Assertions around removing tabs.
352 TEST_F(StackedTabStripLayoutTest, RemoveTab) {
353 // TODO: add coverage of removing pinned tabs!
354 struct TestData {
355 struct CommonTestData common_data;
356 const int remove_index;
357 const int x_after_remove;
358 } test_data[] = {
359 { { 0, 882, 220, 29, 2, 0, 4, "0 23 214 405 596 602",
360 "0 191 382 573 662" }, 1, 0 },
362 // Remove before active.
363 { { 0, 200, 100, 10, 2, 0, 4, "0 2 4 6 8 10 80 98 100",
364 "0 2 6 8 10 80 98 100" },
365 2, 0 },
367 // Stacked tabs on both sides.
368 { { 0, 200, 100, 10, 2, 0, 4, "0 2 4 6 8 10 80 98 100",
369 "0 2 4 6 10 80 98 100" },
370 4, 0 },
372 // Pinned tabs.
373 { { 8, 200, 100, 10, 2, 1, 0, "0 8 94 96 98 100", "0 86 88 90 100" },
374 0, 0 },
375 { { 16, 200, 100, 10, 2, 2, 0, "0 8 16 94 96 98 100", "8 8 86 88 90 100" },
376 0, 8 },
377 { { 16, 200, 100, 10, 2, 2, 0, "0 8 16 94 96 98 100", "0 8 86 88 90 100" },
378 1, 8 },
380 // Remove from ideal layout.
381 { { 0, 200, 100, 10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" },
382 0, 0 },
383 { { 0, 200, 100, 10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" },
384 1, 0 },
385 { { 0, 200, 100, 10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" },
386 2, 0 },
387 { { 0, 200, 100, 10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 98 100" },
388 3, 0 },
389 { { 0, 200, 100, 10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 96 100" },
390 5, 0 },
392 for (size_t i = 0; i < arraysize(test_data); ++i) {
393 CreateLayout(test_data[i].common_data);
394 int old_x = view_model_.ideal_bounds(test_data[i].remove_index).x();
395 view_model_.Remove(test_data[i].remove_index);
396 layout_->RemoveTab(test_data[i].remove_index, test_data[i].x_after_remove,
397 old_x);
398 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
399 " at " << i;
403 // Assertions for SetWidth().
404 TEST_F(StackedTabStripLayoutTest, SetWidth) {
405 struct TestData {
406 CommonTestData common_data;
407 int new_width;
408 } test_data[] = {
409 { { 0, 500, 100, 10, 2, 0, 4, "0 90 180 270 360 400",
410 "0 90 180 196 198 200"}, 300 },
412 // Verifies a bug in AdjustTrailingStackedTabs().
413 { { 0, 103, 100, 10, 2, 0, 0, "", "0 2"}, 102 },
415 { { 8, 250, 100, 10, 2, 2, 2, "0 4 8 98 148 150", "0 4 8 98 160 250"},
416 350 },
417 { { 8, 250, 100, 10, 2, 2, 2, "0 4 8 98 148 150", "0 4 8 96 98 100"}, 200 },
419 { { 0, 250, 100, 10, 2, 0, 2, "0 40 90 120 150", "0 40 90 98 100"}, 200 },
420 { { 0, 250, 100, 10, 2, 0, 2, "0 2 60 150", "0 2 60 100"}, 200 },
421 { { 0, 250, 100, 10, 2, 0, 2, "0 40 120 150", "0 40 98 100"}, 200 },
423 { { 0, 200, 100, 10, 2, 0, 2, "0 2 10 100", "0 2 60 150"}, 250 },
424 { { 0, 200, 100, 10, 2, 0, 2, "0 2 4 10 100", "0 2 20 110 200"}, 300 },
426 for (size_t i = 0; i < arraysize(test_data); ++i) {
427 CreateLayout(test_data[i].common_data);
428 layout_->SetWidth(test_data[i].new_width);
429 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
430 " at " << i;
434 // Assertions for SetActiveIndex().
435 TEST_F(StackedTabStripLayoutTest, SetActiveIndex) {
436 struct TestData {
437 CommonTestData common_data;
438 int new_index;
439 } test_data[] = {
440 { { 0, 250, 100, 10, 2, 0, 2, "0 4 8 98 148 150", "0 90 144 146 148 150"},
441 0 },
442 { { 0, 250, 100, 10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 58 148 150"}, 4 },
443 { { 0, 250, 100, 10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 6 60 150"}, 5 },
444 { { 4, 250, 100, 10, 2, 1, 2, "0 4 8 98 148 150", "0 4 94 146 148 150"},
445 0 },
447 for (size_t i = 0; i < arraysize(test_data); ++i) {
448 CreateLayout(test_data[i].common_data);
449 layout_->SetActiveIndex(test_data[i].new_index);
450 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
451 " at " << i;
455 // Makes sure don't crash when resized and only one tab.
456 TEST_F(StackedTabStripLayoutTest, EmptyTest) {
457 StackedTabStripLayout layout(gfx::Size(160, 10), 27, 6, 4, &view_model_);
458 PrepareChildViews(1);
459 layout.AddTab(0, StackedTabStripLayout::kAddTypeActive, 0);
460 layout.SetWidth(100);
461 layout.SetWidth(50);
462 layout.SetWidth(0);
463 layout.SetWidth(500);
466 // Assertions around removing tabs.
467 TEST_F(StackedTabStripLayoutTest, MoveTab) {
468 // TODO: add coverage of removing pinned tabs!
469 struct TestData {
470 struct CommonTestData common_data;
471 const int from;
472 const int to;
473 const int new_active_index;
474 const int new_start_x;
475 const int new_pinned_tab_count;
476 } test_data[] = {
477 // Moves and unpins.
478 { { 10, 300, 100, 10, 2, 2, 0, "", "0 5 10 100 190 198 200" },
479 0, 1, 2, 5, 1 },
481 // Moves and pins.
482 { { 0, 300, 100, 10, 2, 0, 4, "", "0 5 95 185 196 198 200" },
483 2, 0, 0, 5, 1 },
484 { { 0, 300, 100, 10, 2, 1, 2, "", "0 5 10 100 190 198 200" },
485 2, 0, 0, 10, 2 },
487 { { 0, 200, 100, 10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 96 98 100" },
488 2, 0, 4, 0, 0 },
489 { { 0, 200, 100, 10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 8 10 100" },
490 0, 6, 6, 0, 0 },
492 for (size_t i = 0; i < arraysize(test_data); ++i) {
493 CreateLayout(test_data[i].common_data);
494 view_model_.MoveViewOnly(test_data[i].from, test_data[i].to);
495 for (int j = 0; j < test_data[i].new_pinned_tab_count; ++j) {
496 gfx::Rect bounds;
497 bounds.set_x(j * 5);
498 view_model_.set_ideal_bounds(j, bounds);
500 layout_->MoveTab(test_data[i].from, test_data[i].to,
501 test_data[i].new_active_index, test_data[i].new_start_x,
502 test_data[i].new_pinned_tab_count);
503 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
504 " at " << i;
508 // Assertions around IsStacked().
509 TEST_F(StackedTabStripLayoutTest, IsStacked) {
510 // A single tab with enough space should never be stacked.
511 PrepareChildViews(1);
512 layout_.reset(
513 new StackedTabStripLayout(gfx::Size(100, 10), 10, 2, 4, &view_model_));
514 Reset(layout_.get(), 0, 400, 0, 0);
515 EXPECT_FALSE(layout_->IsStacked(0));
517 // First tab active, remaining tabs stacked.
518 PrepareChildViews(8);
519 Reset(layout_.get(), 0, 400, 0, 0);
520 EXPECT_FALSE(layout_->IsStacked(0));
521 EXPECT_TRUE(layout_->IsStacked(7));
523 // Last tab active, preceeding tabs stacked.
524 layout_->SetActiveIndex(7);
525 EXPECT_FALSE(layout_->IsStacked(7));
526 EXPECT_TRUE(layout_->IsStacked(0));
529 // Assertions around SetXAndPinnedCount.
530 TEST_F(StackedTabStripLayoutTest, SetXAndPinnedCount) {
531 // Verifies we don't crash when transitioning to all pinned tabs.
532 PrepareChildViews(1);
533 layout_.reset(
534 new StackedTabStripLayout(gfx::Size(100, 10), 10, 2, 4, &view_model_));
535 Reset(layout_.get(), 0, 400, 0, 0);
536 layout_->SetXAndPinnedCount(0, 1);
539 // Assertions around SetXAndPinnedCount.
540 TEST_F(StackedTabStripLayoutTest, SetActiveTabLocation) {
541 struct TestData {
542 struct CommonTestData common_data;
543 const int location;
544 } test_data[] = {
545 // Active tab is the first tab, can't be moved.
546 { { 0, 300, 100, 10, 2, 0, 0, "", "0 90 180 194 196 198 200" }, 50 },
548 // Active tab is pinned; should result in nothing.
549 { { 0, 300, 100, 10, 2, 2, 1, "", "0 0 0 90 180 198 200" }, 199 },
551 // Location is too far to the right, ends up being pushed in.
552 { { 0, 300, 100, 10, 2, 0, 3, "", "0 14 104 194 196 198 200" }, 199 },
554 // Location can be honored.
555 { { 0, 300, 100, 10, 2, 0, 3, "", "0 2 4 40 130 198 200" }, 40 },
557 for (size_t i = 0; i < arraysize(test_data); ++i) {
558 CreateLayout(test_data[i].common_data);
559 layout_->SetActiveTabLocation(test_data[i].location);
560 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) <<
561 " at " << i;