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/touch_tab_strip_layout.h" | 5 #include "chrome/browser/ui/views/tabs/touch_tab_strip_layout.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 | 275 |
276 // Assertions around removing tabs. | 276 // Assertions around removing tabs. |
277 TEST_F(TouchTabStripLayoutTest, RemoveTab) { | 277 TEST_F(TouchTabStripLayoutTest, RemoveTab) { |
278 // TODO: add coverage of removing mini tabs! | 278 // TODO: add coverage of removing mini tabs! |
279 struct TestData { | 279 struct TestData { |
280 struct CommonTestData common_data; | 280 struct CommonTestData common_data; |
281 const int remove_index; | 281 const int remove_index; |
282 const int x_after_remove; | 282 const int x_after_remove; |
283 } test_data[] = { | 283 } test_data[] = { |
| 284 // Remove before active. |
| 285 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 8 10 80 98 100", |
| 286 "0 2 6 8 10 80 98 100" }, |
| 287 2, 0 }, |
| 288 |
284 // Stacked tabs on both sides. | 289 // Stacked tabs on both sides. |
285 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 8 10 80 98 100", | 290 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 8 10 80 98 100", |
286 "0 2 4 6 10 80 98 100" }, | 291 "0 2 4 6 10 80 98 100" }, |
287 4, 0 }, | 292 4, 0 }, |
288 | 293 |
289 // Mini-tabs. | 294 // Mini-tabs. |
290 { { 8, 200, 100, -10, 2, 1, 0, "0 8 94 96 98 100", "0 86 88 90 100" }, | 295 { { 8, 200, 100, -10, 2, 1, 0, "0 8 94 96 98 100", "0 86 88 90 100" }, |
291 0, 0 }, | 296 0, 0 }, |
292 { { 16, 200, 100, -10, 2, 2, 0, "0 8 16 94 96 98 100", "8 8 86 88 90 100" }, | 297 { { 16, 200, 100, -10, 2, 2, 0, "0 8 16 94 96 98 100", "8 8 86 88 90 100" }, |
293 0, 8 }, | 298 0, 8 }, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Makes sure don't crash when resized and only one tab. | 372 // Makes sure don't crash when resized and only one tab. |
368 TEST_F(TouchTabStripLayoutTest, EmptyTest) { | 373 TEST_F(TouchTabStripLayoutTest, EmptyTest) { |
369 TouchTabStripLayout layout(gfx::Size(160, 10), -27, 6, 4, &view_model_); | 374 TouchTabStripLayout layout(gfx::Size(160, 10), -27, 6, 4, &view_model_); |
370 PrepareChildViews(1); | 375 PrepareChildViews(1); |
371 layout.AddTab(0, TouchTabStripLayout::kAddTypeActive, 0); | 376 layout.AddTab(0, TouchTabStripLayout::kAddTypeActive, 0); |
372 layout.SetWidth(100); | 377 layout.SetWidth(100); |
373 layout.SetWidth(50); | 378 layout.SetWidth(50); |
374 layout.SetWidth(0); | 379 layout.SetWidth(0); |
375 layout.SetWidth(500); | 380 layout.SetWidth(500); |
376 } | 381 } |
| 382 |
| 383 // Assertions around removing tabs. |
| 384 TEST_F(TouchTabStripLayoutTest, MoveTab) { |
| 385 // TODO: add coverage of removing mini tabs! |
| 386 struct TestData { |
| 387 struct CommonTestData common_data; |
| 388 const int from; |
| 389 const int to; |
| 390 const int new_active_index; |
| 391 const int new_start_x; |
| 392 const int new_mini_tab_count; |
| 393 } test_data[] = { |
| 394 // Moves and unpins. |
| 395 { { 10, 300, 100, -10, 2, 2, 0, "", "0 5 10 100 190 198 200" }, |
| 396 0, 1, 2, 5, 1 }, |
| 397 |
| 398 // Moves and pins. |
| 399 { { 0, 300, 100, -10, 2, 0, 4, "", "0 5 95 185 196 198 200" }, |
| 400 2, 0, 0, 5, 1 }, |
| 401 { { 0, 300, 100, -10, 2, 1, 2, "", "0 5 10 100 190 198 200" }, |
| 402 2, 0, 0, 10, 2 }, |
| 403 |
| 404 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 96 98 100" }, |
| 405 2, 0, 4, 0, 0 }, |
| 406 { { 0, 200, 100, -10, 2, 0, 4, "0 2 4 6 96 98 100", "0 2 4 6 8 10 100" }, |
| 407 0, 6, 6, 0, 0 }, |
| 408 }; |
| 409 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 410 CreateLayout(test_data[i].common_data); |
| 411 view_model_.MoveViewOnly(test_data[i].from, test_data[i].to); |
| 412 for (int j = 0; j < test_data[i].new_mini_tab_count; ++j) { |
| 413 gfx::Rect bounds; |
| 414 bounds.set_x(j * 5); |
| 415 view_model_.set_ideal_bounds(j, bounds); |
| 416 } |
| 417 layout_->MoveTab(test_data[i].from, test_data[i].to, |
| 418 test_data[i].new_active_index, test_data[i].new_start_x, |
| 419 test_data[i].new_mini_tab_count); |
| 420 EXPECT_EQ(test_data[i].common_data.expected_bounds, BoundsString()) << |
| 421 " at " << i; |
| 422 } |
| 423 } |
| 424 |
| 425 // Assertions around IsStacked(). |
| 426 TEST_F(TouchTabStripLayoutTest, IsStacked) { |
| 427 // A single tab with enough space should never be stacked. |
| 428 PrepareChildViews(1); |
| 429 layout_.reset(new TouchTabStripLayout( |
| 430 gfx::Size(100, 10), -10, 2, 4, &view_model_)); |
| 431 Reset(layout_.get(), 0, 400, 0, 0); |
| 432 EXPECT_FALSE(layout_->IsStacked(0)); |
| 433 |
| 434 // First tab active, remaining tabs stacked. |
| 435 PrepareChildViews(8); |
| 436 Reset(layout_.get(), 0, 400, 0, 0); |
| 437 EXPECT_FALSE(layout_->IsStacked(0)); |
| 438 EXPECT_TRUE(layout_->IsStacked(7)); |
| 439 |
| 440 // Last tab active, preceeding tabs stacked. |
| 441 layout_->SetActiveIndex(7); |
| 442 EXPECT_FALSE(layout_->IsStacked(7)); |
| 443 EXPECT_TRUE(layout_->IsStacked(0)); |
| 444 } |
OLD | NEW |