OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar_unittest.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 EXPECT_EQ(gfx::Rect(kSpacing, kIconHeight, kIconWidth, kIconHeight), | 440 EXPECT_EQ(gfx::Rect(kSpacing, kIconHeight, kIconWidth, kIconHeight), |
441 overflow_bar()->GetFrameForIndex(6)); | 441 overflow_bar()->GetFrameForIndex(6)); |
442 | 442 |
443 // Check with > 2 rows. | 443 // Check with > 2 rows. |
444 toolbar_model()->SetVisibleIconCount(0); | 444 toolbar_model()->SetVisibleIconCount(0); |
445 EXPECT_EQ(gfx::Rect(kSpacing, 0, kIconWidth, kIconHeight), | 445 EXPECT_EQ(gfx::Rect(kSpacing, 0, kIconWidth, kIconHeight), |
446 overflow_bar()->GetFrameForIndex(0)); | 446 overflow_bar()->GetFrameForIndex(0)); |
447 EXPECT_EQ(gfx::Rect(kSpacing, kIconHeight * 2, kIconWidth, kIconHeight), | 447 EXPECT_EQ(gfx::Rect(kSpacing, kIconHeight * 2, kIconWidth, kIconHeight), |
448 overflow_bar()->GetFrameForIndex(6)); | 448 overflow_bar()->GetFrameForIndex(6)); |
449 } | 449 } |
| 450 |
| 451 TEST_F(ToolbarActionsBarRedesignUnitTest, TestStartAndEndIndexes) { |
| 452 for (int i = 0; i < 3; ++i) { |
| 453 CreateAndAddExtension( |
| 454 base::StringPrintf("extension %d", i), |
| 455 extensions::extension_action_test_util::BROWSER_ACTION); |
| 456 } |
| 457 // At the start, all icons should be present on the main bar, and no |
| 458 // overflow should be needed. |
| 459 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 460 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 461 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 462 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); |
| 463 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 464 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 465 |
| 466 // Shrink the width of the view to be a little over enough for one icon. |
| 467 browser_action_test_util()->SetWidth(ToolbarActionsBar::IconWidth(true) + 5); |
| 468 // Tricky: GetIconCount() is what we use to determine our preferred size, |
| 469 // stored pref size, etc, and should not be affected by a minimum size that is |
| 470 // too small to show everything. It should remain constant. |
| 471 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 472 // The main container should display only the first icon, with the overflow |
| 473 // displaying the rest. |
| 474 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 475 EXPECT_EQ(1u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 476 EXPECT_EQ(1u, overflow_bar()->GetStartIndexInBounds()); |
| 477 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 478 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 479 |
| 480 // Shrink the container again to be too small to display even one icon. |
| 481 // The overflow container should be displaying everything. |
| 482 browser_action_test_util()->SetWidth(ToolbarActionsBar::IconWidth(true) - 10); |
| 483 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 484 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 485 EXPECT_EQ(0u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 486 EXPECT_EQ(0u, overflow_bar()->GetStartIndexInBounds()); |
| 487 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 488 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 489 |
| 490 // Set the width back to the preferred width. All should be back to normal. |
| 491 browser_action_test_util()->SetWidth( |
| 492 toolbar_actions_bar()->GetPreferredSize().width()); |
| 493 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 494 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 495 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 496 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); |
| 497 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 498 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 499 } |
OLD | NEW |