diff options
-rw-r--r-- | chrome/browser/views/bookmark_bar_view_test.cc | 77 | ||||
-rw-r--r-- | views/controls/menu/chrome_menu.cc | 4 | ||||
-rw-r--r-- | views/controls/menu/chrome_menu.h | 9 |
3 files changed, 87 insertions, 3 deletions
diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc index 8313920..b334549 100644 --- a/chrome/browser/views/bookmark_bar_view_test.cc +++ b/chrome/browser/views/bookmark_bar_view_test.cc @@ -975,3 +975,80 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase { }; VIEW_TEST(BookmarkBarViewTest12, CloseWithModalDialog) + +// Tests clicking on the separator of a context menu (this is for coverage of +// bug 17862). +class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase { + protected: + virtual void DoTestOnMessageLoop() { + // Move the mouse to the first folder on the bookmark bar and press the + // mouse. + views::TextButton* button = bb_view_->other_bookmarked_button(); + ui_controls::MoveMouseToCenterAndPress(button, ui_controls::LEFT, + ui_controls::DOWN | ui_controls::UP, + CreateEventTask(this, &BookmarkBarViewTest13::Step2)); + } + + private: + void Step2() { + // Menu should be showing. + views::MenuItemView* menu = bb_view_->GetMenu(); + ASSERT_TRUE(menu != NULL); + ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); + + views::MenuItemView* child_menu = + menu->GetSubmenu()->GetMenuItemAt(0); + ASSERT_TRUE(child_menu != NULL); + + // Right click on the first child to get its context menu. + ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, + ui_controls::DOWN | ui_controls::UP, + CreateEventTask(this, &BookmarkBarViewTest13::Step3)); + } + + void Step3() { + // Make sure the context menu is showing. + views::MenuItemView* menu = bb_view_->GetContextMenu(); + ASSERT_TRUE(menu != NULL); + ASSERT_TRUE(menu->GetSubmenu()); + ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); + + // Find the first separator. + views::SubmenuView* submenu = menu->GetSubmenu(); + views::View* separator_view = NULL; + for (int i = 0; i < submenu->GetChildViewCount(); ++i) { + if (submenu->GetChildViewAt(i)->GetID() != + views::MenuItemView::kMenuItemViewID) { + separator_view = submenu->GetChildViewAt(i); + break; + } + } + ASSERT_TRUE(separator_view); + + // Click on the separator. Clicking on the separator shouldn't visually + // change anything. + ui_controls::MoveMouseToCenterAndPress(separator_view, + ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, + CreateEventTask(this, &BookmarkBarViewTest13::Step4)); + } + + void Step4() { + // The context menu should still be showing. + views::MenuItemView* menu = bb_view_->GetContextMenu(); + ASSERT_TRUE(menu != NULL); + ASSERT_TRUE(menu->GetSubmenu()); + ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); + + // Select the first context menu item. + ui_controls::MoveMouseToCenterAndPress(menu->GetSubmenu()->GetMenuItemAt(0), + ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, + CreateEventTask(this, &BookmarkBarViewTest13::Step5)); + } + + void Step5() { + DLOG(WARNING) << " DONE"; + Done(); + } +}; + +VIEW_TEST(BookmarkBarViewTest13, ClickOnContextMenuSeparator) diff --git a/views/controls/menu/chrome_menu.cc b/views/controls/menu/chrome_menu.cc index f6e3950..1bd7b53 100644 --- a/views/controls/menu/chrome_menu.cc +++ b/views/controls/menu/chrome_menu.cc @@ -1790,7 +1790,7 @@ void MenuController::OnMousePressed(SubmenuView* source, bool open_submenu = false; if (!part.menu) { - part.menu = source->GetMenuItem(); + part.menu = part.parent; open_submenu = true; } else { if (part.menu->GetDelegate()->CanDrag(part.menu)) { @@ -2339,6 +2339,8 @@ bool MenuController::GetMenuPartByScreenCoordinateImpl( View::ConvertPointToView(NULL, menu, &menu_loc); part->menu = GetMenuItemAt(menu, menu_loc.x(), menu_loc.y()); part->type = MenuPart::MENU_ITEM; + if (!part->menu) + part->parent = menu->GetMenuItem(); return true; } diff --git a/views/controls/menu/chrome_menu.h b/views/controls/menu/chrome_menu.h index e9f6259..89d16d41 100644 --- a/views/controls/menu/chrome_menu.h +++ b/views/controls/menu/chrome_menu.h @@ -714,7 +714,7 @@ class MenuController SCROLL_DOWN }; - MenuPart() : type(NONE), menu(NULL), submenu(NULL) {} + MenuPart() : type(NONE), menu(NULL), parent(NULL), submenu(NULL) {} // Convenience for testing type == SCROLL_DOWN or type == SCROLL_UP. bool is_scroll() const { return type == SCROLL_DOWN || type == SCROLL_UP; } @@ -726,9 +726,14 @@ class MenuController // this is NULL. // NOTE: if type is MENU_ITEM and the mouse is not over a valid menu item // but is over a menu (for example, the mouse is over a separator or - // empty menu), this is NULL. + // empty menu), this is NULL and parent is the menu the mouse was + // clicked on. MenuItemView* menu; + // If type is MENU_ITEM but the mouse is not over a menu item this is the + // parent of the menu item the user clicked on. Otherwise this is NULL. + MenuItemView* parent; + // If type is SCROLL_*, this is the submenu the mouse is over. SubmenuView* submenu; }; |