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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/ui/views/menu_test_base.h" 6 #include "chrome/browser/ui/views/menu_test_base.h"
7 #include "ui/views/controls/menu/menu_controller.h"
7 #include "ui/views/controls/menu/menu_item_view.h" 8 #include "ui/views/controls/menu/menu_item_view.h"
8 #include "ui/views/controls/menu/submenu_view.h" 9 #include "ui/views/controls/menu/submenu_view.h"
10 #include "ui/views/view.h"
9 11
10 using base::ASCIIToUTF16; 12 using base::ASCIIToUTF16;
11 13
12 // Simple test for clicking a menu item. This template class clicks on an 14 // Simple test for clicking a menu item. This template class clicks on an
13 // item and checks that the returned id matches. The index of the item 15 // item and checks that the returned id matches. The index of the item
14 // is the template argument. 16 // is the template argument.
15 template<int INDEX> 17 template<int INDEX>
16 class MenuItemViewTestBasic : public MenuTestBase { 18 class MenuItemViewTestBasic : public MenuTestBase {
17 public: 19 public:
18 MenuItemViewTestBasic() { 20 MenuItemViewTestBasic() {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // ozone bringup - http://crbug.com/401304 336 // ozone bringup - http://crbug.com/401304
335 #define MAYBE_RemoveItemWithSubmenu0 DISABLED_RemoveItemWithSubmenu0 337 #define MAYBE_RemoveItemWithSubmenu0 DISABLED_RemoveItemWithSubmenu0
336 #define MAYBE_RemoveItemWithSubmenu1 DISABLED_RemoveItemWithSubmenu1 338 #define MAYBE_RemoveItemWithSubmenu1 DISABLED_RemoveItemWithSubmenu1
337 #else 339 #else
338 #define MAYBE_RemoveItemWithSubmenu0 RemoveItemWithSubmenu0 340 #define MAYBE_RemoveItemWithSubmenu0 RemoveItemWithSubmenu0
339 #define MAYBE_RemoveItemWithSubmenu1 RemoveItemWithSubmenu1 341 #define MAYBE_RemoveItemWithSubmenu1 RemoveItemWithSubmenu1
340 #endif 342 #endif
341 343
342 VIEW_TEST(MenuItemViewTestRemoveWithSubmenu0, MAYBE_RemoveItemWithSubmenu0) 344 VIEW_TEST(MenuItemViewTestRemoveWithSubmenu0, MAYBE_RemoveItemWithSubmenu0)
343 VIEW_TEST(MenuItemViewTestRemoveWithSubmenu1, MAYBE_RemoveItemWithSubmenu1) 345 VIEW_TEST(MenuItemViewTestRemoveWithSubmenu1, MAYBE_RemoveItemWithSubmenu1)
346
347 // 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
348 class MenuItemViewTestFlexibleWidthChild : public MenuTestBase {
349 public:
350 MenuItemViewTestFlexibleWidthChild() {}
351 virtual ~MenuItemViewTestFlexibleWidthChild() {}
352
353 private:
354 // A simple View class that will match its height to the available width.
355 class SquareView : public views::View {
356 public:
357 SquareView() : width_(1) {}
358 virtual ~SquareView() {}
359
360 private:
361 virtual gfx::Size GetPreferredSize() const OVERRIDE {
362 return gfx::Size(width_, width_);
363 }
364 virtual int GetHeightForWidth(int width) const OVERRIDE {
365 width_ = width;
366 return width;
367 }
368
369 // Mutable because we set it for testing in GetHeightForWidth().
370 mutable int width_;
371 };
372
373 // MenuTestBase:
374 virtual void BuildMenu(views::MenuItemView* menu) OVERRIDE {
375 // Append a normal MenuItemView.
376 menu->AppendMenuItemWithLabel(1, ASCIIToUTF16("item 1"));
377
378 // Append a second MenuItemView that has a child SquareView.
379 views::MenuItemView* item_view =
380 menu->AppendMenuItemWithLabel(2, base::string16());
381 item_view->AddChildView(new SquareView());
382 // Set margins to 0 so that we know width should match height.
383 item_view->SetMargins(0, 0);
384 }
385
386 virtual void DoTestWithMenuOpen() OVERRIDE {
387 views::SubmenuView* submenu = menu()->GetSubmenu();
388 ASSERT_TRUE(submenu);
389 ASSERT_TRUE(submenu->IsShowing());
390
391 views::MenuItemView* first_item = submenu->GetMenuItemAt(0);
392 ASSERT_TRUE(first_item);
393 gfx::Size first_size = first_item->GetPreferredSize();
394
395 views::MenuItemView* second_item = submenu->GetMenuItemAt(1);
396 ASSERT_TRUE(second_item);
397 gfx::Size second_size = second_item->GetPreferredSize();
398
399 // The second menu item should have the same width as the first, since it
400 // is designed to have a flexible width and take up whatever region it can
401 // without expanding the menu.
402 EXPECT_EQ(first_size.width(), second_size.width());
403
404 // The second item should also be a square.
405 EXPECT_EQ(second_size.width(), second_size.height());
406
407 // Finally, the full menu should be large enough to accommodate both menu
408 // items at this height (and no larger).
409 EXPECT_EQ(second_size.height() + first_size.height(),
410 submenu->GetPreferredSize().height());
411
412 // Close the menu to clean up.
413 menu()->GetMenuController()->CancelAll();
414 Done();
415 }
416
417 DISALLOW_COPY_AND_ASSIGN(MenuItemViewTestFlexibleWidthChild);
418 };
419
420 VIEW_TEST(MenuItemViewTestFlexibleWidthChild, FlexibleWidthChild)
OLDNEW
« 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