| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 CreateAndAddExtension( | 197 CreateAndAddExtension( |
| 198 base::StringPrintf("extension %d", i), | 198 base::StringPrintf("extension %d", i), |
| 199 extensions::extension_action_test_util::BROWSER_ACTION); | 199 extensions::extension_action_test_util::BROWSER_ACTION); |
| 200 } | 200 } |
| 201 | 201 |
| 202 const ToolbarActionsBar::PlatformSettings& platform_settings = | 202 const ToolbarActionsBar::PlatformSettings& platform_settings = |
| 203 toolbar_actions_bar()->platform_settings(); | 203 toolbar_actions_bar()->platform_settings(); |
| 204 | 204 |
| 205 // By default, all three actions should be visible. | 205 // By default, all three actions should be visible. |
| 206 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); | 206 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 207 // Check the widths. | 207 // Check the widths. IconWidth(true) includes the spacing to the left of |
| 208 int expected_width = 3 * ToolbarActionsBar::IconWidth(true) - | 208 // each icon and |item_spacing| accounts for the spacing to the right |
| 209 platform_settings.item_spacing + | 209 // of the rightmost icon. |
| 210 platform_settings.left_padding + | 210 int expected_width = |
| 211 platform_settings.right_padding; | 211 3 * ToolbarActionsBar::IconWidth(true) + platform_settings.item_spacing; |
| 212 EXPECT_EQ(expected_width, toolbar_actions_bar()->GetPreferredSize().width()); | 212 EXPECT_EQ(expected_width, toolbar_actions_bar()->GetPreferredSize().width()); |
| 213 // Since all icons are showing, the current width should be the max width. | 213 // Since all icons are showing, the current width should be the max width. |
| 214 int maximum_width = expected_width; | 214 int maximum_width = expected_width; |
| 215 EXPECT_EQ(maximum_width, toolbar_actions_bar()->GetMaximumWidth()); | 215 EXPECT_EQ(maximum_width, toolbar_actions_bar()->GetMaximumWidth()); |
| 216 // The minimum width should be just enough for the chevron to be displayed. | 216 // The minimum width should be just enough for the chevron to be displayed |
| 217 int minimum_width = platform_settings.left_padding + | 217 // along with left and right padding. |
| 218 platform_settings.right_padding + | 218 int minimum_width = 2 * platform_settings.item_spacing + |
| 219 toolbar_actions_bar()->delegate_for_test()-> | 219 toolbar_actions_bar()->delegate_for_test()-> |
| 220 GetChevronWidth(); | 220 GetChevronWidth(); |
| 221 EXPECT_EQ(minimum_width, toolbar_actions_bar()->GetMinimumWidth()); | 221 EXPECT_EQ(minimum_width, toolbar_actions_bar()->GetMinimumWidth()); |
| 222 | 222 |
| 223 // Test the connection between the ToolbarActionsBar and the model by | 223 // Test the connection between the ToolbarActionsBar and the model by |
| 224 // adjusting the visible count. | 224 // adjusting the visible count. |
| 225 toolbar_model()->SetVisibleIconCount(2u); | 225 toolbar_model()->SetVisibleIconCount(2u); |
| 226 EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); | 226 EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); |
| 227 | 227 |
| 228 // The current width should now be enough for two icons, and the chevron. | 228 // The current width should now be enough for two icons, and the chevron. |
| 229 expected_width = 2 * ToolbarActionsBar::IconWidth(true) - | 229 // IconWidth(true) includes the spacing to the left of each icon and |
| 230 // |item_spacing| accounts for the spacing to the right of the rightmost |
| 231 // icon. |
| 232 expected_width = 2 * ToolbarActionsBar::IconWidth(true) + |
| 230 platform_settings.item_spacing + | 233 platform_settings.item_spacing + |
| 231 platform_settings.left_padding + | |
| 232 platform_settings.right_padding + | |
| 233 toolbar_actions_bar()->delegate_for_test()-> | 234 toolbar_actions_bar()->delegate_for_test()-> |
| 234 GetChevronWidth(); | 235 GetChevronWidth(); |
| 235 EXPECT_EQ(expected_width, toolbar_actions_bar()->GetPreferredSize().width()); | 236 EXPECT_EQ(expected_width, toolbar_actions_bar()->GetPreferredSize().width()); |
| 236 // The maximum and minimum widths should have remained constant (since we have | 237 // The maximum and minimum widths should have remained constant (since we have |
| 237 // the same number of actions). | 238 // the same number of actions). |
| 238 EXPECT_EQ(maximum_width, toolbar_actions_bar()->GetMaximumWidth()); | 239 EXPECT_EQ(maximum_width, toolbar_actions_bar()->GetMaximumWidth()); |
| 239 EXPECT_EQ(minimum_width, toolbar_actions_bar()->GetMinimumWidth()); | 240 EXPECT_EQ(minimum_width, toolbar_actions_bar()->GetMinimumWidth()); |
| 240 | 241 |
| 241 // Test drag-and-drop logic. | 242 // Test drag-and-drop logic. |
| 242 const char kExtension0[] = "extension 0"; | 243 const char kExtension0[] = "extension 0"; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // Set the width back to the preferred width. All should be back to normal. | 559 // Set the width back to the preferred width. All should be back to normal. |
| 559 browser_action_test_util()->SetWidth( | 560 browser_action_test_util()->SetWidth( |
| 560 toolbar_actions_bar()->GetPreferredSize().width()); | 561 toolbar_actions_bar()->GetPreferredSize().width()); |
| 561 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); | 562 EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); |
| 562 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); | 563 EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds()); |
| 563 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); | 564 EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds()); |
| 564 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); | 565 EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds()); |
| 565 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); | 566 EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds()); |
| 566 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); | 567 EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow()); |
| 567 } | 568 } |
| OLD | NEW |