Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8098)

Unified Diff: chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 6fb1a2a39cf3fc6a21236c083b8415791eded3e3..0f1907deb1ea8db3b142b5082325e39e57eb46d8 100644
--- a/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc
+++ b/chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc
@@ -447,3 +447,53 @@ TEST_F(ToolbarActionsBarRedesignUnitTest, TestActionFrameBounds) {
EXPECT_EQ(gfx::Rect(kSpacing, kIconHeight * 2, kIconWidth, kIconHeight),
overflow_bar()->GetFrameForIndex(6));
}
+
+TEST_F(ToolbarActionsBarRedesignUnitTest, TestStartAndEndIndexes) {
+ for (int i = 0; i < 3; ++i) {
+ CreateAndAddExtension(
+ base::StringPrintf("extension %d", i),
+ extensions::extension_action_test_util::BROWSER_ACTION);
+ }
+ // At the start, all icons should be present on the main bar, and no
+ // overflow should be needed.
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount());
+ EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds());
+ EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow());
+
+ // Shrink the width of the view to be a little over enough for one icon.
+ browser_action_test_util()->SetWidth(ToolbarActionsBar::IconWidth(true) + 5);
+ // Tricky: GetIconCount() is what we use to determine our preferred size,
+ // stored pref size, etc, and should not be affected by a minimum size that is
+ // too small to show everything. It should remain constant.
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount());
+ // The main container should display only the first icon, with the overflow
+ // displaying the rest.
+ EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(1u, toolbar_actions_bar()->GetEndIndexInBounds());
+ EXPECT_EQ(1u, overflow_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds());
+ EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow());
+
+ // Shrink the container again to be too small to display even one icon.
+ // The overflow container should be displaying everything.
+ browser_action_test_util()->SetWidth(ToolbarActionsBar::IconWidth(true) - 10);
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount());
+ EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(0u, toolbar_actions_bar()->GetEndIndexInBounds());
+ EXPECT_EQ(0u, overflow_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds());
+ EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow());
+
+ // Set the width back to the preferred width. All should be back to normal.
+ browser_action_test_util()->SetWidth(
+ toolbar_actions_bar()->GetPreferredSize().width());
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount());
+ EXPECT_EQ(0u, toolbar_actions_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, toolbar_actions_bar()->GetEndIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetStartIndexInBounds());
+ EXPECT_EQ(3u, overflow_bar()->GetEndIndexInBounds());
+ EXPECT_FALSE(toolbar_actions_bar()->NeedsOverflow());
+}

Powered by Google App Engine
This is Rietveld 408576698