Chromium Code Reviews| Index: chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc |
| diff --git a/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc b/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc |
| index a84530b2feda140fb5148ae4580d7da8273b212f..56c4c0ce0ea00f6df13a172e3ddf9d277c7d8649 100644 |
| --- a/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc |
| +++ b/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc |
| @@ -595,3 +595,63 @@ TEST_P(ToolbarActionsBarRedesignUnitTest, TestStartAndEndIndexes) { |
| EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| } |
| + |
| +// Tests the logic for determining if the container needs an overflow menu item. |
| +TEST_P(ToolbarActionsBarRedesignUnitTest, TestNeedsOverflow) { |
| + CreateAndAddExtension( |
| + "extension 1", |
| + extensions::extension_action_test_util::BROWSER_ACTION); |
| + // One extension on the main bar, none overflowed. Overflow not needed. |
| + EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_EQ(0u, overflow_bar()->GetIconCount()); |
| + EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| + |
| + // One extension in the overflow menu, none on the main bar. Overflow needed. |
|
Finnur
2016/03/11 15:10:11
s/One/Set one/
Devlin
2016/03/11 17:32:10
Done.
|
| + toolbar_model()->SetVisibleIconCount(0u); |
| + EXPECT_EQ(0u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_EQ(1u, overflow_bar()->GetIconCount()); |
| + EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| + |
| + // Pop out an extension for a non-sticky popup. Even though the extension is |
| + // on the main bar, overflow is still needed because it will pop back in |
| + // when the menu is opened. |
| + ToolbarActionViewController* action = toolbar_actions_bar()->GetActions()[0]; |
| + { |
| + base::RunLoop run_loop; |
| + toolbar_actions_bar()->PopOutAction(action, false, run_loop.QuitClosure()); |
| + run_loop.Run(); |
| + } |
| + EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| + |
| + // Back to one in overflow, none on the main bar. |
| + toolbar_actions_bar()->UndoPopOut(); |
| + EXPECT_EQ(0u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_EQ(1u, overflow_bar()->GetIconCount()); |
| + EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| + |
| + // Pop out an extension for a sticky popup. Overflow shouldn't be needed now |
| + // because the extension will remain popped out even when the menu opens. |
| + { |
| + base::RunLoop run_loop; |
| + toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); |
| + run_loop.Run(); |
| + } |
| + EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| + |
| + // Add another extension and verify that if one is still in overflow when |
| + // another is popped out, we still need overflow. |
| + toolbar_actions_bar()->UndoPopOut(); |
| + CreateAndAddExtension( |
| + "extension 2", |
| + extensions::extension_action_test_util::BROWSER_ACTION); |
| + toolbar_model()->SetVisibleIconCount(0u); |
| + { |
| + base::RunLoop run_loop; |
| + toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); |
| + run_loop.Run(); |
| + } |
| + EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| + EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| +} |