| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" | 5 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 { 0, 198, 100, -10, 1, 0, 0, "", "0 90 94 95 96 97 98 98 98" }, | 160 { 0, 198, 100, -10, 1, 0, 0, "", "0 90 94 95 96 97 98 98 98" }, |
| 161 { 0, 300, 100, -10, 1, 0, 0, "", | 161 { 0, 300, 100, -10, 1, 0, 0, "", |
| 162 "0 90 180 196 197 198 199 200 200 200 200" }, | 162 "0 90 180 196 197 198 199 200 200 200 200" }, |
| 163 { 0, 300, 100, -10, 1, 0, 10, "", "0 0 0 0 1 2 3 4 20 110 200" }, | 163 { 0, 300, 100, -10, 1, 0, 10, "", "0 0 0 0 1 2 3 4 20 110 200" }, |
| 164 { 0, 300, 100, -10, 1, 0, 1, "", "0 90 180 196 197 198 199 200 200" }, | 164 { 0, 300, 100, -10, 1, 0, 1, "", "0 90 180 196 197 198 199 200 200" }, |
| 165 { 0, 643, 160, -27, 6, 0, 0, "", "0 133 266 399" }, | 165 { 0, 643, 160, -27, 6, 0, 0, "", "0 133 266 399" }, |
| 166 { 0, 300, 100, -10, 1, 0, 7, "", "0 1 2 3 4 20 110 200" }, | 166 { 0, 300, 100, -10, 1, 0, 7, "", "0 1 2 3 4 20 110 200" }, |
| 167 { 0, 300, 100, -10, 1, 0, 6, "", "0 1 2 3 4 20 110 200" }, | 167 { 0, 300, 100, -10, 1, 0, 6, "", "0 1 2 3 4 20 110 200" }, |
| 168 { 0, 300, 100, -10, 1, 0, 4, "", "0 1 2 3 4 94 184 199 200" }, | 168 { 0, 300, 100, -10, 1, 0, 4, "", "0 1 2 3 4 94 184 199 200" }, |
| 169 }; | 169 }; |
| 170 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 170 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 171 CreateLayout(test_data[i]); | 171 CreateLayout(test_data[i]); |
| 172 EXPECT_EQ(test_data[i].expected_bounds, BoundsString()) << " at " << i; | 172 EXPECT_EQ(test_data[i].expected_bounds, BoundsString()) << " at " << i; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Assertions for dragging from an existing configuration. | 176 // Assertions for dragging from an existing configuration. |
| 177 TEST_F(StackedTabStripLayoutTest, DragActiveTabExisting) { | 177 TEST_F(StackedTabStripLayoutTest, DragActiveTabExisting) { |
| 178 struct TestData { | 178 struct TestData { |
| 179 struct CommonTestData common_data; | 179 struct CommonTestData common_data; |
| 180 const int delta; | 180 const int delta; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // Drags 1 beyond the left most position, which should pull in the right | 245 // Drags 1 beyond the left most position, which should pull in the right |
| 246 // tab slightly. | 246 // tab slightly. |
| 247 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 49 139" }, -41 }, | 247 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 49 139" }, -41 }, |
| 248 // Drags to the left as far as the tab goes. | 248 // Drags to the left as far as the tab goes. |
| 249 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 2 92" }, -88 }, | 249 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 2 92" }, -88 }, |
| 250 // Drags one past as far to the left as the tab goes. Should keep pulling | 250 // Drags one past as far to the left as the tab goes. Should keep pulling |
| 251 // in the rightmost tab. | 251 // in the rightmost tab. |
| 252 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 2 91" }, -89 }, | 252 { { 0, 240, 100, -10, 2, 0, 1, "0 90 140", "0 2 91" }, -89 }, |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 255 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 256 CreateLayout(test_data[i].common_data); | 256 CreateLayout(test_data[i].common_data); |
| 257 layout_->DragActiveTab(test_data[i].delta); | 257 layout_->DragActiveTab(test_data[i].delta); |
| 258 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << | 258 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 259 " at " << i; | 259 " at " << i; |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Assertions for SizeToFit(). | 263 // Assertions for SizeToFit(). |
| 264 TEST_F(StackedTabStripLayoutTest, SizeToFit) { | 264 TEST_F(StackedTabStripLayoutTest, SizeToFit) { |
| 265 struct CommonTestData test_data[] = { | 265 struct CommonTestData test_data[] = { |
| 266 // Dragged to the right. | 266 // Dragged to the right. |
| 267 { 10, 240, 100, -10, 2, 2, 1, "0 5 10 100 138 140", "1 6 11 101 138 140"}, | 267 { 10, 240, 100, -10, 2, 2, 1, "0 5 10 100 138 140", "1 6 11 101 138 140"}, |
| 268 { 10, 240, 100, -10, 2, 2, 1, "0 5 10 100 138 140", | 268 { 10, 240, 100, -10, 2, 2, 1, "0 5 10 100 138 140", |
| 269 "124 129 134 136 138 140" }, | 269 "124 129 134 136 138 140" }, |
| 270 | 270 |
| 271 // Dragged to the left. | 271 // Dragged to the left. |
| 272 { 0, 240, 100, -10, 2, 0, 1, "0 50 140", "0 49 139" }, | 272 { 0, 240, 100, -10, 2, 0, 1, "0 50 140", "0 49 139" }, |
| 273 | 273 |
| 274 // Dragged to the left. | 274 // Dragged to the left. |
| 275 { 0, 240, 100, -10, 2, 0, 1, "0 49 89 140", "0 49 89 139" }, | 275 { 0, 240, 100, -10, 2, 0, 1, "0 49 89 140", "0 49 89 139" }, |
| 276 }; | 276 }; |
| 277 | 277 |
| 278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 278 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 279 CreateLayout(test_data[i]); | 279 CreateLayout(test_data[i]); |
| 280 SetBoundsFromString(test_data[i].expected_bounds); | 280 SetBoundsFromString(test_data[i].expected_bounds); |
| 281 layout_->SizeToFit(); | 281 layout_->SizeToFit(); |
| 282 // NOTE: because of the way the code is structured this asserts on | 282 // NOTE: because of the way the code is structured this asserts on |
| 283 // |start_bound|, not |expected_bounds|. | 283 // |start_bound|, not |expected_bounds|. |
| 284 EXPECT_EQ(test_data[i].start_bounds, BoundsString()) << " at " << i; | 284 EXPECT_EQ(test_data[i].start_bounds, BoundsString()) << " at " << i; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Assertions for AddTab(). | 288 // Assertions for AddTab(). |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 { { 0, 200, 100, -10, 2, 0, 7, "0 2 4 6 8 8 10 100", | 321 { { 0, 200, 100, -10, 2, 0, 7, "0 2 4 6 8 8 10 100", |
| 322 "0 2 4 6 8 94 96 98 100"}, | 322 "0 2 4 6 8 94 96 98 100"}, |
| 323 4, true, false }, | 323 4, true, false }, |
| 324 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 10 98 100"}, | 324 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 10 98 100"}, |
| 325 2, true, false }, | 325 2, true, false }, |
| 326 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 4 10 100"}, | 326 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 4 10 100"}, |
| 327 4, true, false }, | 327 4, true, false }, |
| 328 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 90 96 98 100"}, | 328 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 90 96 98 100"}, |
| 329 0, true, false }, | 329 0, true, false }, |
| 330 }; | 330 }; |
| 331 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 331 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 332 CreateLayout(test_data[i].common_data); | 332 CreateLayout(test_data[i].common_data); |
| 333 int add_types = 0; | 333 int add_types = 0; |
| 334 if (test_data[i].add_active) | 334 if (test_data[i].add_active) |
| 335 add_types |= StackedTabStripLayout::kAddTypeActive; | 335 add_types |= StackedTabStripLayout::kAddTypeActive; |
| 336 if (test_data[i].add_mini) | 336 if (test_data[i].add_mini) |
| 337 add_types |= StackedTabStripLayout::kAddTypeMini; | 337 add_types |= StackedTabStripLayout::kAddTypeMini; |
| 338 AddViewToViewModel(test_data[i].add_index); | 338 AddViewToViewModel(test_data[i].add_index); |
| 339 layout_->AddTab(test_data[i].add_index, add_types, | 339 layout_->AddTab(test_data[i].add_index, add_types, |
| 340 test_data[i].common_data.initial_x + | 340 test_data[i].common_data.initial_x + |
| 341 (test_data[i].add_mini ? 4 : 0)); | 341 (test_data[i].add_mini ? 4 : 0)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 0, 0 }, | 378 0, 0 }, |
| 379 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" }, | 379 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" }, |
| 380 1, 0 }, | 380 1, 0 }, |
| 381 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" }, | 381 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 96 98 100" }, |
| 382 2, 0 }, | 382 2, 0 }, |
| 383 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 98 100" }, | 383 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 98 100" }, |
| 384 3, 0 }, | 384 3, 0 }, |
| 385 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 96 100" }, | 385 { { 0, 200, 100, -10, 2, 0, 0, "0 90 94 96 98 100", "0 90 94 96 100" }, |
| 386 5, 0 }, | 386 5, 0 }, |
| 387 }; | 387 }; |
| 388 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 388 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 389 CreateLayout(test_data[i].common_data); | 389 CreateLayout(test_data[i].common_data); |
| 390 int old_x = view_model_.ideal_bounds(test_data[i].remove_index).x(); | 390 int old_x = view_model_.ideal_bounds(test_data[i].remove_index).x(); |
| 391 view_model_.Remove(test_data[i].remove_index); | 391 view_model_.Remove(test_data[i].remove_index); |
| 392 layout_->RemoveTab(test_data[i].remove_index, test_data[i].x_after_remove, | 392 layout_->RemoveTab(test_data[i].remove_index, test_data[i].x_after_remove, |
| 393 old_x); | 393 old_x); |
| 394 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << | 394 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 395 " at " << i; | 395 " at " << i; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 413 { { 8, 250, 100, -10, 2, 2, 2, "0 4 8 98 148 150", "0 4 8 96 98 100"}, | 413 { { 8, 250, 100, -10, 2, 2, 2, "0 4 8 98 148 150", "0 4 8 96 98 100"}, |
| 414 200 }, | 414 200 }, |
| 415 | 415 |
| 416 { { 0, 250, 100, -10, 2, 0, 2, "0 40 90 120 150", "0 40 90 98 100"}, 200 }, | 416 { { 0, 250, 100, -10, 2, 0, 2, "0 40 90 120 150", "0 40 90 98 100"}, 200 }, |
| 417 { { 0, 250, 100, -10, 2, 0, 2, "0 2 60 150", "0 2 60 100"}, 200 }, | 417 { { 0, 250, 100, -10, 2, 0, 2, "0 2 60 150", "0 2 60 100"}, 200 }, |
| 418 { { 0, 250, 100, -10, 2, 0, 2, "0 40 120 150", "0 40 98 100"}, 200 }, | 418 { { 0, 250, 100, -10, 2, 0, 2, "0 40 120 150", "0 40 98 100"}, 200 }, |
| 419 | 419 |
| 420 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 60 150"}, 250 }, | 420 { { 0, 200, 100, -10, 2, 0, 2, "0 2 10 100", "0 2 60 150"}, 250 }, |
| 421 { { 0, 200, 100, -10, 2, 0, 2, "0 2 4 10 100", "0 2 20 110 200"}, 300 }, | 421 { { 0, 200, 100, -10, 2, 0, 2, "0 2 4 10 100", "0 2 20 110 200"}, 300 }, |
| 422 }; | 422 }; |
| 423 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 423 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 424 CreateLayout(test_data[i].common_data); | 424 CreateLayout(test_data[i].common_data); |
| 425 layout_->SetWidth(test_data[i].new_width); | 425 layout_->SetWidth(test_data[i].new_width); |
| 426 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << | 426 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 427 " at " << i; | 427 " at " << i; |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 // Assertions for SetActiveIndex(). | 431 // Assertions for SetActiveIndex(). |
| 432 TEST_F(StackedTabStripLayoutTest, SetActiveIndex) { | 432 TEST_F(StackedTabStripLayoutTest, SetActiveIndex) { |
| 433 struct TestData { | 433 struct TestData { |
| 434 CommonTestData common_data; | 434 CommonTestData common_data; |
| 435 int new_index; | 435 int new_index; |
| 436 } test_data[] = { | 436 } test_data[] = { |
| 437 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 90 144 146 148 150"}, | 437 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 90 144 146 148 150"}, |
| 438 0 }, | 438 0 }, |
| 439 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 58 148 150"}, 4 }, | 439 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 58 148 150"}, 4 }, |
| 440 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 6 60 150"}, 5 }, | 440 { { 0, 250, 100, -10, 2, 0, 2, "0 4 8 98 148 150", "0 2 4 6 60 150"}, 5 }, |
| 441 { { 4, 250, 100, -10, 2, 1, 2, "0 4 8 98 148 150", "0 4 94 146 148 150"}, | 441 { { 4, 250, 100, -10, 2, 1, 2, "0 4 8 98 148 150", "0 4 94 146 148 150"}, |
| 442 0 }, | 442 0 }, |
| 443 }; | 443 }; |
| 444 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 444 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 445 CreateLayout(test_data[i].common_data); | 445 CreateLayout(test_data[i].common_data); |
| 446 layout_->SetActiveIndex(test_data[i].new_index); | 446 layout_->SetActiveIndex(test_data[i].new_index); |
| 447 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << | 447 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 448 " at " << i; | 448 " at " << i; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 // Makes sure don't crash when resized and only one tab. | 452 // Makes sure don't crash when resized and only one tab. |
| 453 TEST_F(StackedTabStripLayoutTest, EmptyTest) { | 453 TEST_F(StackedTabStripLayoutTest, EmptyTest) { |
| 454 StackedTabStripLayout layout(gfx::Size(160, 10), -27, 6, 4, &view_model_); | 454 StackedTabStripLayout layout(gfx::Size(160, 10), -27, 6, 4, &view_model_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 479 { { 0, 300, 100, -10, 2, 0, 4, "", "0 5 95 185 196 198 200" }, | 479 { { 0, 300, 100, -10, 2, 0, 4, "", "0 5 95 185 196 198 200" }, |
| 480 2, 0, 0, 5, 1 }, | 480 2, 0, 0, 5, 1 }, |
| 481 { { 0, 300, 100, -10, 2, 1, 2, "", "0 5 10 100 190 198 200" }, | 481 { { 0, 300, 100, -10, 2, 1, 2, "", "0 5 10 100 190 198 200" }, |
| 482 2, 0, 0, 10, 2 }, | 482 2, 0, 0, 10, 2 }, |
| 483 | 483 |
| 484 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 96 98 100" }, | 484 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 96 98 100" }, |
| 485 2, 0, 4, 0, 0 }, | 485 2, 0, 4, 0, 0 }, |
| 486 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 8 10 100" }, | 486 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 8 10 100" }, |
| 487 0, 6, 6, 0, 0 }, | 487 0, 6, 6, 0, 0 }, |
| 488 }; | 488 }; |
| 489 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 489 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 490 CreateLayout(test_data[i].common_data); | 490 CreateLayout(test_data[i].common_data); |
| 491 view_model_.MoveViewOnly(test_data[i].from, test_data[i].to); | 491 view_model_.MoveViewOnly(test_data[i].from, test_data[i].to); |
| 492 for (int j = 0; j < test_data[i].new_mini_tab_count; ++j) { | 492 for (int j = 0; j < test_data[i].new_mini_tab_count; ++j) { |
| 493 gfx::Rect bounds; | 493 gfx::Rect bounds; |
| 494 bounds.set_x(j * 5); | 494 bounds.set_x(j * 5); |
| 495 view_model_.set_ideal_bounds(j, bounds); | 495 view_model_.set_ideal_bounds(j, bounds); |
| 496 } | 496 } |
| 497 layout_->MoveTab(test_data[i].from, test_data[i].to, | 497 layout_->MoveTab(test_data[i].from, test_data[i].to, |
| 498 test_data[i].new_active_index, test_data[i].new_start_x, | 498 test_data[i].new_active_index, test_data[i].new_start_x, |
| 499 test_data[i].new_mini_tab_count); | 499 test_data[i].new_mini_tab_count); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 544 |
| 545 // Active tab is pinned; should result in nothing. | 545 // Active tab is pinned; should result in nothing. |
| 546 { { 0, 300, 100, -10, 2, 2, 1, "", "0 0 0 90 180 198 200" }, 199 }, | 546 { { 0, 300, 100, -10, 2, 2, 1, "", "0 0 0 90 180 198 200" }, 199 }, |
| 547 | 547 |
| 548 // Location is too far to the right, ends up being pushed in. | 548 // Location is too far to the right, ends up being pushed in. |
| 549 { { 0, 300, 100, -10, 2, 0, 3, "", "0 14 104 194 196 198 200" }, 199 }, | 549 { { 0, 300, 100, -10, 2, 0, 3, "", "0 14 104 194 196 198 200" }, 199 }, |
| 550 | 550 |
| 551 // Location can be honored. | 551 // Location can be honored. |
| 552 { { 0, 300, 100, -10, 2, 0, 3, "", "0 2 4 40 130 198 200" }, 40 }, | 552 { { 0, 300, 100, -10, 2, 0, 3, "", "0 2 4 40 130 198 200" }, 40 }, |
| 553 }; | 553 }; |
| 554 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 554 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 555 CreateLayout(test_data[i].common_data); | 555 CreateLayout(test_data[i].common_data); |
| 556 layout_->SetActiveTabLocation(test_data[i].location); | 556 layout_->SetActiveTabLocation(test_data[i].location); |
| 557 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << | 557 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 558 " at " << i; | 558 " at " << i; |
| 559 } | 559 } |
| 560 } | 560 } |
| OLD | NEW |