| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 // Set the width back to the preferred width. All should be back to normal. | 588 // Set the width back to the preferred width. All should be back to normal. |
| 589 browser_action_test_util()->SetWidth( | 589 browser_action_test_util()->SetWidth( |
| 590 toolbar_actions_bar()->GetPreferredSize().width()); | 590 toolbar_actions_bar()->GetPreferredSize().width()); |
| 591 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); | 591 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 592 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); | 592 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 593 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); | 593 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 594 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); | 594 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); |
| 595 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); | 595 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 596 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); | 596 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 597 } | 597 } |
| 598 |
| 599 // Tests the logic for determining if the container needs an overflow menu item. |
| 600 TEST_P(ToolbarActionsBarRedesignUnitTest, TestNeedsOverflow) { |
| 601 CreateAndAddExtension( |
| 602 "extension 1", |
| 603 extensions::extension_action_test_util::BROWSER_ACTION); |
| 604 // One extension on the main bar, none overflowed. Overflow not needed. |
| 605 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 606 EXPECT_EQ(0u, overflow_bar()->GetIconCount()); |
| 607 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 608 |
| 609 // Set one extension in the overflow menu, none on the main bar. Overflow |
| 610 // needed. |
| 611 toolbar_model()->SetVisibleIconCount(0u); |
| 612 EXPECT_EQ(0u, toolbar_actions_bar()->GetIconCount()); |
| 613 EXPECT_EQ(1u, overflow_bar()->GetIconCount()); |
| 614 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 615 |
| 616 // Pop out an extension for a non-sticky popup. Even though the extension is |
| 617 // on the main bar, overflow is still needed because it will pop back in |
| 618 // when the menu is opened. |
| 619 ToolbarActionViewController* action = toolbar_actions_bar()->GetActions()[0]; |
| 620 { |
| 621 base::RunLoop run_loop; |
| 622 toolbar_actions_bar()->PopOutAction(action, false, run_loop.QuitClosure()); |
| 623 run_loop.Run(); |
| 624 } |
| 625 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 626 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 627 |
| 628 // Back to one in overflow, none on the main bar. |
| 629 toolbar_actions_bar()->UndoPopOut(); |
| 630 EXPECT_EQ(0u, toolbar_actions_bar()->GetIconCount()); |
| 631 EXPECT_EQ(1u, overflow_bar()->GetIconCount()); |
| 632 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 633 |
| 634 // Pop out an extension for a sticky popup. Overflow shouldn't be needed now |
| 635 // because the extension will remain popped out even when the menu opens. |
| 636 { |
| 637 base::RunLoop run_loop; |
| 638 toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); |
| 639 run_loop.Run(); |
| 640 } |
| 641 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 642 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 643 |
| 644 // Add another extension and verify that if one is still in overflow when |
| 645 // another is popped out, we still need overflow. |
| 646 toolbar_actions_bar()->UndoPopOut(); |
| 647 CreateAndAddExtension( |
| 648 "extension 2", |
| 649 extensions::extension_action_test_util::BROWSER_ACTION); |
| 650 toolbar_model()->SetVisibleIconCount(0u); |
| 651 { |
| 652 base::RunLoop run_loop; |
| 653 toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); |
| 654 run_loop.Run(); |
| 655 } |
| 656 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 657 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 658 } |
| OLD | NEW |