1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/callback.h"
7 #include "base/compiler_specific.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
14 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_tabstrip.h"
20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/interactive_test_utils.h"
25 #include "chrome/test/base/scoped_testing_local_state.h"
26 #include "chrome/test/base/test_browser_window.h"
27 #include "chrome/test/base/testing_browser_process.h"
28 #include "chrome/test/base/testing_profile.h"
29 #include "chrome/test/base/ui_test_utils.h"
30 #include "chrome/test/base/view_event_test_base.h"
31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/page_navigator.h"
33 #include "content/public/test/test_browser_thread.h"
34 #include "grit/generated_resources.h"
35 #include "ui/base/accessibility/accessibility_types.h"
36 #include "ui/base/clipboard/clipboard.h"
37 #include "ui/base/test/ui_controls.h"
38 #include "ui/events/keycodes/keyboard_codes.h"
39 #include "ui/views/controls/button/menu_button.h"
40 #include "ui/views/controls/button/text_button.h"
41 #include "ui/views/controls/menu/menu_controller.h"
42 #include "ui/views/controls/menu/menu_item_view.h"
43 #include "ui/views/controls/menu/submenu_view.h"
44 #include "ui/views/widget/widget.h"
46 using base::ASCIIToUTF16
;
47 using content::BrowserThread
;
48 using content::OpenURLParams
;
49 using content::PageNavigator
;
50 using content::WebContents
;
54 void MoveMouseAndPress(const gfx::Point
& screen_pos
,
55 ui_controls::MouseButton button
,
57 const base::Closure
& closure
) {
58 ui_controls::SendMouseMove(screen_pos
.x(), screen_pos
.y());
59 ui_controls::SendMouseEventsNotifyWhenDone(button
, state
, closure
);
62 // PageNavigator implementation that records the URL.
63 class TestingPageNavigator
: public PageNavigator
{
65 virtual WebContents
* OpenURL(const OpenURLParams
& params
) OVERRIDE
{
73 // TODO(jschuh): Fix bookmark DND tests on Win64. crbug.com/244605
74 // TODO(erg): Fix bookmark DBD tests on linux_aura. crbug.com/163931
75 #if (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) || \
76 (defined(OS_LINUX) && defined(USE_AURA))
77 #define MAYBE(x) DISABLED_##x
84 // Base class for event generating bookmark view tests. These test are intended
85 // to exercise View's menus, but that's easier done with BookmarkBarView rather
86 // than View's menu itself.
88 // SetUp creates a bookmark model with the following structure.
89 // All folders are in upper case, all URLs in lower case.
110 // * if CreateBigMenu returns return true, 100 menu items are created here with
111 // the names f1-f100.
113 // Subclasses should be sure and invoke super's implementation of SetUp and
115 class BookmarkBarViewEventTestBase
: public ViewEventTestBase
{
117 BookmarkBarViewEventTestBase()
118 : ViewEventTestBase(),
121 virtual void SetUp() OVERRIDE
{
122 views::MenuController::TurnOffMenuSelectionHoldForTest();
123 BookmarkBarView::DisableAnimationsForTesting(true);
125 profile_
.reset(new TestingProfile());
126 profile_
->CreateBookmarkModel(true);
127 model_
= BookmarkModelFactory::GetForProfile(profile_
.get());
128 test::WaitForBookmarkModelToLoad(model_
);
129 profile_
->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar
, true);
131 Browser::CreateParams
native_params(profile_
.get(),
132 chrome::GetActiveDesktop());
134 chrome::CreateBrowserWithTestWindowForParams(&native_params
));
136 local_state_
.reset(new ScopedTestingLocalState(
137 TestingBrowserProcess::GetGlobal()));
138 model_
->ClearStore();
140 bb_view_
.reset(new BookmarkBarView(browser_
.get(), NULL
));
141 bb_view_
->set_owned_by_client();
142 bb_view_
->SetPageNavigator(&navigator_
);
144 AddTestData(CreateBigMenu());
146 // Calculate the preferred size so that one button doesn't fit, which
147 // triggers the overflow button to appear.
149 // BookmarkBarView::Layout does nothing if the parent is NULL and
150 // GetPreferredSize hard codes a width of 1. For that reason we add the
151 // BookmarkBarView to a dumby view as the parent.
153 // This code looks a bit hacky, but I've written it so that it shouldn't
154 // be dependant upon any of the layout code in BookmarkBarView. Instead
155 // we brute force search for a size that triggers the overflow button.
156 views::View tmp_parent
;
158 tmp_parent
.AddChildView(bb_view_
.get());
160 bb_view_pref_
= bb_view_
->GetPreferredSize();
161 bb_view_pref_
.set_width(1000);
162 views::TextButton
* button
= GetBookmarkButton(6);
163 while (button
->visible()) {
164 bb_view_pref_
.set_width(bb_view_pref_
.width() - 25);
165 bb_view_
->SetBounds(0, 0, bb_view_pref_
.width(), bb_view_pref_
.height());
169 tmp_parent
.RemoveChildView(bb_view_
.get());
171 ViewEventTestBase::SetUp();
174 virtual void TearDown() {
175 // Destroy everything, then run the message loop to ensure we delete all
176 // Tasks and fully shut down.
177 browser_
->tab_strip_model()->CloseAllTabs();
182 // Run the message loop to ensure we delete allTasks and fully shut down.
183 base::MessageLoop::current()->PostTask(FROM_HERE
,
184 base::MessageLoop::QuitClosure());
185 base::MessageLoop::current()->Run();
187 ViewEventTestBase::TearDown();
188 BookmarkBarView::DisableAnimationsForTesting(false);
192 virtual views::View
* CreateContentsView() OVERRIDE
{
193 return bb_view_
.get();
196 virtual gfx::Size
GetPreferredSize() OVERRIDE
{ return bb_view_pref_
; }
198 views::TextButton
* GetBookmarkButton(int view_index
) {
199 return bb_view_
->GetBookmarkButton(view_index
);
202 // See comment above class description for what this does.
203 virtual bool CreateBigMenu() { return false; }
205 BookmarkModel
* model_
;
206 scoped_ptr
<BookmarkBarView
> bb_view_
;
207 TestingPageNavigator navigator_
;
210 void AddTestData(bool big_menu
) {
211 const BookmarkNode
* bb_node
= model_
->bookmark_bar_node();
212 std::string test_base
= "file:///c:/tmp/";
213 const BookmarkNode
* f1
= model_
->AddFolder(bb_node
, 0, ASCIIToUTF16("F1"));
214 model_
->AddURL(f1
, 0, ASCIIToUTF16("f1a"), GURL(test_base
+ "f1a"));
215 const BookmarkNode
* f11
= model_
->AddFolder(f1
, 1, ASCIIToUTF16("F11"));
216 model_
->AddURL(f11
, 0, ASCIIToUTF16("f11a"), GURL(test_base
+ "f11a"));
218 for (int i
= 1; i
<= 100; ++i
) {
219 model_
->AddURL(f1
, i
+ 1, ASCIIToUTF16("f") + base::IntToString16(i
),
220 GURL(test_base
+ "f" + base::IntToString(i
)));
223 model_
->AddURL(bb_node
, 1, ASCIIToUTF16("a"), GURL(test_base
+ "a"));
224 model_
->AddURL(bb_node
, 2, ASCIIToUTF16("b"), GURL(test_base
+ "b"));
225 model_
->AddURL(bb_node
, 3, ASCIIToUTF16("c"), GURL(test_base
+ "c"));
226 model_
->AddURL(bb_node
, 4, ASCIIToUTF16("d"), GURL(test_base
+ "d"));
227 model_
->AddFolder(bb_node
, 5, ASCIIToUTF16("F2"));
228 model_
->AddURL(bb_node
, 6, ASCIIToUTF16("d"), GURL(test_base
+ "d"));
230 model_
->AddURL(model_
->other_node(), 0, ASCIIToUTF16("oa"),
231 GURL(test_base
+ "oa"));
232 const BookmarkNode
* of
= model_
->AddFolder(model_
->other_node(), 1,
234 model_
->AddURL(of
, 0, ASCIIToUTF16("ofa"), GURL(test_base
+ "ofa"));
235 model_
->AddURL(of
, 1, ASCIIToUTF16("ofb"), GURL(test_base
+ "ofb"));
236 const BookmarkNode
* of2
= model_
->AddFolder(model_
->other_node(), 2,
237 ASCIIToUTF16("OF2"));
238 model_
->AddURL(of2
, 0, ASCIIToUTF16("of2a"), GURL(test_base
+ "of2a"));
239 model_
->AddURL(of2
, 1, ASCIIToUTF16("of2b"), GURL(test_base
+ "of2b"));
242 gfx::Size bb_view_pref_
;
243 scoped_ptr
<TestingProfile
> profile_
;
244 scoped_ptr
<Browser
> browser_
;
245 scoped_ptr
<ScopedTestingLocalState
> local_state_
;
248 // Clicks on first menu, makes sure button is depressed. Moves mouse to first
249 // child, clicks it and makes sure a navigation occurs.
250 class BookmarkBarViewTest1
: public BookmarkBarViewEventTestBase
{
252 virtual void DoTestOnMessageLoop() OVERRIDE
{
253 // Move the mouse to the first folder on the bookmark bar and press the
255 views::TextButton
* button
= GetBookmarkButton(0);
256 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
257 ui_controls::DOWN
| ui_controls::UP
,
258 CreateEventTask(this, &BookmarkBarViewTest1::Step2
));
263 // Menu should be showing.
264 views::MenuItemView
* menu
= bb_view_
->GetMenu();
265 ASSERT_TRUE(menu
!= NULL
);
266 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
268 // Button should be depressed.
269 views::TextButton
* button
= GetBookmarkButton(0);
270 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_PRESSED
);
272 // Click on the 2nd menu item (A URL).
273 ASSERT_TRUE(menu
->GetSubmenu());
275 views::MenuItemView
* menu_to_select
=
276 menu
->GetSubmenu()->GetMenuItemAt(0);
277 ui_test_utils::MoveMouseToCenterAndPress(menu_to_select
, ui_controls::LEFT
,
278 ui_controls::DOWN
| ui_controls::UP
,
279 CreateEventTask(this, &BookmarkBarViewTest1::Step3
));
283 // We should have navigated to URL f1a.
284 ASSERT_TRUE(navigator_
.url_
==
285 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url());
287 // Make sure button is no longer pushed.
288 views::TextButton
* button
= GetBookmarkButton(0);
289 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_NORMAL
);
291 views::MenuItemView
* menu
= bb_view_
->GetMenu();
292 ASSERT_TRUE(menu
== NULL
|| !menu
->GetSubmenu()->IsShowing());
298 VIEW_TEST(BookmarkBarViewTest1
, Basic
)
300 // Brings up menu, clicks on empty space and make sure menu hides.
301 class BookmarkBarViewTest2
: public BookmarkBarViewEventTestBase
{
303 virtual void DoTestOnMessageLoop() OVERRIDE
{
304 // Move the mouse to the first folder on the bookmark bar and press the
306 views::TextButton
* button
= GetBookmarkButton(0);
307 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
308 ui_controls::DOWN
| ui_controls::UP
,
309 CreateEventTask(this, &BookmarkBarViewTest2::Step2
));
314 // Menu should be showing.
315 views::MenuItemView
* menu
= bb_view_
->GetMenu();
316 ASSERT_TRUE(menu
!= NULL
&& menu
->GetSubmenu()->IsShowing());
318 // Click on 0x0, which should trigger closing menu.
319 // NOTE: this code assume there is a left margin, which is currently
320 // true. If that changes, this code will need to find another empty space
321 // to press the mouse on.
322 gfx::Point mouse_loc
;
323 views::View::ConvertPointToScreen(bb_view_
.get(), &mouse_loc
);
324 ui_controls::SendMouseMoveNotifyWhenDone(0, 0,
325 CreateEventTask(this, &BookmarkBarViewTest2::Step3
));
329 // As the click is on the desktop the hook never sees the up, so we only
330 // wait on the down. We still send the up though else the system thinks
331 // the mouse is still down.
332 ui_controls::SendMouseEventsNotifyWhenDone(
333 ui_controls::LEFT
, ui_controls::DOWN
,
334 CreateEventTask(this, &BookmarkBarViewTest2::Step4
));
335 ui_controls::SendMouseEvents(ui_controls::LEFT
, ui_controls::UP
);
339 // The menu shouldn't be showing.
340 views::MenuItemView
* menu
= bb_view_
->GetMenu();
341 ASSERT_TRUE(menu
== NULL
|| !menu
->GetSubmenu()->IsShowing());
343 // Make sure button is no longer pushed.
344 views::TextButton
* button
= GetBookmarkButton(0);
345 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_NORMAL
);
351 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
352 // TODO(erg): linux_aura bringup: http://crbug.com/163931
353 #define MAYBE_HideOnDesktopClick DISABLED_HideOnDesktopClick
355 #define MAYBE_HideOnDesktopClick HideOnDesktopClick
358 VIEW_TEST(BookmarkBarViewTest2
, MAYBE_HideOnDesktopClick
)
360 // Brings up menu. Moves over child to make sure submenu appears, moves over
361 // another child and make sure next menu appears.
362 class BookmarkBarViewTest3
: public BookmarkBarViewEventTestBase
{
364 virtual void DoTestOnMessageLoop() OVERRIDE
{
365 // Move the mouse to the first folder on the bookmark bar and press the
367 views::MenuButton
* button
= bb_view_
->other_bookmarked_button();
368 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
369 ui_controls::DOWN
| ui_controls::UP
,
370 CreateEventTask(this, &BookmarkBarViewTest3::Step2
));
375 // Menu should be showing.
376 views::MenuItemView
* menu
= bb_view_
->GetMenu();
377 ASSERT_TRUE(menu
!= NULL
);
378 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
380 views::MenuItemView
* child_menu
=
381 menu
->GetSubmenu()->GetMenuItemAt(1);
382 ASSERT_TRUE(child_menu
!= NULL
);
384 // Click on second child, which has a submenu.
385 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
386 ui_controls::DOWN
| ui_controls::UP
,
387 CreateEventTask(this, &BookmarkBarViewTest3::Step3
));
391 // Make sure sub menu is showing.
392 views::MenuItemView
* menu
= bb_view_
->GetMenu();
394 views::MenuItemView
* child_menu
=
395 menu
->GetSubmenu()->GetMenuItemAt(1);
396 ASSERT_TRUE(child_menu
->GetSubmenu() != NULL
);
397 ASSERT_TRUE(child_menu
->GetSubmenu()->IsShowing());
399 // Click on third child, which has a submenu too.
400 child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
401 ASSERT_TRUE(child_menu
!= NULL
);
402 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
403 ui_controls::DOWN
| ui_controls::UP
,
404 CreateEventTask(this, &BookmarkBarViewTest3::Step4
));
408 // Make sure sub menu we first clicked isn't showing.
409 views::MenuItemView
* menu
= bb_view_
->GetMenu();
410 views::MenuItemView
* child_menu
=
411 menu
->GetSubmenu()->GetMenuItemAt(1);
412 ASSERT_TRUE(child_menu
->GetSubmenu() != NULL
);
413 ASSERT_FALSE(child_menu
->GetSubmenu()->IsShowing());
415 // And submenu we last clicked is showing.
416 child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
417 ASSERT_TRUE(child_menu
!= NULL
);
418 ASSERT_TRUE(child_menu
->GetSubmenu()->IsShowing());
420 // Nothing should have been selected.
421 EXPECT_EQ(GURL(), navigator_
.url_
);
424 menu
->GetMenuController()->CancelAll();
430 VIEW_TEST(BookmarkBarViewTest3
, Submenus
)
432 // Observer that posts task upon the context menu creation.
433 // This is necessary for Linux as the context menu has to check
434 // the clipboard, which invokes the event loop.
435 class BookmarkContextMenuNotificationObserver
436 : public content::NotificationObserver
{
438 explicit BookmarkContextMenuNotificationObserver(const base::Closure
& task
)
441 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN
,
442 content::NotificationService::AllSources());
445 virtual void Observe(int type
,
446 const content::NotificationSource
& source
,
447 const content::NotificationDetails
& details
) OVERRIDE
{
448 base::MessageLoop::current()->PostTask(FROM_HERE
, task_
);
451 // Sets the task that is posted when the context menu is shown.
452 void set_task(const base::Closure
& task
) { task_
= task
; }
455 content::NotificationRegistrar registrar_
;
458 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver
);
461 // Tests context menus by way of opening a context menu for a bookmark,
462 // then right clicking to get context menu and selecting the first menu item
464 class BookmarkBarViewTest4
: public BookmarkBarViewEventTestBase
{
466 BookmarkBarViewTest4()
467 : observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3
)) {
471 virtual void DoTestOnMessageLoop() OVERRIDE
{
472 // Move the mouse to the first folder on the bookmark bar and press the
474 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
475 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
476 ui_controls::DOWN
| ui_controls::UP
,
477 CreateEventTask(this, &BookmarkBarViewTest4::Step2
));
482 // Menu should be showing.
483 views::MenuItemView
* menu
= bb_view_
->GetMenu();
484 ASSERT_TRUE(menu
!= NULL
);
485 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
487 views::MenuItemView
* child_menu
=
488 menu
->GetSubmenu()->GetMenuItemAt(0);
489 ASSERT_TRUE(child_menu
!= NULL
);
491 // Right click on the first child to get its context menu.
492 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
493 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
494 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
498 // Make sure the context menu is showing.
499 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
500 ASSERT_TRUE(menu
!= NULL
);
501 ASSERT_TRUE(menu
->GetSubmenu());
502 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
504 // Select the first menu item (open).
505 ui_test_utils::MoveMouseToCenterAndPress(
506 menu
->GetSubmenu()->GetMenuItemAt(0),
507 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
508 CreateEventTask(this, &BookmarkBarViewTest4::Step4
));
512 EXPECT_EQ(navigator_
.url_
, model_
->other_node()->GetChild(0)->url());
516 BookmarkContextMenuNotificationObserver observer_
;
519 VIEW_TEST(BookmarkBarViewTest4
, ContextMenus
)
521 // Tests drag and drop within the same menu.
522 class BookmarkBarViewTest5
: public BookmarkBarViewEventTestBase
{
524 virtual void DoTestOnMessageLoop() OVERRIDE
{
526 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
528 // Move the mouse to the first folder on the bookmark bar and press the
530 views::TextButton
* button
= GetBookmarkButton(0);
531 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
532 ui_controls::DOWN
| ui_controls::UP
,
533 CreateEventTask(this, &BookmarkBarViewTest5::Step2
));
538 // Menu should be showing.
539 views::MenuItemView
* menu
= bb_view_
->GetMenu();
540 ASSERT_TRUE(menu
!= NULL
);
541 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
543 views::MenuItemView
* child_menu
=
544 menu
->GetSubmenu()->GetMenuItemAt(0);
545 ASSERT_TRUE(child_menu
!= NULL
);
547 // Move mouse to center of menu and press button.
548 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
550 CreateEventTask(this, &BookmarkBarViewTest5::Step3
));
554 views::MenuItemView
* target_menu
=
555 bb_view_
->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
556 gfx::Point
loc(1, target_menu
->height() - 1);
557 views::View::ConvertPointToScreen(target_menu
, &loc
);
560 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
561 CreateEventTask(this, &BookmarkBarViewTest5::Step4
));
563 // See comment above this method as to why we do this.
564 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
568 // Drop the item so that it's now the second item.
569 views::MenuItemView
* target_menu
=
570 bb_view_
->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
571 gfx::Point
loc(1, target_menu
->height() - 2);
572 views::View::ConvertPointToScreen(target_menu
, &loc
);
573 ui_controls::SendMouseMove(loc
.x(), loc
.y());
575 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT
,
577 CreateEventTask(this, &BookmarkBarViewTest5::Step5
));
581 GURL url
= model_
->bookmark_bar_node()->GetChild(0)->GetChild(1)->url();
582 EXPECT_EQ(url_dragging_
, url
);
589 VIEW_TEST(BookmarkBarViewTest5
, MAYBE(DND
))
591 // Tests holding mouse down on overflow button, dragging such that menu pops up
592 // then selecting an item.
593 class BookmarkBarViewTest6
: public BookmarkBarViewEventTestBase
{
595 virtual void DoTestOnMessageLoop() OVERRIDE
{
596 // Press the mouse button on the overflow button. Don't release it though.
597 views::TextButton
* button
= bb_view_
->overflow_button();
598 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
599 ui_controls::DOWN
, CreateEventTask(this, &BookmarkBarViewTest6::Step2
));
604 // Menu should be showing.
605 views::MenuItemView
* menu
= bb_view_
->GetMenu();
606 ASSERT_TRUE(menu
!= NULL
);
607 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
609 views::MenuItemView
* child_menu
=
610 menu
->GetSubmenu()->GetMenuItemAt(0);
611 ASSERT_TRUE(child_menu
!= NULL
);
613 // Move mouse to center of menu and release mouse.
614 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
615 ui_controls::UP
, CreateEventTask(this, &BookmarkBarViewTest6::Step3
));
619 ASSERT_TRUE(navigator_
.url_
==
620 model_
->bookmark_bar_node()->GetChild(6)->url());
627 VIEW_TEST(BookmarkBarViewTest6
, OpenMenuOnClickAndHold
)
629 // Tests drag and drop to different menu.
630 class BookmarkBarViewTest7
: public BookmarkBarViewEventTestBase
{
632 virtual void DoTestOnMessageLoop() OVERRIDE
{
634 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
636 // Move the mouse to the first folder on the bookmark bar and press the
638 views::TextButton
* button
= GetBookmarkButton(0);
639 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
640 ui_controls::DOWN
| ui_controls::UP
,
641 CreateEventTask(this, &BookmarkBarViewTest7::Step2
));
646 // Menu should be showing.
647 views::MenuItemView
* menu
= bb_view_
->GetMenu();
648 ASSERT_TRUE(menu
!= NULL
);
649 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
651 views::MenuItemView
* child_menu
=
652 menu
->GetSubmenu()->GetMenuItemAt(0);
653 ASSERT_TRUE(child_menu
!= NULL
);
655 // Move mouse to center of menu and press button.
656 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
658 CreateEventTask(this, &BookmarkBarViewTest7::Step3
));
662 // Drag over other button.
663 views::TextButton
* other_button
=
664 bb_view_
->other_bookmarked_button();
665 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
666 views::View::ConvertPointToScreen(other_button
, &loc
);
668 #if defined(USE_AURA)
669 // TODO: fix this. Aura requires an additional mouse event to trigger drag
670 // and drop checking state.
671 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
672 base::Bind(&BookmarkBarViewTest7::Step3A
, this));
675 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
676 base::Bind(&BookmarkBarViewTest7::Step4
, this));
678 // See comment above this method as to why we do this.
679 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
684 // Drag over other button.
685 views::TextButton
* other_button
=
686 bb_view_
->other_bookmarked_button();
687 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
688 views::View::ConvertPointToScreen(other_button
, &loc
);
690 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
691 base::Bind(&BookmarkBarViewTest7::Step4
, this));
695 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
696 ASSERT_TRUE(drop_menu
!= NULL
);
697 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
699 views::MenuItemView
* target_menu
=
700 drop_menu
->GetSubmenu()->GetMenuItemAt(0);
701 gfx::Point
loc(1, 1);
702 views::View::ConvertPointToScreen(target_menu
, &loc
);
703 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
704 CreateEventTask(this, &BookmarkBarViewTest7::Step5
));
708 ui_controls::SendMouseEventsNotifyWhenDone(
709 ui_controls::LEFT
, ui_controls::UP
,
710 CreateEventTask(this, &BookmarkBarViewTest7::Step6
));
714 ASSERT_TRUE(model_
->other_node()->GetChild(0)->url() == url_dragging_
);
722 // This test passes locally (on aero and non-aero) but fails on the trybots and
724 // http://crbug.com/154081
725 VIEW_TEST(BookmarkBarViewTest7
, MAYBE(DNDToDifferentMenu
))
728 // Drags from one menu to next so that original menu closes, then back to
730 class BookmarkBarViewTest8
: public BookmarkBarViewEventTestBase
{
732 virtual void DoTestOnMessageLoop() OVERRIDE
{
734 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
736 // Move the mouse to the first folder on the bookmark bar and press the
738 views::TextButton
* button
= GetBookmarkButton(0);
739 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
740 ui_controls::DOWN
| ui_controls::UP
,
741 CreateEventTask(this, &BookmarkBarViewTest8::Step2
));
746 // Menu should be showing.
747 views::MenuItemView
* menu
= bb_view_
->GetMenu();
748 ASSERT_TRUE(menu
!= NULL
);
749 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
751 views::MenuItemView
* child_menu
=
752 menu
->GetSubmenu()->GetMenuItemAt(0);
753 ASSERT_TRUE(child_menu
!= NULL
);
755 // Move mouse to center of menu and press button.
756 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
758 CreateEventTask(this, &BookmarkBarViewTest8::Step3
));
762 // Drag over other button.
763 views::TextButton
* other_button
=
764 bb_view_
->other_bookmarked_button();
765 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
766 views::View::ConvertPointToScreen(other_button
, &loc
);
769 #if defined(USE_AURA)
770 // TODO: fix this. Aura requires an additional mouse event to trigger drag
771 // and drop checking state.
772 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
773 base::Bind(&BookmarkBarViewTest8::Step3A
, this));
775 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
776 base::Bind(&BookmarkBarViewTest8::Step4
, this));
777 // See comment above this method as to why we do this.
778 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
783 // Drag over other button.
784 views::TextButton
* other_button
=
785 bb_view_
->other_bookmarked_button();
786 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
787 views::View::ConvertPointToScreen(other_button
, &loc
);
789 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
790 base::Bind(&BookmarkBarViewTest8::Step4
, this));
794 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
795 ASSERT_TRUE(drop_menu
!= NULL
);
796 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
798 // Now drag back over first menu.
799 views::TextButton
* button
= GetBookmarkButton(0);
800 gfx::Point
loc(button
->width() / 2, button
->height() / 2);
801 views::View::ConvertPointToScreen(button
, &loc
);
802 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
803 base::Bind(&BookmarkBarViewTest8::Step5
, this));
807 // Drop on folder F11.
808 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
809 ASSERT_TRUE(drop_menu
!= NULL
);
810 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
812 views::MenuItemView
* target_menu
=
813 drop_menu
->GetSubmenu()->GetMenuItemAt(1);
814 ui_test_utils::MoveMouseToCenterAndPress(
815 target_menu
, ui_controls::LEFT
, ui_controls::UP
,
816 CreateEventTask(this, &BookmarkBarViewTest8::Step6
));
820 // Make sure drop was processed.
821 GURL final_url
= model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->
823 ASSERT_TRUE(final_url
== url_dragging_
);
831 // This test passes locally (on aero and non-aero) but fails on the trybots and
833 // http://crbug.com/154081
834 VIEW_TEST(BookmarkBarViewTest8
, MAYBE(DNDBackToOriginatingMenu
))
837 // Moves the mouse over the scroll button and makes sure we get scrolling.
838 class BookmarkBarViewTest9
: public BookmarkBarViewEventTestBase
{
840 virtual bool CreateBigMenu() OVERRIDE
{ return true; }
842 virtual void DoTestOnMessageLoop() OVERRIDE
{
843 // Move the mouse to the first folder on the bookmark bar and press the
845 views::TextButton
* button
= GetBookmarkButton(0);
846 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
847 ui_controls::DOWN
| ui_controls::UP
,
848 CreateEventTask(this, &BookmarkBarViewTest9::Step2
));
853 // Menu should be showing.
854 views::MenuItemView
* menu
= bb_view_
->GetMenu();
855 ASSERT_TRUE(menu
!= NULL
);
856 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
858 first_menu_
= menu
->GetSubmenu()->GetMenuItemAt(0);
860 views::View::ConvertPointToScreen(first_menu_
, &menu_loc
);
861 start_y_
= menu_loc
.y();
863 // Move the mouse over the scroll button.
864 views::View
* scroll_container
= menu
->GetSubmenu()->parent();
865 ASSERT_TRUE(scroll_container
!= NULL
);
866 scroll_container
= scroll_container
->parent();
867 ASSERT_TRUE(scroll_container
!= NULL
);
868 views::View
* scroll_down_button
= scroll_container
->child_at(1);
869 ASSERT_TRUE(scroll_down_button
);
870 gfx::Point
loc(scroll_down_button
->width() / 2,
871 scroll_down_button
->height() / 2);
872 views::View::ConvertPointToScreen(scroll_down_button
, &loc
);
874 // On linux, the sending one location isn't enough.
875 ui_controls::SendMouseMove(loc
.x() - 1 , loc
.y() - 1);
876 ui_controls::SendMouseMoveNotifyWhenDone(
877 loc
.x(), loc
.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3
));
881 base::MessageLoop::current()->PostDelayedTask(
883 base::Bind(&BookmarkBarViewTest9::Step4
, this),
884 base::TimeDelta::FromMilliseconds(200));
889 views::View::ConvertPointToScreen(first_menu_
, &menu_loc
);
890 ASSERT_NE(start_y_
, menu_loc
.y());
893 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
895 // On linux, Cancelling menu will call Quit on the message loop,
896 // which can interfere with Done. We need to run Done in the
897 // next execution loop.
898 base::MessageLoop::current()->PostTask(
899 FROM_HERE
, base::Bind(&ViewEventTestBase::Done
, this));
903 views::MenuItemView
* first_menu_
;
906 VIEW_TEST(BookmarkBarViewTest9
, ScrollButtonScrolls
)
908 // Tests up/down/left/enter key messages.
909 class BookmarkBarViewTest10
: public BookmarkBarViewEventTestBase
{
911 virtual void DoTestOnMessageLoop() OVERRIDE
{
912 // Move the mouse to the first folder on the bookmark bar and press the
914 views::TextButton
* button
= GetBookmarkButton(0);
915 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
916 ui_controls::DOWN
| ui_controls::UP
,
917 CreateEventTask(this, &BookmarkBarViewTest10::Step2
));
918 base::MessageLoop::current()->RunUntilIdle();
923 // Menu should be showing.
924 views::MenuItemView
* menu
= bb_view_
->GetMenu();
925 ASSERT_TRUE(menu
!= NULL
);
926 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
928 // Send a down event, which should select the first item.
929 ui_controls::SendKeyPressNotifyWhenDone(
930 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
931 CreateEventTask(this, &BookmarkBarViewTest10::Step3
));
935 // Make sure menu is showing and item is selected.
936 views::MenuItemView
* menu
= bb_view_
->GetMenu();
937 ASSERT_TRUE(menu
!= NULL
);
938 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
939 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
941 // Send a key down event, which should select the next item.
942 ui_controls::SendKeyPressNotifyWhenDone(
943 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
944 CreateEventTask(this, &BookmarkBarViewTest10::Step4
));
948 views::MenuItemView
* menu
= bb_view_
->GetMenu();
949 ASSERT_TRUE(menu
!= NULL
);
950 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
951 ASSERT_FALSE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
952 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(1)->IsSelected());
954 // Send a right arrow to force the menu to open.
955 ui_controls::SendKeyPressNotifyWhenDone(
956 window_
->GetNativeWindow(), ui::VKEY_RIGHT
, false, false, false, false,
957 CreateEventTask(this, &BookmarkBarViewTest10::Step5
));
961 // Make sure the submenu is showing.
962 views::MenuItemView
* menu
= bb_view_
->GetMenu();
963 ASSERT_TRUE(menu
!= NULL
);
964 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
965 views::MenuItemView
* submenu
= menu
->GetSubmenu()->GetMenuItemAt(1);
966 ASSERT_TRUE(submenu
->IsSelected());
967 ASSERT_TRUE(submenu
->GetSubmenu());
968 ASSERT_TRUE(submenu
->GetSubmenu()->IsShowing());
970 // Send a left arrow to close the submenu.
971 ui_controls::SendKeyPressNotifyWhenDone(
972 window_
->GetNativeWindow(), ui::VKEY_LEFT
, false, false, false, false,
973 CreateEventTask(this, &BookmarkBarViewTest10::Step6
));
977 // Make sure the submenu is showing.
978 views::MenuItemView
* menu
= bb_view_
->GetMenu();
979 ASSERT_TRUE(menu
!= NULL
);
980 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
981 views::MenuItemView
* submenu
= menu
->GetSubmenu()->GetMenuItemAt(1);
982 ASSERT_TRUE(submenu
->IsSelected());
983 ASSERT_TRUE(!submenu
->GetSubmenu() || !submenu
->GetSubmenu()->IsShowing());
985 // Send a down arrow to wrap back to f1a
986 ui_controls::SendKeyPressNotifyWhenDone(
987 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
988 CreateEventTask(this, &BookmarkBarViewTest10::Step7
));
992 // Make sure menu is showing and item is selected.
993 views::MenuItemView
* menu
= bb_view_
->GetMenu();
994 ASSERT_TRUE(menu
!= NULL
);
995 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
996 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
998 // Send enter, which should select the item.
999 ui_controls::SendKeyPressNotifyWhenDone(
1000 window_
->GetNativeWindow(), ui::VKEY_RETURN
, false, false, false, false,
1001 CreateEventTask(this, &BookmarkBarViewTest10::Step8
));
1006 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url() ==
1012 VIEW_TEST(BookmarkBarViewTest10
, KeyEvents
)
1014 // Make sure the menu closes with the following sequence: show menu, show
1015 // context menu, close context menu (via escape), then click else where. This
1016 // effectively verifies we maintain mouse capture after the context menu is
1018 class BookmarkBarViewTest11
: public BookmarkBarViewEventTestBase
{
1020 BookmarkBarViewTest11()
1021 : observer_(CreateEventTask(this, &BookmarkBarViewTest11::Step3
)) {
1025 virtual void DoTestOnMessageLoop() OVERRIDE
{
1026 // Move the mouse to the first folder on the bookmark bar and press the
1028 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1029 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1030 ui_controls::DOWN
| ui_controls::UP
,
1031 CreateEventTask(this, &BookmarkBarViewTest11::Step2
));
1036 // Menu should be showing.
1037 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1038 ASSERT_TRUE(menu
!= NULL
);
1039 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1041 views::MenuItemView
* child_menu
=
1042 menu
->GetSubmenu()->GetMenuItemAt(0);
1043 ASSERT_TRUE(child_menu
!= NULL
);
1045 // Right click on the first child to get its context menu.
1046 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1047 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1048 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1052 // Send escape so that the context menu hides.
1053 ui_controls::SendKeyPressNotifyWhenDone(
1054 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
1055 CreateEventTask(this, &BookmarkBarViewTest11::Step4
));
1059 // Make sure the context menu is no longer showing.
1060 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1061 ASSERT_TRUE(!menu
|| !menu
->GetSubmenu() ||
1062 !menu
->GetSubmenu()->IsShowing());
1064 // But the menu should be showing.
1065 menu
= bb_view_
->GetMenu();
1066 ASSERT_TRUE(menu
&& menu
->GetSubmenu() && menu
->GetSubmenu()->IsShowing());
1068 // Now click on empty space.
1069 gfx::Point mouse_loc
;
1070 views::View::ConvertPointToScreen(bb_view_
.get(), &mouse_loc
);
1071 ui_controls::SendMouseMove(mouse_loc
.x(), mouse_loc
.y());
1072 ui_controls::SendMouseEventsNotifyWhenDone(
1073 ui_controls::LEFT
, ui_controls::UP
| ui_controls::DOWN
,
1074 CreateEventTask(this, &BookmarkBarViewTest11::Step5
));
1078 // Make sure the menu is not showing.
1079 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1080 ASSERT_TRUE(!menu
|| !menu
->GetSubmenu() ||
1081 !menu
->GetSubmenu()->IsShowing());
1085 BookmarkContextMenuNotificationObserver observer_
;
1088 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1089 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1090 #define MAYBE_CloseMenuAfterClosingContextMenu \
1091 DISABLED_CloseMenuAfterClosingContextMenu
1093 #define MAYBE_CloseMenuAfterClosingContextMenu CloseMenuAfterClosingContextMenu
1096 VIEW_TEST(BookmarkBarViewTest11
, MAYBE_CloseMenuAfterClosingContextMenu
)
1098 // Tests showing a modal dialog from a context menu.
1099 class BookmarkBarViewTest12
: public BookmarkBarViewEventTestBase
{
1101 virtual void DoTestOnMessageLoop() OVERRIDE
{
1102 // Open up the other folder.
1103 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1104 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1105 ui_controls::DOWN
| ui_controls::UP
,
1106 CreateEventTask(this, &BookmarkBarViewTest12::Step2
));
1107 chrome::num_bookmark_urls_before_prompting
= 1;
1110 virtual ~BookmarkBarViewTest12() {
1111 chrome::num_bookmark_urls_before_prompting
= 15;
1116 // Menu should be showing.
1117 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1118 ASSERT_TRUE(menu
!= NULL
);
1119 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1121 views::MenuItemView
* child_menu
=
1122 menu
->GetSubmenu()->GetMenuItemAt(1);
1123 ASSERT_TRUE(child_menu
!= NULL
);
1125 // Right click on the second child (a folder) to get its context menu.
1126 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1127 ui_controls::DOWN
| ui_controls::UP
,
1128 CreateEventTask(this, &BookmarkBarViewTest12::Step3
));
1132 // Make sure the context menu is showing.
1133 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1134 ASSERT_TRUE(menu
&& menu
->GetSubmenu() && menu
->GetSubmenu()->IsShowing());
1136 // Select the first item in the context menu (open all).
1137 views::MenuItemView
* child_menu
=
1138 menu
->GetSubmenu()->GetMenuItemAt(0);
1139 ASSERT_TRUE(child_menu
!= NULL
);
1140 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
1141 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1143 // Delay until we send tab, otherwise the message box doesn't appear
1145 base::MessageLoop::current()->PostDelayedTask(
1147 CreateEventTask(this, &BookmarkBarViewTest12::Step4
),
1148 base::TimeDelta::FromSeconds(1));
1152 // Press tab to give focus to the cancel button.
1153 ui_controls::SendKeyPress(
1154 window_
->GetNativeWindow(), ui::VKEY_TAB
, false, false, false, false);
1156 // For some reason return isn't processed correctly unless we delay.
1157 base::MessageLoop::current()->PostDelayedTask(
1159 CreateEventTask(this, &BookmarkBarViewTest12::Step5
),
1160 base::TimeDelta::FromSeconds(1));
1164 // And press enter so that the cancel button is selected.
1165 ui_controls::SendKeyPressNotifyWhenDone(
1166 window_
->GetNativeWindow(), ui::VKEY_RETURN
, false, false, false, false,
1167 CreateEventTask(this, &BookmarkBarViewTest12::Step6
));
1171 // Do a delayed task to give the dialog time to exit.
1172 base::MessageLoop::current()->PostTask(
1173 FROM_HERE
, CreateEventTask(this, &BookmarkBarViewTest12::Step7
));
1181 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1182 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1183 #define MAYBE_CloseWithModalDialog DISABLED_CloseWithModalDialog
1185 #define MAYBE_CloseWithModalDialog CloseWithModalDialog
1188 VIEW_TEST(BookmarkBarViewTest12
, MAYBE_CloseWithModalDialog
)
1190 // Tests clicking on the separator of a context menu (this is for coverage of
1192 class BookmarkBarViewTest13
: public BookmarkBarViewEventTestBase
{
1194 BookmarkBarViewTest13()
1195 : observer_(CreateEventTask(this, &BookmarkBarViewTest13::Step3
)) {
1199 virtual void DoTestOnMessageLoop() OVERRIDE
{
1200 // Move the mouse to the first folder on the bookmark bar and press the
1202 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1203 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1204 ui_controls::DOWN
| ui_controls::UP
,
1205 CreateEventTask(this, &BookmarkBarViewTest13::Step2
));
1210 // Menu should be showing.
1211 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1212 ASSERT_TRUE(menu
!= NULL
);
1213 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1215 views::MenuItemView
* child_menu
=
1216 menu
->GetSubmenu()->GetMenuItemAt(0);
1217 ASSERT_TRUE(child_menu
!= NULL
);
1219 // Right click on the first child to get its context menu.
1220 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1221 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1222 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1226 // Make sure the context menu is showing.
1227 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1228 ASSERT_TRUE(menu
!= NULL
);
1229 ASSERT_TRUE(menu
->GetSubmenu());
1230 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1232 // Find the first separator.
1233 views::SubmenuView
* submenu
= menu
->GetSubmenu();
1234 views::View
* separator_view
= NULL
;
1235 for (int i
= 0; i
< submenu
->child_count(); ++i
) {
1236 if (submenu
->child_at(i
)->id() != views::MenuItemView::kMenuItemViewID
) {
1237 separator_view
= submenu
->child_at(i
);
1241 ASSERT_TRUE(separator_view
);
1243 // Click on the separator. Clicking on the separator shouldn't visually
1245 ui_test_utils::MoveMouseToCenterAndPress(separator_view
,
1246 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1247 CreateEventTask(this, &BookmarkBarViewTest13::Step4
));
1251 // The context menu should still be showing.
1252 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1253 ASSERT_TRUE(menu
!= NULL
);
1254 ASSERT_TRUE(menu
->GetSubmenu());
1255 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1257 // Select the first context menu item.
1258 ui_test_utils::MoveMouseToCenterAndPress(
1259 menu
->GetSubmenu()->GetMenuItemAt(0),
1261 ui_controls::DOWN
| ui_controls::UP
,
1262 CreateEventTask(this, &BookmarkBarViewTest13::Step5
));
1269 BookmarkContextMenuNotificationObserver observer_
;
1272 VIEW_TEST(BookmarkBarViewTest13
, ClickOnContextMenuSeparator
)
1274 // Makes sure right clicking on a folder on the bookmark bar doesn't result in
1275 // both a context menu and showing the menu.
1276 class BookmarkBarViewTest14
: public BookmarkBarViewEventTestBase
{
1278 BookmarkBarViewTest14()
1279 : observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2
)) {
1283 virtual void DoTestOnMessageLoop() OVERRIDE
{
1284 // Move the mouse to the first folder on the bookmark bar and press the
1285 // right mouse button.
1286 views::TextButton
* button
= GetBookmarkButton(0);
1287 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::RIGHT
,
1288 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1289 // Step2 will be invoked by BookmarkContextMenuNotificationObserver.
1295 // Menu should NOT be showing.
1296 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1297 ASSERT_TRUE(menu
== NULL
);
1299 // Send escape so that the context menu hides.
1300 ui_controls::SendKeyPressNotifyWhenDone(
1301 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
1302 CreateEventTask(this, &BookmarkBarViewTest14::Step3
));
1309 BookmarkContextMenuNotificationObserver observer_
;
1312 VIEW_TEST(BookmarkBarViewTest14
, ContextMenus2
)
1314 // Makes sure deleting from the context menu keeps the bookmark menu showing.
1315 class BookmarkBarViewTest15
: public BookmarkBarViewEventTestBase
{
1317 BookmarkBarViewTest15()
1318 : deleted_menu_id_(0),
1319 observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3
)) {
1323 virtual void DoTestOnMessageLoop() OVERRIDE
{
1324 // Show the other bookmarks.
1325 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1326 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1327 ui_controls::DOWN
| ui_controls::UP
,
1328 CreateEventTask(this, &BookmarkBarViewTest15::Step2
));
1333 // Menu should be showing.
1334 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1335 ASSERT_TRUE(menu
!= NULL
);
1336 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1338 views::MenuItemView
* child_menu
=
1339 menu
->GetSubmenu()->GetMenuItemAt(1);
1340 ASSERT_TRUE(child_menu
!= NULL
);
1342 deleted_menu_id_
= child_menu
->GetCommand();
1344 // Right click on the second child to get its context menu.
1345 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1346 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1347 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1351 // Make sure the context menu is showing.
1352 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1353 ASSERT_TRUE(menu
!= NULL
);
1354 ASSERT_TRUE(menu
->GetSubmenu());
1355 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1357 views::MenuItemView
* delete_menu
=
1358 menu
->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE
);
1359 ASSERT_TRUE(delete_menu
);
1361 // Click on the delete button.
1362 ui_test_utils::MoveMouseToCenterAndPress(delete_menu
,
1363 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1364 CreateEventTask(this, &BookmarkBarViewTest15::Step4
));
1368 // The context menu should not be showing.
1369 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1370 ASSERT_TRUE(context_menu
== NULL
);
1372 // But the menu should be showing.
1373 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1374 ASSERT_TRUE(menu
!= NULL
);
1375 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1377 // And the deleted_menu_id_ should have been removed.
1378 ASSERT_TRUE(menu
->GetMenuItemByID(deleted_menu_id_
) == NULL
);
1380 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
1385 int deleted_menu_id_
;
1386 BookmarkContextMenuNotificationObserver observer_
;
1389 VIEW_TEST(BookmarkBarViewTest15
, MenuStaysVisibleAfterDelete
)
1391 // Tests that we don't crash or get stuck if the parent of a menu is closed.
1392 class BookmarkBarViewTest16
: public BookmarkBarViewEventTestBase
{
1394 virtual void DoTestOnMessageLoop() OVERRIDE
{
1395 // Move the mouse to the first folder on the bookmark bar and press the
1397 views::TextButton
* button
= GetBookmarkButton(0);
1398 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1399 ui_controls::DOWN
| ui_controls::UP
,
1400 CreateEventTask(this, &BookmarkBarViewTest16::Step2
));
1405 // Menu should be showing.
1406 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1407 ASSERT_TRUE(menu
!= NULL
);
1408 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1410 // Button should be depressed.
1411 views::TextButton
* button
= GetBookmarkButton(0);
1412 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_PRESSED
);
1414 // Close the window.
1418 base::MessageLoop::current()->PostTask(
1419 FROM_HERE
, CreateEventTask(this, &BookmarkBarViewTest16::Done
));
1423 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1424 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1425 #define MAYBE_DeleteMenu DISABLED_DeleteMenu
1427 #define MAYBE_DeleteMenu DeleteMenu
1430 VIEW_TEST(BookmarkBarViewTest16
, MAYBE_DeleteMenu
)
1432 // Makes sure right clicking on an item while a context menu is already showing
1433 // doesn't crash and works.
1434 class BookmarkBarViewTest17
: public BookmarkBarViewEventTestBase
{
1436 BookmarkBarViewTest17()
1437 : observer_(CreateEventTask(this, &BookmarkBarViewTest17::Step3
)) {
1441 virtual void DoTestOnMessageLoop() OVERRIDE
{
1442 // Move the mouse to the other folder on the bookmark bar and press the
1443 // left mouse button.
1444 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1445 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1446 ui_controls::DOWN
| ui_controls::UP
,
1447 CreateEventTask(this, &BookmarkBarViewTest17::Step2
));
1452 // Menu should be showing.
1453 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1454 ASSERT_TRUE(menu
!= NULL
);
1455 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1457 // Right click on the second item to show its context menu.
1458 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
1459 ASSERT_TRUE(child_menu
!= NULL
);
1460 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1461 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1462 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1466 // Make sure the context menu is showing.
1467 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1468 ASSERT_TRUE(context_menu
!= NULL
);
1469 ASSERT_TRUE(context_menu
->GetSubmenu());
1470 ASSERT_TRUE(context_menu
->GetSubmenu()->IsShowing());
1472 // Right click on the first menu item to trigger its context menu.
1473 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1474 ASSERT_TRUE(menu
!= NULL
);
1475 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1476 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1477 ASSERT_TRUE(child_menu
!= NULL
);
1479 // The context menu and child_menu can be overlapped, calculate the
1480 // non-intersected Rect of the child menu and click on its center to make
1481 // sure the click is always on the child menu.
1482 gfx::Rect context_rect
= context_menu
->GetSubmenu()->GetBoundsInScreen();
1483 gfx::Rect child_menu_rect
= child_menu
->GetBoundsInScreen();
1484 gfx::Rect clickable_rect
=
1485 gfx::SubtractRects(child_menu_rect
, context_rect
);
1486 ASSERT_FALSE(clickable_rect
.IsEmpty());
1487 observer_
.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4
));
1488 MoveMouseAndPress(clickable_rect
.CenterPoint(), ui_controls::RIGHT
,
1489 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1490 // Step4 will be invoked by BookmarkContextMenuNotificationObserver.
1494 // The context menu should still be showing.
1495 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1496 ASSERT_TRUE(context_menu
!= NULL
);
1498 // And the menu should be showing.
1499 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1500 ASSERT_TRUE(menu
!= NULL
);
1501 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1503 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
1508 BookmarkContextMenuNotificationObserver observer_
;
1511 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1512 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1513 #define MAYBE_ContextMenus3 DISABLED_ContextMenus3
1515 #define MAYBE_ContextMenus3 ContextMenus3
1518 VIEW_TEST(BookmarkBarViewTest17
, MAYBE_ContextMenus3
)
1520 // Verifies sibling menus works. Clicks on the 'other bookmarks' folder, then
1521 // moves the mouse over the first item on the bookmark bar and makes sure the
1523 class BookmarkBarViewTest18
: public BookmarkBarViewEventTestBase
{
1525 virtual void DoTestOnMessageLoop() OVERRIDE
{
1526 // Move the mouse to the other folder on the bookmark bar and press the
1527 // left mouse button.
1528 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1529 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1530 ui_controls::DOWN
| ui_controls::UP
,
1531 CreateEventTask(this, &BookmarkBarViewTest18::Step2
));
1536 // Menu should be showing.
1537 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1538 ASSERT_TRUE(menu
!= NULL
);
1539 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1541 // Move the mouse to the first folder on the bookmark bar
1542 views::TextButton
* button
= GetBookmarkButton(0);
1543 gfx::Point
button_center(button
->width() / 2, button
->height() / 2);
1544 views::View::ConvertPointToScreen(button
, &button_center
);
1545 ui_controls::SendMouseMoveNotifyWhenDone(
1546 button_center
.x(), button_center
.y(),
1547 CreateEventTask(this, &BookmarkBarViewTest18::Step3
));
1551 // Make sure the menu is showing.
1552 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1553 ASSERT_TRUE(menu
!= NULL
);
1554 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1556 // The menu for the first folder should be in the pressed state (since the
1557 // menu is showing for it).
1558 EXPECT_EQ(views::CustomButton::STATE_PRESSED
,
1559 GetBookmarkButton(0)->state());
1561 menu
->GetMenuController()->CancelAll();
1567 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1568 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1569 #define MAYBE_BookmarkBarViewTest18_SiblingMenu \
1570 DISABLED_BookmarkBarViewTest18_SiblingMenu
1572 #define MAYBE_BookmarkBarViewTest18_SiblingMenu \
1573 BookmarkBarViewTest18_SiblingMenu
1576 VIEW_TEST(BookmarkBarViewTest18
, MAYBE_BookmarkBarViewTest18_SiblingMenu
)
1578 // Verifies mousing over an already open sibling menu doesn't prematurely cancel
1580 class BookmarkBarViewTest19
: public BookmarkBarViewEventTestBase
{
1582 virtual void DoTestOnMessageLoop() OVERRIDE
{
1583 // Move the mouse to the other folder on the bookmark bar and press the
1584 // left mouse button.
1585 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1586 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1587 ui_controls::DOWN
| ui_controls::UP
,
1588 CreateEventTask(this, &BookmarkBarViewTest19::Step2
));
1593 // Menu should be showing.
1594 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1595 ASSERT_TRUE(menu
!= NULL
);
1596 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1598 // Click on the first folder.
1599 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1600 ASSERT_TRUE(child_menu
!= NULL
);
1601 ui_test_utils::MoveMouseToCenterAndPress(
1602 child_menu
, ui_controls::LEFT
,
1603 ui_controls::DOWN
| ui_controls::UP
,
1604 CreateEventTask(this, &BookmarkBarViewTest19::Step3
));
1608 // Make sure the menu is showing.
1609 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1610 ASSERT_TRUE(menu
!= NULL
);
1611 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1613 // Move the mouse back to the other bookmark button.
1614 views::TextButton
* button
= bb_view_
->other_bookmarked_button();
1615 gfx::Point
button_center(button
->width() / 2, button
->height() / 2);
1616 views::View::ConvertPointToScreen(button
, &button_center
);
1617 ui_controls::SendMouseMoveNotifyWhenDone(
1618 button_center
.x() + 1, button_center
.y() + 1,
1619 CreateEventTask(this, &BookmarkBarViewTest19::Step4
));
1623 // Menu should be showing.
1624 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1625 ASSERT_TRUE(menu
!= NULL
);
1626 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1628 // Click on the first folder.
1629 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1630 ASSERT_TRUE(child_menu
!= NULL
);
1631 ui_test_utils::MoveMouseToCenterAndPress(
1634 ui_controls::DOWN
| ui_controls::UP
,
1635 CreateEventTask(this, &BookmarkBarViewTest19::Step5
));
1639 // Make sure the menu is showing.
1640 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1641 ASSERT_TRUE(menu
!= NULL
);
1642 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1644 menu
->GetMenuController()->CancelAll();
1650 VIEW_TEST(BookmarkBarViewTest19
, BookmarkBarViewTest19_SiblingMenu
)
1652 // Verify that when clicking a mouse button outside a context menu,
1653 // the context menu is dismissed *and* the underlying view receives
1654 // the the mouse event (due to event reposting).
1655 class BookmarkBarViewTest20
: public BookmarkBarViewEventTestBase
{
1657 BookmarkBarViewTest20() : test_view_(new TestViewForMenuExit
) {}
1660 virtual void DoTestOnMessageLoop() OVERRIDE
{
1661 // Add |test_view_| next to |bb_view_|.
1662 views::View
* parent
= bb_view_
->parent();
1663 views::View
* container_view
= new ContainerViewForMenuExit
;
1664 container_view
->AddChildView(bb_view_
.get());
1665 container_view
->AddChildView(test_view_
);
1666 parent
->AddChildView(container_view
);
1669 ASSERT_EQ(test_view_
->press_count(), 0);
1671 // Move the mouse to the Test View and press the left mouse button.
1672 ui_test_utils::MoveMouseToCenterAndPress(
1673 test_view_
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1674 CreateEventTask(this, &BookmarkBarViewTest20::Step1
));
1679 ASSERT_EQ(test_view_
->press_count(), 1);
1680 ASSERT_TRUE(bb_view_
->GetMenu() == NULL
);
1682 // Move the mouse to the first folder on the bookmark bar and press the
1683 // left mouse button.
1684 views::TextButton
* button
= GetBookmarkButton(0);
1685 ui_test_utils::MoveMouseToCenterAndPress(
1686 button
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1687 CreateEventTask(this, &BookmarkBarViewTest20::Step2
));
1691 ASSERT_EQ(test_view_
->press_count(), 1);
1692 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1693 ASSERT_TRUE(menu
!= NULL
);
1694 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1696 // Move the mouse to the Test View and press the left mouse button.
1697 // The context menu will consume the event and exit. Thereafter,
1698 // the event is reposted and delivered to the Test View which
1699 // increases its press-count.
1700 ui_test_utils::MoveMouseToCenterAndPress(
1701 test_view_
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1702 CreateEventTask(this, &BookmarkBarViewTest20::Step3
));
1706 ASSERT_EQ(test_view_
->press_count(), 2);
1707 ASSERT_TRUE(bb_view_
->GetMenu() == NULL
);
1711 class ContainerViewForMenuExit
: public views::View
{
1713 ContainerViewForMenuExit() {
1716 virtual void Layout() OVERRIDE
{
1717 DCHECK_EQ(2, child_count());
1718 views::View
* bb_view
= child_at(0);
1719 views::View
* test_view
= child_at(1);
1720 const int width
= bb_view
->width();
1721 const int height
= bb_view
->height();
1722 bb_view
->SetBounds(0,0, width
- 22, height
);
1723 test_view
->SetBounds(width
- 20, 0, 20, height
);
1728 DISALLOW_COPY_AND_ASSIGN(ContainerViewForMenuExit
);
1731 class TestViewForMenuExit
: public views::View
{
1733 TestViewForMenuExit() : press_count_(0) {
1735 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
{
1739 int press_count() const { return press_count_
; }
1744 DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit
);
1747 TestViewForMenuExit
* test_view_
;
1750 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1751 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1752 #define MAYBE_ContextMenuExitTest DISABLED_ContextMenuExitTest
1754 #define MAYBE_ContextMenuExitTest ContextMenuExitTest
1757 VIEW_TEST(BookmarkBarViewTest20
, MAYBE_ContextMenuExitTest
)
1759 // Tests context menu by way of opening a context menu for a empty folder menu.
1760 // The opened context menu should behave as it is from the folder button.
1761 class BookmarkBarViewTest21
: public BookmarkBarViewEventTestBase
{
1763 BookmarkBarViewTest21()
1764 : observer_(CreateEventTask(this, &BookmarkBarViewTest21::Step3
)) {
1768 // Move the mouse to the empty folder on the bookmark bar and press the
1769 // left mouse button.
1770 virtual void DoTestOnMessageLoop() OVERRIDE
{
1771 views::TextButton
* button
= GetBookmarkButton(5);
1772 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1773 ui_controls::DOWN
| ui_controls::UP
,
1774 CreateEventTask(this, &BookmarkBarViewTest21::Step2
));
1778 // Confirm that a menu for empty folder shows and right click the menu.
1780 // Menu should be showing.
1781 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1782 ASSERT_TRUE(menu
!= NULL
);
1784 views::SubmenuView
* submenu
= menu
->GetSubmenu();
1785 ASSERT_TRUE(submenu
->IsShowing());
1786 ASSERT_EQ(1, submenu
->child_count());
1788 views::View
* view
= submenu
->child_at(0);
1789 ASSERT_TRUE(view
!= NULL
);
1790 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID
, view
->id());
1792 // Right click on the first child to get its context menu.
1793 ui_test_utils::MoveMouseToCenterAndPress(view
, ui_controls::RIGHT
,
1794 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1795 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1798 // Confirm that context menu shows and click REMOVE menu.
1800 // Make sure the context menu is showing.
1801 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1802 ASSERT_TRUE(menu
!= NULL
);
1803 ASSERT_TRUE(menu
->GetSubmenu());
1804 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1806 views::MenuItemView
* delete_menu
=
1807 menu
->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE
);
1808 ASSERT_TRUE(delete_menu
);
1810 // Click on the delete menu item.
1811 ui_test_utils::MoveMouseToCenterAndPress(delete_menu
,
1812 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1813 CreateEventTask(this, &BookmarkBarViewTest21::Step4
));
1816 // Confirm that the empty folder gets removed and menu doesn't show.
1818 views::TextButton
* button
= GetBookmarkButton(5);
1819 ASSERT_TRUE(button
);
1820 EXPECT_EQ(ASCIIToUTF16("d"), button
->text());
1821 EXPECT_TRUE(bb_view_
->GetContextMenu() == NULL
);
1822 EXPECT_TRUE(bb_view_
->GetMenu() == NULL
);
1827 BookmarkContextMenuNotificationObserver observer_
;
1830 VIEW_TEST(BookmarkBarViewTest21
, ContextMenusForEmptyFolder
)