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

Unified Diff: chrome/browser/ui/views/menu_item_view_interactive_uitest.cc

Issue 553233002: Dynamically calculate the number of extension icons to show per row in overflow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/toolbar/browser_actions_container.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
diff --git a/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc b/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
index af0f4c80359a4eefcda6c64e3c8e86a9a9eb09d0..8d82a3b1e552dfb8a2e08ded5876004cdae0ad74 100644
--- a/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
+++ b/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc
@@ -4,8 +4,10 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/menu_test_base.h"
+#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"
+#include "ui/views/view.h"
using base::ASCIIToUTF16;
@@ -341,3 +343,78 @@ typedef MenuItemViewTestRemoveWithSubmenu<1> MenuItemViewTestRemoveWithSubmenu1;
VIEW_TEST(MenuItemViewTestRemoveWithSubmenu0, MAYBE_RemoveItemWithSubmenu0)
VIEW_TEST(MenuItemViewTestRemoveWithSubmenu1, MAYBE_RemoveItemWithSubmenu1)
+
+// Test that MenuItemViews can have flexible sizes if they are containers.
sky 2014/09/15 17:14:56 Isn't there a way to test your new code without an
Devlin 2014/09/15 17:48:23 Ah, I suppose none of this really needs interactio
+class MenuItemViewTestFlexibleWidthChild : public MenuTestBase {
+ public:
+ MenuItemViewTestFlexibleWidthChild() {}
+ virtual ~MenuItemViewTestFlexibleWidthChild() {}
+
+ private:
+ // A simple View class that will match its height to the available width.
+ class SquareView : public views::View {
+ public:
+ SquareView() : width_(1) {}
+ virtual ~SquareView() {}
+
+ private:
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
+ return gfx::Size(width_, width_);
+ }
+ virtual int GetHeightForWidth(int width) const OVERRIDE {
+ width_ = width;
+ return width;
+ }
+
+ // Mutable because we set it for testing in GetHeightForWidth().
+ mutable int width_;
+ };
+
+ // MenuTestBase:
+ virtual void BuildMenu(views::MenuItemView* menu) OVERRIDE {
+ // Append a normal MenuItemView.
+ menu->AppendMenuItemWithLabel(1, ASCIIToUTF16("item 1"));
+
+ // Append a second MenuItemView that has a child SquareView.
+ views::MenuItemView* item_view =
+ menu->AppendMenuItemWithLabel(2, base::string16());
+ item_view->AddChildView(new SquareView());
+ // Set margins to 0 so that we know width should match height.
+ item_view->SetMargins(0, 0);
+ }
+
+ virtual void DoTestWithMenuOpen() OVERRIDE {
+ views::SubmenuView* submenu = menu()->GetSubmenu();
+ ASSERT_TRUE(submenu);
+ ASSERT_TRUE(submenu->IsShowing());
+
+ views::MenuItemView* first_item = submenu->GetMenuItemAt(0);
+ ASSERT_TRUE(first_item);
+ gfx::Size first_size = first_item->GetPreferredSize();
+
+ views::MenuItemView* second_item = submenu->GetMenuItemAt(1);
+ ASSERT_TRUE(second_item);
+ gfx::Size second_size = second_item->GetPreferredSize();
+
+ // The second menu item should have the same width as the first, since it
+ // is designed to have a flexible width and take up whatever region it can
+ // without expanding the menu.
+ EXPECT_EQ(first_size.width(), second_size.width());
+
+ // The second item should also be a square.
+ EXPECT_EQ(second_size.width(), second_size.height());
+
+ // Finally, the full menu should be large enough to accommodate both menu
+ // items at this height (and no larger).
+ EXPECT_EQ(second_size.height() + first_size.height(),
+ submenu->GetPreferredSize().height());
+
+ // Close the menu to clean up.
+ menu()->GetMenuController()->CancelAll();
+ Done();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(MenuItemViewTestFlexibleWidthChild);
+};
+
+VIEW_TEST(MenuItemViewTestFlexibleWidthChild, FlexibleWidthChild)
« no previous file with comments | « no previous file | chrome/browser/ui/views/toolbar/browser_actions_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698