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/location.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/chrome_content_browser_client.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_tabstrip.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
25 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
26 #include "chrome/common/chrome_content_client.h"
27 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/interactive_test_utils.h"
29 #include "chrome/test/base/scoped_testing_local_state.h"
30 #include "chrome/test/base/test_browser_window.h"
31 #include "chrome/test/base/testing_browser_process.h"
32 #include "chrome/test/base/testing_profile.h"
33 #include "chrome/test/base/ui_test_utils.h"
34 #include "chrome/test/base/view_event_test_base.h"
35 #include "components/bookmarks/browser/bookmark_model.h"
36 #include "components/bookmarks/test/bookmark_test_helpers.h"
37 #include "components/constrained_window/constrained_window_views.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/page_navigator.h"
40 #include "content/public/test/test_browser_thread.h"
41 #include "ui/aura/env.h"
42 #include "ui/aura/env_observer.h"
43 #include "ui/aura/window.h"
44 #include "ui/base/clipboard/clipboard.h"
45 #include "ui/base/test/ui_controls.h"
46 #include "ui/events/keycodes/keyboard_codes.h"
47 #include "ui/views/controls/button/menu_button.h"
48 #include "ui/views/controls/menu/menu_controller.h"
49 #include "ui/views/controls/menu/menu_item_view.h"
50 #include "ui/views/controls/menu/submenu_view.h"
51 #include "ui/views/widget/widget.h"
53 using base::ASCIIToUTF16
;
54 using bookmarks::BookmarkModel
;
55 using bookmarks::BookmarkNode
;
56 using content::BrowserThread
;
57 using content::OpenURLParams
;
58 using content::PageNavigator
;
59 using content::WebContents
;
63 // Waits for a views::Widget dialog to show up.
64 class DialogWaiter
: public aura::EnvObserver
,
65 public views::WidgetObserver
{
68 : dialog_created_(false),
70 aura::Env::GetInstance()->AddObserver(this);
73 ~DialogWaiter() override
{ aura::Env::GetInstance()->RemoveObserver(this); }
75 views::Widget
* WaitForDialog() {
78 base::MessageLoopForUI
* loop
= base::MessageLoopForUI::current();
79 base::MessageLoopForUI::ScopedNestableTaskAllower
allow_nested(loop
);
80 base::RunLoop run_loop
;
81 quit_closure_
= run_loop
.QuitClosure();
88 void OnWindowInitialized(aura::Window
* window
) override
{
91 views::Widget
* widget
= views::Widget::GetWidgetForNativeView(window
);
92 if (!widget
|| !widget
->IsDialogBox())
95 dialog_
->AddObserver(this);
98 // views::WidgetObserver:
99 void OnWidgetVisibilityChanged(views::Widget
* widget
, bool visible
) override
{
100 CHECK_EQ(dialog_
, widget
);
102 dialog_created_
= true;
103 dialog_
->RemoveObserver(this);
104 if (!quit_closure_
.is_null())
109 bool dialog_created_
;
110 views::Widget
* dialog_
;
111 base::Closure quit_closure_
;
113 DISALLOW_COPY_AND_ASSIGN(DialogWaiter
);
116 // Waits for a dialog to terminate.
117 class DialogCloseWaiter
: public views::WidgetObserver
{
119 explicit DialogCloseWaiter(views::Widget
* dialog
)
120 : dialog_closed_(false) {
121 dialog
->AddObserver(this);
124 ~DialogCloseWaiter() override
{
125 // It is not necessary to remove |this| from the dialog's observer, since
126 // the dialog is destroyed before this waiter.
129 void WaitForDialogClose() {
132 base::MessageLoopForUI
* loop
= base::MessageLoopForUI::current();
133 base::MessageLoopForUI::ScopedNestableTaskAllower
allow_nested(loop
);
134 base::RunLoop run_loop
;
135 quit_closure_
= run_loop
.QuitClosure();
140 // views::WidgetObserver:
141 void OnWidgetDestroyed(views::Widget
* widget
) override
{
142 dialog_closed_
= true;
143 if (!quit_closure_
.is_null())
148 base::Closure quit_closure_
;
150 DISALLOW_COPY_AND_ASSIGN(DialogCloseWaiter
);
153 // Waits for a views::Widget to receive a Tab key.
154 class TabKeyWaiter
: public ui::EventHandler
{
156 explicit TabKeyWaiter(views::Widget
* widget
)
158 received_tab_(false) {
159 widget_
->GetNativeView()->AddPreTargetHandler(this);
162 ~TabKeyWaiter() override
{
163 widget_
->GetNativeView()->RemovePreTargetHandler(this);
169 base::MessageLoopForUI
* loop
= base::MessageLoopForUI::current();
170 base::MessageLoopForUI::ScopedNestableTaskAllower
allow_nested(loop
);
171 base::RunLoop run_loop
;
172 quit_closure_
= run_loop
.QuitClosure();
178 void OnKeyEvent(ui::KeyEvent
* event
) override
{
179 if (event
->type() == ui::ET_KEY_RELEASED
&&
180 event
->key_code() == ui::VKEY_TAB
) {
181 received_tab_
= true;
182 if (!quit_closure_
.is_null())
187 views::Widget
* widget_
;
189 base::Closure quit_closure_
;
191 DISALLOW_COPY_AND_ASSIGN(TabKeyWaiter
);
194 void MoveMouseAndPress(const gfx::Point
& screen_pos
,
195 ui_controls::MouseButton button
,
197 const base::Closure
& closure
) {
198 ui_controls::SendMouseMove(screen_pos
.x(), screen_pos
.y());
199 ui_controls::SendMouseEventsNotifyWhenDone(button
, state
, closure
);
202 // PageNavigator implementation that records the URL.
203 class TestingPageNavigator
: public PageNavigator
{
205 WebContents
* OpenURL(const OpenURLParams
& params
) override
{
213 // TODO(erg): Fix bookmark DND tests on linux_aura. crbug.com/163931
214 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
215 #define MAYBE(x) DISABLED_##x
222 // Base class for event generating bookmark view tests. These test are intended
223 // to exercise View's menus, but that's easier done with BookmarkBarView rather
224 // than View's menu itself.
226 // SetUp creates a bookmark model with the following structure.
227 // All folders are in upper case, all URLs in lower case.
248 // * if CreateBigMenu returns return true, 100 menu items are created here with
249 // the names f1-f100.
251 // Subclasses should be sure and invoke super's implementation of SetUp and
253 class BookmarkBarViewEventTestBase
: public ViewEventTestBase
{
255 BookmarkBarViewEventTestBase()
256 : ViewEventTestBase(),
259 void SetUp() override
{
260 content_client_
.reset(new ChromeContentClient
);
261 content::SetContentClient(content_client_
.get());
262 browser_content_client_
.reset(new ChromeContentBrowserClient());
263 content::SetBrowserClientForTesting(browser_content_client_
.get());
265 views::MenuController::TurnOffMenuSelectionHoldForTest();
266 BookmarkBarView::DisableAnimationsForTesting(true);
267 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient());
269 profile_
.reset(new TestingProfile());
270 profile_
->CreateBookmarkModel(true);
271 model_
= BookmarkModelFactory::GetForProfile(profile_
.get());
272 bookmarks::test::WaitForBookmarkModelToLoad(model_
);
273 profile_
->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar
, true);
275 Browser::CreateParams
native_params(profile_
.get(),
276 chrome::GetActiveDesktop());
277 browser_
= chrome::CreateBrowserWithTestWindowForParams(&native_params
);
279 local_state_
.reset(new ScopedTestingLocalState(
280 TestingBrowserProcess::GetGlobal()));
281 model_
->ClearStore();
283 bb_view_
.reset(new BookmarkBarView(browser_
.get(), NULL
));
284 bb_view_
->set_owned_by_client();
285 bb_view_
->SetPageNavigator(&navigator_
);
287 AddTestData(CreateBigMenu());
289 // Create the Widget. Note the initial size is given by GetPreferredSize()
290 // during initialization. This occurs after the WidgetDelegate provides
291 // |bb_view_| as the contents view and adds it to the hierarchy.
292 ViewEventTestBase::SetUp();
294 // Verify the layout triggered by the initial size preserves the overflow
295 // state calculated in GetPreferredSize().
296 EXPECT_TRUE(GetBookmarkButton(5)->visible());
297 EXPECT_FALSE(GetBookmarkButton(6)->visible());
300 void TearDown() override
{
301 // Destroy everything, then run the message loop to ensure we delete all
302 // Tasks and fully shut down.
303 browser_
->tab_strip_model()->CloseAllTabs();
308 // Run the message loop to ensure we delete allTasks and fully shut down.
309 base::MessageLoopForUI
* loop
= base::MessageLoopForUI::current();
310 base::MessageLoopForUI::ScopedNestableTaskAllower
allow_nested(loop
);
311 base::RunLoop run_loop
;
312 loop
->task_runner()->PostTask(FROM_HERE
, run_loop
.QuitClosure());
315 ViewEventTestBase::TearDown();
316 BookmarkBarView::DisableAnimationsForTesting(false);
317 constrained_window::SetConstrainedWindowViewsClient(nullptr);
319 browser_content_client_
.reset();
320 content_client_
.reset();
321 content::SetContentClient(NULL
);
325 views::View
* CreateContentsView() override
{ return bb_view_
.get(); }
327 gfx::Size
GetPreferredSize() const override
{
328 // Calculate the preferred size so that one button doesn't fit, which
329 // triggers the overflow button to appear. We have to do this incrementally
330 // as there isn't a good way to determine the point at which the overflow
333 // This code looks a bit hacky, but it is written so that it shouldn't
334 // depend on any of the layout code in BookmarkBarView, or extra buttons
335 // added to the right of the bookmarks. Instead, brute force search for a
336 // size that triggers the overflow button.
337 gfx::Size size
= bb_view_
->GetPreferredSize();
338 size
.set_width(1000);
340 size
.set_width(size
.width() - 25);
341 bb_view_
->SetBounds(0, 0, size
.width(), size
.height());
343 } while (bb_view_
->GetBookmarkButton(6)->visible());
347 views::LabelButton
* GetBookmarkButton(int view_index
) {
348 return bb_view_
->GetBookmarkButton(view_index
);
351 // See comment above class description for what this does.
352 virtual bool CreateBigMenu() { return false; }
354 BookmarkModel
* model_
;
355 scoped_ptr
<BookmarkBarView
> bb_view_
;
356 TestingPageNavigator navigator_
;
359 void AddTestData(bool big_menu
) {
360 const BookmarkNode
* bb_node
= model_
->bookmark_bar_node();
361 std::string test_base
= "file:///c:/tmp/";
362 const BookmarkNode
* f1
= model_
->AddFolder(bb_node
, 0, ASCIIToUTF16("F1"));
363 model_
->AddURL(f1
, 0, ASCIIToUTF16("f1a"), GURL(test_base
+ "f1a"));
364 const BookmarkNode
* f11
= model_
->AddFolder(f1
, 1, ASCIIToUTF16("F11"));
365 model_
->AddURL(f11
, 0, ASCIIToUTF16("f11a"), GURL(test_base
+ "f11a"));
367 for (int i
= 1; i
<= 100; ++i
) {
368 model_
->AddURL(f1
, i
+ 1, ASCIIToUTF16("f") + base::IntToString16(i
),
369 GURL(test_base
+ "f" + base::IntToString(i
)));
372 model_
->AddURL(bb_node
, 1, ASCIIToUTF16("a"), GURL(test_base
+ "a"));
373 model_
->AddURL(bb_node
, 2, ASCIIToUTF16("b"), GURL(test_base
+ "b"));
374 model_
->AddURL(bb_node
, 3, ASCIIToUTF16("c"), GURL(test_base
+ "c"));
375 model_
->AddURL(bb_node
, 4, ASCIIToUTF16("d"), GURL(test_base
+ "d"));
376 model_
->AddFolder(bb_node
, 5, ASCIIToUTF16("F2"));
377 model_
->AddURL(bb_node
, 6, ASCIIToUTF16("d"), GURL(test_base
+ "d"));
379 model_
->AddURL(model_
->other_node(), 0, ASCIIToUTF16("oa"),
380 GURL(test_base
+ "oa"));
381 const BookmarkNode
* of
= model_
->AddFolder(model_
->other_node(), 1,
383 model_
->AddURL(of
, 0, ASCIIToUTF16("ofa"), GURL(test_base
+ "ofa"));
384 model_
->AddURL(of
, 1, ASCIIToUTF16("ofb"), GURL(test_base
+ "ofb"));
385 const BookmarkNode
* of2
= model_
->AddFolder(model_
->other_node(), 2,
386 ASCIIToUTF16("OF2"));
387 model_
->AddURL(of2
, 0, ASCIIToUTF16("of2a"), GURL(test_base
+ "of2a"));
388 model_
->AddURL(of2
, 1, ASCIIToUTF16("of2b"), GURL(test_base
+ "of2b"));
391 scoped_ptr
<ChromeContentClient
> content_client_
;
392 scoped_ptr
<ChromeContentBrowserClient
> browser_content_client_
;
393 scoped_ptr
<TestingProfile
> profile_
;
394 scoped_ptr
<Browser
> browser_
;
395 scoped_ptr
<ScopedTestingLocalState
> local_state_
;
398 // Clicks on first menu, makes sure button is depressed. Moves mouse to first
399 // child, clicks it and makes sure a navigation occurs.
400 class BookmarkBarViewTest1
: public BookmarkBarViewEventTestBase
{
402 void DoTestOnMessageLoop() override
{
403 // Move the mouse to the first folder on the bookmark bar and press the
405 views::LabelButton
* button
= GetBookmarkButton(0);
406 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
407 ui_controls::DOWN
| ui_controls::UP
,
408 CreateEventTask(this, &BookmarkBarViewTest1::Step2
));
413 // Menu should be showing.
414 views::MenuItemView
* menu
= bb_view_
->GetMenu();
415 ASSERT_TRUE(menu
!= NULL
);
416 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
418 // Button should be depressed.
419 views::LabelButton
* button
= GetBookmarkButton(0);
420 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_PRESSED
);
422 // Click on the 2nd menu item (A URL).
423 ASSERT_TRUE(menu
->GetSubmenu());
425 views::MenuItemView
* menu_to_select
=
426 menu
->GetSubmenu()->GetMenuItemAt(0);
427 ui_test_utils::MoveMouseToCenterAndPress(menu_to_select
, ui_controls::LEFT
,
428 ui_controls::DOWN
| ui_controls::UP
,
429 CreateEventTask(this, &BookmarkBarViewTest1::Step3
));
433 // We should have navigated to URL f1a.
434 ASSERT_TRUE(navigator_
.url_
==
435 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url());
437 // Make sure button is no longer pushed.
438 views::LabelButton
* button
= GetBookmarkButton(0);
439 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_NORMAL
);
441 views::MenuItemView
* menu
= bb_view_
->GetMenu();
442 ASSERT_TRUE(menu
== NULL
|| !menu
->GetSubmenu()->IsShowing());
448 VIEW_TEST(BookmarkBarViewTest1
, Basic
)
450 // Brings up menu, clicks on empty space and make sure menu hides.
451 class BookmarkBarViewTest2
: public BookmarkBarViewEventTestBase
{
453 void DoTestOnMessageLoop() override
{
454 // Move the mouse to the first folder on the bookmark bar and press the
456 views::LabelButton
* button
= GetBookmarkButton(0);
457 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
458 ui_controls::DOWN
| ui_controls::UP
,
459 CreateEventTask(this, &BookmarkBarViewTest2::Step2
));
464 // Menu should be showing.
465 views::MenuItemView
* menu
= bb_view_
->GetMenu();
466 ASSERT_TRUE(menu
!= NULL
&& menu
->GetSubmenu()->IsShowing());
468 // Click on 0x0, which should trigger closing menu.
469 // NOTE: this code assume there is a left margin, which is currently
470 // true. If that changes, this code will need to find another empty space
471 // to press the mouse on.
472 gfx::Point mouse_loc
;
473 views::View::ConvertPointToScreen(bb_view_
.get(), &mouse_loc
);
474 ui_controls::SendMouseMoveNotifyWhenDone(0, 0,
475 CreateEventTask(this, &BookmarkBarViewTest2::Step3
));
479 // As the click is on the desktop the hook never sees the up, so we only
480 // wait on the down. We still send the up though else the system thinks
481 // the mouse is still down.
482 ui_controls::SendMouseEventsNotifyWhenDone(
483 ui_controls::LEFT
, ui_controls::DOWN
,
484 CreateEventTask(this, &BookmarkBarViewTest2::Step4
));
485 ui_controls::SendMouseEvents(ui_controls::LEFT
, ui_controls::UP
);
489 // The menu shouldn't be showing.
490 views::MenuItemView
* menu
= bb_view_
->GetMenu();
491 ASSERT_TRUE(menu
== NULL
|| !menu
->GetSubmenu()->IsShowing());
493 // Make sure button is no longer pushed.
494 views::LabelButton
* button
= GetBookmarkButton(0);
495 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_NORMAL
);
501 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
502 // TODO(erg): linux_aura bringup: http://crbug.com/163931
503 #define MAYBE_HideOnDesktopClick DISABLED_HideOnDesktopClick
505 #define MAYBE_HideOnDesktopClick HideOnDesktopClick
508 VIEW_TEST(BookmarkBarViewTest2
, MAYBE_HideOnDesktopClick
)
510 // Brings up menu. Moves over child to make sure submenu appears, moves over
511 // another child and make sure next menu appears.
512 class BookmarkBarViewTest3
: public BookmarkBarViewEventTestBase
{
514 void DoTestOnMessageLoop() override
{
515 // Move the mouse to the first folder on the bookmark bar and press the
517 views::MenuButton
* button
= bb_view_
->other_bookmarks_button();
518 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
519 ui_controls::DOWN
| ui_controls::UP
,
520 CreateEventTask(this, &BookmarkBarViewTest3::Step2
));
525 // Menu should be showing.
526 views::MenuItemView
* menu
= bb_view_
->GetMenu();
527 ASSERT_TRUE(menu
!= NULL
);
528 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
530 views::MenuItemView
* child_menu
=
531 menu
->GetSubmenu()->GetMenuItemAt(1);
532 ASSERT_TRUE(child_menu
!= NULL
);
534 // Click on second child, which has a submenu.
535 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
536 ui_controls::DOWN
| ui_controls::UP
,
537 CreateEventTask(this, &BookmarkBarViewTest3::Step3
));
541 // Make sure sub menu is showing.
542 views::MenuItemView
* menu
= bb_view_
->GetMenu();
544 views::MenuItemView
* child_menu
=
545 menu
->GetSubmenu()->GetMenuItemAt(1);
546 ASSERT_TRUE(child_menu
->GetSubmenu() != NULL
);
547 ASSERT_TRUE(child_menu
->GetSubmenu()->IsShowing());
549 // Click on third child, which has a submenu too.
550 child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
551 ASSERT_TRUE(child_menu
!= NULL
);
552 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
553 ui_controls::DOWN
| ui_controls::UP
,
554 CreateEventTask(this, &BookmarkBarViewTest3::Step4
));
558 // Make sure sub menu we first clicked isn't showing.
559 views::MenuItemView
* menu
= bb_view_
->GetMenu();
560 views::MenuItemView
* child_menu
=
561 menu
->GetSubmenu()->GetMenuItemAt(1);
562 ASSERT_TRUE(child_menu
->GetSubmenu() != NULL
);
563 ASSERT_FALSE(child_menu
->GetSubmenu()->IsShowing());
565 // And submenu we last clicked is showing.
566 child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
567 ASSERT_TRUE(child_menu
!= NULL
);
568 ASSERT_TRUE(child_menu
->GetSubmenu()->IsShowing());
570 // Nothing should have been selected.
571 EXPECT_EQ(GURL(), navigator_
.url_
);
574 menu
->GetMenuController()->CancelAll();
580 VIEW_TEST(BookmarkBarViewTest3
, Submenus
)
582 // Observer that posts task upon the context menu creation.
583 // This is necessary for Linux as the context menu has to check
584 // the clipboard, which invokes the event loop.
585 class BookmarkContextMenuNotificationObserver
586 : public content::NotificationObserver
{
588 explicit BookmarkContextMenuNotificationObserver(const base::Closure
& task
)
591 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN
,
592 content::NotificationService::AllSources());
595 void Observe(int type
,
596 const content::NotificationSource
& source
,
597 const content::NotificationDetails
& details
) override
{
598 base::MessageLoop::current()->task_runner()->PostTask(FROM_HERE
, task_
);
601 // Sets the task that is posted when the context menu is shown.
602 void set_task(const base::Closure
& task
) { task_
= task
; }
605 content::NotificationRegistrar registrar_
;
608 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver
);
611 // Tests context menus by way of opening a context menu for a bookmark,
612 // then right clicking to get context menu and selecting the first menu item
614 class BookmarkBarViewTest4
: public BookmarkBarViewEventTestBase
{
616 BookmarkBarViewTest4()
617 : observer_(CreateEventTask(this, &BookmarkBarViewTest4::Step3
)) {
621 void DoTestOnMessageLoop() override
{
622 // Move the mouse to the first folder on the bookmark bar and press the
624 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
625 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
626 ui_controls::DOWN
| ui_controls::UP
,
627 CreateEventTask(this, &BookmarkBarViewTest4::Step2
));
632 // Menu should be showing.
633 views::MenuItemView
* menu
= bb_view_
->GetMenu();
634 ASSERT_TRUE(menu
!= NULL
);
635 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
637 views::MenuItemView
* child_menu
=
638 menu
->GetSubmenu()->GetMenuItemAt(0);
639 ASSERT_TRUE(child_menu
!= NULL
);
641 // Right click on the first child to get its context menu.
642 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
643 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
644 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
648 // Make sure the context menu is showing.
649 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
650 ASSERT_TRUE(menu
!= NULL
);
651 ASSERT_TRUE(menu
->GetSubmenu());
652 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
654 // Select the first menu item (open).
655 ui_test_utils::MoveMouseToCenterAndPress(
656 menu
->GetSubmenu()->GetMenuItemAt(0),
657 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
658 CreateEventTask(this, &BookmarkBarViewTest4::Step4
));
662 EXPECT_EQ(navigator_
.url_
, model_
->other_node()->GetChild(0)->url());
666 BookmarkContextMenuNotificationObserver observer_
;
669 VIEW_TEST(BookmarkBarViewTest4
, ContextMenus
)
671 // Tests drag and drop within the same menu.
672 class BookmarkBarViewTest5
: public BookmarkBarViewEventTestBase
{
674 void DoTestOnMessageLoop() override
{
676 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
678 // Move the mouse to the first folder on the bookmark bar and press the
680 views::LabelButton
* button
= GetBookmarkButton(0);
681 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
682 ui_controls::DOWN
| ui_controls::UP
,
683 CreateEventTask(this, &BookmarkBarViewTest5::Step2
));
688 // Menu should be showing.
689 views::MenuItemView
* menu
= bb_view_
->GetMenu();
690 ASSERT_TRUE(menu
!= NULL
);
691 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
693 views::MenuItemView
* child_menu
=
694 menu
->GetSubmenu()->GetMenuItemAt(0);
695 ASSERT_TRUE(child_menu
!= NULL
);
697 // Move mouse to center of menu and press button.
698 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
700 CreateEventTask(this, &BookmarkBarViewTest5::Step3
));
704 views::MenuItemView
* target_menu
=
705 bb_view_
->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
706 gfx::Point
loc(1, target_menu
->height() - 1);
707 views::View::ConvertPointToScreen(target_menu
, &loc
);
710 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
711 CreateEventTask(this, &BookmarkBarViewTest5::Step4
));
713 // See comment above this method as to why we do this.
714 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
718 // Drop the item so that it's now the second item.
719 views::MenuItemView
* target_menu
=
720 bb_view_
->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
721 gfx::Point
loc(1, target_menu
->height() - 2);
722 views::View::ConvertPointToScreen(target_menu
, &loc
);
723 ui_controls::SendMouseMove(loc
.x(), loc
.y());
725 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT
,
727 CreateEventTask(this, &BookmarkBarViewTest5::Step5
));
731 GURL url
= model_
->bookmark_bar_node()->GetChild(0)->GetChild(1)->url();
732 EXPECT_EQ(url_dragging_
, url
);
739 #if !defined(OS_WIN) // flaky http://crbug.com/400578
740 VIEW_TEST(BookmarkBarViewTest5
, DND
)
743 // Tests holding mouse down on overflow button, dragging such that menu pops up
744 // then selecting an item.
745 class BookmarkBarViewTest6
: public BookmarkBarViewEventTestBase
{
747 void DoTestOnMessageLoop() override
{
748 // Press the mouse button on the overflow button. Don't release it though.
749 views::LabelButton
* button
= bb_view_
->overflow_button();
750 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
751 ui_controls::DOWN
, CreateEventTask(this, &BookmarkBarViewTest6::Step2
));
756 // Menu should be showing.
757 views::MenuItemView
* menu
= bb_view_
->GetMenu();
758 ASSERT_TRUE(menu
!= NULL
);
759 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
761 views::MenuItemView
* child_menu
=
762 menu
->GetSubmenu()->GetMenuItemAt(0);
763 ASSERT_TRUE(child_menu
!= NULL
);
765 // Move mouse to center of menu and release mouse.
766 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
767 ui_controls::UP
, CreateEventTask(this, &BookmarkBarViewTest6::Step3
));
771 ASSERT_TRUE(navigator_
.url_
==
772 model_
->bookmark_bar_node()->GetChild(6)->url());
779 #if defined(OS_WIN) // flaky http://crbug.com/523255
780 #define MAYBE_OpenMenuOnClickAndHold DISABLED_OpenMenuOnClickAndHold
782 #define MAYBE_OpenMenuOnClickAndHold OpenMenuOnClickAndHold
784 VIEW_TEST(BookmarkBarViewTest6
, MAYBE_OpenMenuOnClickAndHold
)
786 // Tests drag and drop to different menu.
787 class BookmarkBarViewTest7
: public BookmarkBarViewEventTestBase
{
789 void DoTestOnMessageLoop() override
{
791 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
793 // Move the mouse to the first folder on the bookmark bar and press the
795 views::LabelButton
* button
= GetBookmarkButton(0);
796 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
797 ui_controls::DOWN
| ui_controls::UP
,
798 CreateEventTask(this, &BookmarkBarViewTest7::Step2
));
803 // Menu should be showing.
804 views::MenuItemView
* menu
= bb_view_
->GetMenu();
805 ASSERT_TRUE(menu
!= NULL
);
806 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
808 views::MenuItemView
* child_menu
=
809 menu
->GetSubmenu()->GetMenuItemAt(0);
810 ASSERT_TRUE(child_menu
!= NULL
);
812 // Move mouse to center of menu and press button.
813 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
815 CreateEventTask(this, &BookmarkBarViewTest7::Step3
));
819 // Drag over other button.
820 views::LabelButton
* other_button
= bb_view_
->other_bookmarks_button();
821 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
822 views::View::ConvertPointToScreen(other_button
, &loc
);
824 #if defined(USE_AURA)
825 // TODO: fix this. Aura requires an additional mouse event to trigger drag
826 // and drop checking state.
827 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
828 base::Bind(&BookmarkBarViewTest7::Step3A
, this));
831 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
832 base::Bind(&BookmarkBarViewTest7::Step4
, this));
834 // See comment above this method as to why we do this.
835 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
840 // Drag over other button.
841 views::LabelButton
* other_button
= bb_view_
->other_bookmarks_button();
842 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
843 views::View::ConvertPointToScreen(other_button
, &loc
);
845 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
846 base::Bind(&BookmarkBarViewTest7::Step4
, this));
850 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
851 ASSERT_TRUE(drop_menu
!= NULL
);
852 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
854 views::MenuItemView
* target_menu
=
855 drop_menu
->GetSubmenu()->GetMenuItemAt(0);
856 gfx::Point
loc(1, 1);
857 views::View::ConvertPointToScreen(target_menu
, &loc
);
858 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
859 CreateEventTask(this, &BookmarkBarViewTest7::Step5
));
863 ui_controls::SendMouseEventsNotifyWhenDone(
864 ui_controls::LEFT
, ui_controls::UP
,
865 CreateEventTask(this, &BookmarkBarViewTest7::Step6
));
869 ASSERT_TRUE(model_
->other_node()->GetChild(0)->url() == url_dragging_
);
877 // This test passes locally (on aero and non-aero) but fails on the trybots and
879 // http://crbug.com/154081
880 VIEW_TEST(BookmarkBarViewTest7
, MAYBE(DNDToDifferentMenu
))
883 // Drags from one menu to next so that original menu closes, then back to
885 class BookmarkBarViewTest8
: public BookmarkBarViewEventTestBase
{
887 void DoTestOnMessageLoop() override
{
889 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url();
891 // Move the mouse to the first folder on the bookmark bar and press the
893 views::LabelButton
* button
= GetBookmarkButton(0);
894 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
895 ui_controls::DOWN
| ui_controls::UP
,
896 CreateEventTask(this, &BookmarkBarViewTest8::Step2
));
901 // Menu should be showing.
902 views::MenuItemView
* menu
= bb_view_
->GetMenu();
903 ASSERT_TRUE(menu
!= NULL
);
904 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
906 views::MenuItemView
* child_menu
=
907 menu
->GetSubmenu()->GetMenuItemAt(0);
908 ASSERT_TRUE(child_menu
!= NULL
);
910 // Move mouse to center of menu and press button.
911 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::LEFT
,
913 CreateEventTask(this, &BookmarkBarViewTest8::Step3
));
917 // Drag over other button.
918 views::LabelButton
* other_button
= bb_view_
->other_bookmarks_button();
919 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
920 views::View::ConvertPointToScreen(other_button
, &loc
);
923 #if defined(USE_AURA)
924 // TODO: fix this. Aura requires an additional mouse event to trigger drag
925 // and drop checking state.
926 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
927 base::Bind(&BookmarkBarViewTest8::Step3A
, this));
929 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
930 base::Bind(&BookmarkBarViewTest8::Step4
, this));
931 // See comment above this method as to why we do this.
932 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
937 // Drag over other button.
938 views::LabelButton
* other_button
= bb_view_
->other_bookmarks_button();
939 gfx::Point
loc(other_button
->width() / 2, other_button
->height() / 2);
940 views::View::ConvertPointToScreen(other_button
, &loc
);
942 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
943 base::Bind(&BookmarkBarViewTest8::Step4
, this));
947 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
948 ASSERT_TRUE(drop_menu
!= NULL
);
949 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
951 // Now drag back over first menu.
952 views::LabelButton
* button
= GetBookmarkButton(0);
953 gfx::Point
loc(button
->width() / 2, button
->height() / 2);
954 views::View::ConvertPointToScreen(button
, &loc
);
955 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x(), loc
.y(),
956 base::Bind(&BookmarkBarViewTest8::Step5
, this));
960 // Drop on folder F11.
961 views::MenuItemView
* drop_menu
= bb_view_
->GetDropMenu();
962 ASSERT_TRUE(drop_menu
!= NULL
);
963 ASSERT_TRUE(drop_menu
->GetSubmenu()->IsShowing());
965 views::MenuItemView
* target_menu
=
966 drop_menu
->GetSubmenu()->GetMenuItemAt(1);
967 ui_test_utils::MoveMouseToCenterAndPress(
968 target_menu
, ui_controls::LEFT
, ui_controls::UP
,
969 CreateEventTask(this, &BookmarkBarViewTest8::Step6
));
973 // Make sure drop was processed.
974 GURL final_url
= model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->
976 ASSERT_TRUE(final_url
== url_dragging_
);
984 // This test passes locally (on aero and non-aero) but fails on the trybots and
986 // http://crbug.com/154081
987 VIEW_TEST(BookmarkBarViewTest8
, MAYBE(DNDBackToOriginatingMenu
))
990 // Moves the mouse over the scroll button and makes sure we get scrolling.
991 class BookmarkBarViewTest9
: public BookmarkBarViewEventTestBase
{
993 bool CreateBigMenu() override
{ return true; }
995 void DoTestOnMessageLoop() override
{
996 // Move the mouse to the first folder on the bookmark bar and press the
998 views::LabelButton
* button
= GetBookmarkButton(0);
999 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1000 ui_controls::DOWN
| ui_controls::UP
,
1001 CreateEventTask(this, &BookmarkBarViewTest9::Step2
));
1006 // Menu should be showing.
1007 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1008 ASSERT_TRUE(menu
!= NULL
);
1009 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1011 first_menu_
= menu
->GetSubmenu()->GetMenuItemAt(0);
1012 gfx::Point menu_loc
;
1013 views::View::ConvertPointToScreen(first_menu_
, &menu_loc
);
1014 start_y_
= menu_loc
.y();
1016 // Move the mouse over the scroll button.
1017 views::View
* scroll_container
= menu
->GetSubmenu()->parent();
1018 ASSERT_TRUE(scroll_container
!= NULL
);
1019 scroll_container
= scroll_container
->parent();
1020 ASSERT_TRUE(scroll_container
!= NULL
);
1021 views::View
* scroll_down_button
= scroll_container
->child_at(1);
1022 ASSERT_TRUE(scroll_down_button
);
1023 gfx::Point
loc(scroll_down_button
->width() / 2,
1024 scroll_down_button
->height() / 2);
1025 views::View::ConvertPointToScreen(scroll_down_button
, &loc
);
1027 // On linux, the sending one location isn't enough.
1028 ui_controls::SendMouseMove(loc
.x() - 1 , loc
.y() - 1);
1029 ui_controls::SendMouseMoveNotifyWhenDone(
1030 loc
.x(), loc
.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3
));
1034 base::MessageLoop::current()->task_runner()->PostDelayedTask(
1035 FROM_HERE
, base::Bind(&BookmarkBarViewTest9::Step4
, this),
1036 base::TimeDelta::FromMilliseconds(200));
1040 gfx::Point menu_loc
;
1041 views::View::ConvertPointToScreen(first_menu_
, &menu_loc
);
1042 ASSERT_NE(start_y_
, menu_loc
.y());
1045 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
1047 // On linux, Cancelling menu will call Quit on the message loop,
1048 // which can interfere with Done. We need to run Done in the
1049 // next execution loop.
1050 base::MessageLoop::current()->task_runner()->PostTask(
1051 FROM_HERE
, base::Bind(&ViewEventTestBase::Done
, this));
1055 views::MenuItemView
* first_menu_
;
1058 // Fails on official cros bot. crbug.com/431427.
1059 #if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)
1060 #define MAYBE_ScrollButtonScrolls DISABLED_ScrollButtonScrolls
1062 #define MAYBE_ScrollButtonScrolls ScrollButtonScrolls
1065 VIEW_TEST(BookmarkBarViewTest9
, MAYBE_ScrollButtonScrolls
)
1067 // Tests up/down/left/enter key messages.
1068 class BookmarkBarViewTest10
: public BookmarkBarViewEventTestBase
{
1070 void DoTestOnMessageLoop() override
{
1071 // Move the mouse to the first folder on the bookmark bar and press the
1073 views::LabelButton
* button
= GetBookmarkButton(0);
1074 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1075 ui_controls::DOWN
| ui_controls::UP
,
1076 CreateEventTask(this, &BookmarkBarViewTest10::Step2
));
1077 base::MessageLoop::current()->RunUntilIdle();
1082 // Menu should be showing.
1083 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1084 ASSERT_TRUE(menu
!= NULL
);
1085 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1087 // Send a down event, which should select the first item.
1088 ui_controls::SendKeyPressNotifyWhenDone(
1089 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
1090 CreateEventTask(this, &BookmarkBarViewTest10::Step3
));
1094 // Make sure menu is showing and item is selected.
1095 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1096 ASSERT_TRUE(menu
!= NULL
);
1097 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1098 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
1100 // Send a key down event, which should select the next item.
1101 ui_controls::SendKeyPressNotifyWhenDone(
1102 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
1103 CreateEventTask(this, &BookmarkBarViewTest10::Step4
));
1107 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1108 ASSERT_TRUE(menu
!= NULL
);
1109 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1110 ASSERT_FALSE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
1111 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(1)->IsSelected());
1113 // Send a right arrow to force the menu to open.
1114 ui_controls::SendKeyPressNotifyWhenDone(
1115 window_
->GetNativeWindow(), ui::VKEY_RIGHT
, false, false, false, false,
1116 CreateEventTask(this, &BookmarkBarViewTest10::Step5
));
1120 // Make sure the submenu is showing.
1121 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1122 ASSERT_TRUE(menu
!= NULL
);
1123 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1124 views::MenuItemView
* submenu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1125 ASSERT_TRUE(submenu
->IsSelected());
1126 ASSERT_TRUE(submenu
->GetSubmenu());
1127 ASSERT_TRUE(submenu
->GetSubmenu()->IsShowing());
1129 // Send a left arrow to close the submenu.
1130 ui_controls::SendKeyPressNotifyWhenDone(
1131 window_
->GetNativeWindow(), ui::VKEY_LEFT
, false, false, false, false,
1132 CreateEventTask(this, &BookmarkBarViewTest10::Step6
));
1136 // Make sure the submenu is showing.
1137 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1138 ASSERT_TRUE(menu
!= NULL
);
1139 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1140 views::MenuItemView
* submenu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1141 ASSERT_TRUE(submenu
->IsSelected());
1142 ASSERT_TRUE(!submenu
->GetSubmenu() || !submenu
->GetSubmenu()->IsShowing());
1144 // Send a down arrow to wrap back to f1a
1145 ui_controls::SendKeyPressNotifyWhenDone(
1146 window_
->GetNativeWindow(), ui::VKEY_DOWN
, false, false, false, false,
1147 CreateEventTask(this, &BookmarkBarViewTest10::Step7
));
1151 // Make sure menu is showing and item is selected.
1152 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1153 ASSERT_TRUE(menu
!= NULL
);
1154 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1155 ASSERT_TRUE(menu
->GetSubmenu()->GetMenuItemAt(0)->IsSelected());
1157 // Send enter, which should select the item.
1158 ui_controls::SendKeyPressNotifyWhenDone(
1159 window_
->GetNativeWindow(), ui::VKEY_RETURN
, false, false, false, false,
1160 CreateEventTask(this, &BookmarkBarViewTest10::Step8
));
1165 model_
->bookmark_bar_node()->GetChild(0)->GetChild(0)->url() ==
1171 #if defined(USE_OZONE)
1172 // ozone bringup - http://crbug.com/401304
1173 #define MAYBE_KeyEvents DISABLED_KeyEvents
1175 #define MAYBE_KeyEvents KeyEvents
1178 VIEW_TEST(BookmarkBarViewTest10
, MAYBE_KeyEvents
)
1180 // Make sure the menu closes with the following sequence: show menu, show
1181 // context menu, close context menu (via escape), then click else where. This
1182 // effectively verifies we maintain mouse capture after the context menu is
1184 class BookmarkBarViewTest11
: public BookmarkBarViewEventTestBase
{
1186 BookmarkBarViewTest11()
1187 : observer_(CreateEventTask(this, &BookmarkBarViewTest11::Step3
)) {
1191 void DoTestOnMessageLoop() override
{
1192 // Move the mouse to the first folder on the bookmark bar and press the
1194 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1195 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1196 ui_controls::DOWN
| ui_controls::UP
,
1197 CreateEventTask(this, &BookmarkBarViewTest11::Step2
));
1202 // Menu should be showing.
1203 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1204 ASSERT_TRUE(menu
!= NULL
);
1205 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1207 views::MenuItemView
* child_menu
=
1208 menu
->GetSubmenu()->GetMenuItemAt(0);
1209 ASSERT_TRUE(child_menu
!= NULL
);
1211 // Right click on the first child to get its context menu.
1212 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1213 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1214 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1218 // Send escape so that the context menu hides.
1219 ui_controls::SendKeyPressNotifyWhenDone(
1220 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
1221 CreateEventTask(this, &BookmarkBarViewTest11::Step4
));
1225 // Make sure the context menu is no longer showing.
1226 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1227 ASSERT_TRUE(!menu
|| !menu
->GetSubmenu() ||
1228 !menu
->GetSubmenu()->IsShowing());
1230 // But the menu should be showing.
1231 menu
= bb_view_
->GetMenu();
1232 ASSERT_TRUE(menu
&& menu
->GetSubmenu() && menu
->GetSubmenu()->IsShowing());
1234 // Now click on empty space.
1235 gfx::Point mouse_loc
;
1236 views::View::ConvertPointToScreen(bb_view_
.get(), &mouse_loc
);
1237 ui_controls::SendMouseMove(mouse_loc
.x(), mouse_loc
.y());
1238 ui_controls::SendMouseEventsNotifyWhenDone(
1239 ui_controls::LEFT
, ui_controls::UP
| ui_controls::DOWN
,
1240 CreateEventTask(this, &BookmarkBarViewTest11::Step5
));
1244 // Make sure the menu is not showing.
1245 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1246 ASSERT_TRUE(!menu
|| !menu
->GetSubmenu() ||
1247 !menu
->GetSubmenu()->IsShowing());
1251 BookmarkContextMenuNotificationObserver observer_
;
1254 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1255 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1256 #define MAYBE_CloseMenuAfterClosingContextMenu \
1257 DISABLED_CloseMenuAfterClosingContextMenu
1258 #elif defined(USE_OZONE)
1259 // ozone bringup - http://crbug.com/401304
1260 #define MAYBE_CloseMenuAfterClosingContextMenu \
1261 DISABLED_CloseMenuAfterClosingContextMenu
1263 #define MAYBE_CloseMenuAfterClosingContextMenu CloseMenuAfterClosingContextMenu
1266 VIEW_TEST(BookmarkBarViewTest11
, MAYBE_CloseMenuAfterClosingContextMenu
)
1268 // Tests showing a modal dialog from a context menu.
1269 class BookmarkBarViewTest12
: public BookmarkBarViewEventTestBase
{
1271 void DoTestOnMessageLoop() override
{
1272 // Open up the other folder.
1273 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1274 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1275 ui_controls::DOWN
| ui_controls::UP
,
1276 CreateEventTask(this, &BookmarkBarViewTest12::Step2
));
1277 chrome::num_bookmark_urls_before_prompting
= 1;
1280 ~BookmarkBarViewTest12() override
{
1281 chrome::num_bookmark_urls_before_prompting
= 15;
1286 // Menu should be showing.
1287 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1288 ASSERT_TRUE(menu
!= NULL
);
1289 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1291 views::MenuItemView
* child_menu
=
1292 menu
->GetSubmenu()->GetMenuItemAt(1);
1293 ASSERT_TRUE(child_menu
!= NULL
);
1295 // Right click on the second child (a folder) to get its context menu.
1296 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1297 ui_controls::DOWN
| ui_controls::UP
,
1298 CreateEventTask(this, &BookmarkBarViewTest12::Step3
));
1302 // Make sure the context menu is showing.
1303 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1304 ASSERT_TRUE(menu
&& menu
->GetSubmenu() && menu
->GetSubmenu()->IsShowing());
1306 // Select the first item in the context menu (open all).
1307 views::MenuItemView
* child_menu
=
1308 menu
->GetSubmenu()->GetMenuItemAt(0);
1309 ASSERT_TRUE(child_menu
!= NULL
);
1311 // Click and wait until the dialog box appears.
1312 scoped_ptr
<DialogWaiter
> dialog_waiter(new DialogWaiter());
1313 ui_test_utils::MoveMouseToCenterAndPress(
1316 ui_controls::DOWN
| ui_controls::UP
,
1318 &BookmarkBarViewTest12::Step4
, this, base::Passed(&dialog_waiter
)));
1321 void Step4(scoped_ptr
<DialogWaiter
> waiter
) {
1322 views::Widget
* dialog
= waiter
->WaitForDialog();
1325 // Press tab to give focus to the cancel button. Wait until the widget
1326 // receives the tab key.
1327 TabKeyWaiter
tab_waiter(dialog
);
1328 ui_controls::SendKeyPress(
1329 window_
->GetNativeWindow(), ui::VKEY_TAB
, false, false, false, false);
1330 tab_waiter
.WaitForTab();
1332 // For some reason return isn't processed correctly unless we delay.
1333 base::MessageLoop::current()->task_runner()->PostDelayedTask(
1334 FROM_HERE
, base::Bind(&BookmarkBarViewTest12::Step5
, this,
1335 base::Unretained(dialog
)),
1336 base::TimeDelta::FromSeconds(1));
1339 void Step5(views::Widget
* dialog
) {
1340 DialogCloseWaiter
waiter(dialog
);
1341 // And press enter so that the cancel button is selected.
1342 ui_controls::SendKeyPressNotifyWhenDone(window_
->GetNativeWindow(),
1349 waiter
.WaitForDialogClose();
1354 // Times out on Win. http://crbug.com/499858
1355 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
1356 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1357 #define MAYBE_CloseWithModalDialog DISABLED_CloseWithModalDialog
1359 #define MAYBE_CloseWithModalDialog CloseWithModalDialog
1362 VIEW_TEST(BookmarkBarViewTest12
, MAYBE_CloseWithModalDialog
)
1364 // Tests clicking on the separator of a context menu (this is for coverage of
1366 class BookmarkBarViewTest13
: public BookmarkBarViewEventTestBase
{
1368 BookmarkBarViewTest13()
1369 : observer_(CreateEventTask(this, &BookmarkBarViewTest13::Step3
)) {
1373 void DoTestOnMessageLoop() override
{
1374 // Move the mouse to the first folder on the bookmark bar and press the
1376 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1377 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1378 ui_controls::DOWN
| ui_controls::UP
,
1379 CreateEventTask(this, &BookmarkBarViewTest13::Step2
));
1384 // Menu should be showing.
1385 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1386 ASSERT_TRUE(menu
!= NULL
);
1387 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1389 views::MenuItemView
* child_menu
=
1390 menu
->GetSubmenu()->GetMenuItemAt(0);
1391 ASSERT_TRUE(child_menu
!= NULL
);
1393 // Right click on the first child to get its context menu.
1394 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1395 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1396 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1400 // Make sure the context menu is showing.
1401 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1402 ASSERT_TRUE(menu
!= NULL
);
1403 ASSERT_TRUE(menu
->GetSubmenu());
1404 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1406 // Find the first separator.
1407 views::SubmenuView
* submenu
= menu
->GetSubmenu();
1408 views::View
* separator_view
= NULL
;
1409 for (int i
= 0; i
< submenu
->child_count(); ++i
) {
1410 if (submenu
->child_at(i
)->id() != views::MenuItemView::kMenuItemViewID
) {
1411 separator_view
= submenu
->child_at(i
);
1415 ASSERT_TRUE(separator_view
);
1417 // Click on the separator. Clicking on the separator shouldn't visually
1419 ui_test_utils::MoveMouseToCenterAndPress(separator_view
,
1420 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1421 CreateEventTask(this, &BookmarkBarViewTest13::Step4
));
1425 // The context menu should still be showing.
1426 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1427 ASSERT_TRUE(menu
!= NULL
);
1428 ASSERT_TRUE(menu
->GetSubmenu());
1429 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1431 // Select the first context menu item.
1432 ui_test_utils::MoveMouseToCenterAndPress(
1433 menu
->GetSubmenu()->GetMenuItemAt(0),
1435 ui_controls::DOWN
| ui_controls::UP
,
1436 CreateEventTask(this, &BookmarkBarViewTest13::Step5
));
1443 BookmarkContextMenuNotificationObserver observer_
;
1446 VIEW_TEST(BookmarkBarViewTest13
, ClickOnContextMenuSeparator
)
1448 // Makes sure right clicking on a folder on the bookmark bar doesn't result in
1449 // both a context menu and showing the menu.
1450 class BookmarkBarViewTest14
: public BookmarkBarViewEventTestBase
{
1452 BookmarkBarViewTest14()
1453 : observer_(CreateEventTask(this, &BookmarkBarViewTest14::Step2
)) {
1457 void DoTestOnMessageLoop() override
{
1458 // Move the mouse to the first folder on the bookmark bar and press the
1459 // right mouse button.
1460 views::LabelButton
* button
= GetBookmarkButton(0);
1461 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::RIGHT
,
1462 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1463 // Step2 will be invoked by BookmarkContextMenuNotificationObserver.
1469 // Menu should NOT be showing.
1470 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1471 ASSERT_TRUE(menu
== NULL
);
1473 // Send escape so that the context menu hides.
1474 ui_controls::SendKeyPressNotifyWhenDone(
1475 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
1476 CreateEventTask(this, &BookmarkBarViewTest14::Step3
));
1483 BookmarkContextMenuNotificationObserver observer_
;
1486 #if defined(USE_OZONE)
1487 // ozone bringup - http://crbug.com/401304
1488 #define MAYBE_ContextMenus2 DISABLED_ContextMenus2
1490 #define MAYBE_ContextMenus2 ContextMenus2
1493 VIEW_TEST(BookmarkBarViewTest14
, MAYBE_ContextMenus2
)
1495 // Makes sure deleting from the context menu keeps the bookmark menu showing.
1496 class BookmarkBarViewTest15
: public BookmarkBarViewEventTestBase
{
1498 BookmarkBarViewTest15()
1499 : deleted_menu_id_(0),
1500 observer_(CreateEventTask(this, &BookmarkBarViewTest15::Step3
)) {
1504 void DoTestOnMessageLoop() override
{
1505 // Show the other bookmarks.
1506 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1507 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1508 ui_controls::DOWN
| ui_controls::UP
,
1509 CreateEventTask(this, &BookmarkBarViewTest15::Step2
));
1514 // Menu should be showing.
1515 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1516 ASSERT_TRUE(menu
!= NULL
);
1517 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1519 views::MenuItemView
* child_menu
=
1520 menu
->GetSubmenu()->GetMenuItemAt(1);
1521 ASSERT_TRUE(child_menu
!= NULL
);
1523 deleted_menu_id_
= child_menu
->GetCommand();
1525 // Right click on the second child to get its context menu.
1526 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1527 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1528 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1532 // Make sure the context menu is showing.
1533 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1534 ASSERT_TRUE(menu
!= NULL
);
1535 ASSERT_TRUE(menu
->GetSubmenu());
1536 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1538 views::MenuItemView
* delete_menu
=
1539 menu
->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE
);
1540 ASSERT_TRUE(delete_menu
);
1542 // Click on the delete button.
1543 ui_test_utils::MoveMouseToCenterAndPress(delete_menu
,
1544 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1545 CreateEventTask(this, &BookmarkBarViewTest15::Step4
));
1549 // The context menu should not be showing.
1550 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1551 ASSERT_TRUE(context_menu
== NULL
);
1553 // But the menu should be showing.
1554 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1555 ASSERT_TRUE(menu
!= NULL
);
1556 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1558 // And the deleted_menu_id_ should have been removed.
1559 ASSERT_TRUE(menu
->GetMenuItemByID(deleted_menu_id_
) == NULL
);
1561 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
1566 int deleted_menu_id_
;
1567 BookmarkContextMenuNotificationObserver observer_
;
1570 VIEW_TEST(BookmarkBarViewTest15
, MenuStaysVisibleAfterDelete
)
1572 // Tests that we don't crash or get stuck if the parent of a menu is closed.
1573 class BookmarkBarViewTest16
: public BookmarkBarViewEventTestBase
{
1575 void DoTestOnMessageLoop() override
{
1576 // Move the mouse to the first folder on the bookmark bar and press the
1578 views::LabelButton
* button
= GetBookmarkButton(0);
1579 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1580 ui_controls::DOWN
| ui_controls::UP
,
1581 CreateEventTask(this, &BookmarkBarViewTest16::Step2
));
1586 // Menu should be showing.
1587 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1588 ASSERT_TRUE(menu
!= NULL
);
1589 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1591 // Button should be depressed.
1592 views::LabelButton
* button
= GetBookmarkButton(0);
1593 ASSERT_TRUE(button
->state() == views::CustomButton::STATE_PRESSED
);
1595 // Close the window.
1599 base::MessageLoop::current()->task_runner()->PostTask(
1600 FROM_HERE
, CreateEventTask(this, &BookmarkBarViewTest16::Done
));
1604 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1605 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1606 #define MAYBE_DeleteMenu DISABLED_DeleteMenu
1608 #define MAYBE_DeleteMenu DeleteMenu
1611 VIEW_TEST(BookmarkBarViewTest16
, MAYBE_DeleteMenu
)
1613 // Makes sure right clicking on an item while a context menu is already showing
1614 // doesn't crash and works.
1615 class BookmarkBarViewTest17
: public BookmarkBarViewEventTestBase
{
1617 BookmarkBarViewTest17()
1618 : observer_(CreateEventTask(this, &BookmarkBarViewTest17::Step3
)) {
1622 void DoTestOnMessageLoop() override
{
1623 // Move the mouse to the other folder on the bookmark bar and press the
1624 // left mouse button.
1625 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1626 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1627 ui_controls::DOWN
| ui_controls::UP
,
1628 CreateEventTask(this, &BookmarkBarViewTest17::Step2
));
1633 // Menu should be showing.
1634 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1635 ASSERT_TRUE(menu
!= NULL
);
1636 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1638 // Right click on the second item to show its context menu.
1639 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(2);
1640 ASSERT_TRUE(child_menu
!= NULL
);
1641 ui_test_utils::MoveMouseToCenterAndPress(child_menu
, ui_controls::RIGHT
,
1642 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1643 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1647 // Make sure the context menu is showing.
1648 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1649 ASSERT_TRUE(context_menu
!= NULL
);
1650 ASSERT_TRUE(context_menu
->GetSubmenu());
1651 ASSERT_TRUE(context_menu
->GetSubmenu()->IsShowing());
1653 // Right click on the first menu item to trigger its context menu.
1654 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1655 ASSERT_TRUE(menu
!= NULL
);
1656 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1657 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1658 ASSERT_TRUE(child_menu
!= NULL
);
1660 // The context menu and child_menu can be overlapped, calculate the
1661 // non-intersected Rect of the child menu and click on its center to make
1662 // sure the click is always on the child menu.
1663 gfx::Rect context_rect
= context_menu
->GetSubmenu()->GetBoundsInScreen();
1664 gfx::Rect child_menu_rect
= child_menu
->GetBoundsInScreen();
1665 gfx::Rect clickable_rect
=
1666 gfx::SubtractRects(child_menu_rect
, context_rect
);
1667 ASSERT_FALSE(clickable_rect
.IsEmpty());
1668 observer_
.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4
));
1669 MoveMouseAndPress(clickable_rect
.CenterPoint(), ui_controls::RIGHT
,
1670 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1671 // Step4 will be invoked by BookmarkContextMenuNotificationObserver.
1675 // The context menu should still be showing.
1676 views::MenuItemView
* context_menu
= bb_view_
->GetContextMenu();
1677 ASSERT_TRUE(context_menu
!= NULL
);
1679 // And the menu should be showing.
1680 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1681 ASSERT_TRUE(menu
!= NULL
);
1682 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1684 bb_view_
->GetMenu()->GetMenuController()->CancelAll();
1689 BookmarkContextMenuNotificationObserver observer_
;
1693 // Flaky on Win7. crbug/453796
1694 #define MAYBE_ContextMenus3 DISABLED_ContextMenus3
1696 #define MAYBE_ContextMenus3 ContextMenus3
1699 VIEW_TEST(BookmarkBarViewTest17
, MAYBE_ContextMenus3
)
1701 // Verifies sibling menus works. Clicks on the 'other bookmarks' folder, then
1702 // moves the mouse over the first item on the bookmark bar and makes sure the
1704 class BookmarkBarViewTest18
: public BookmarkBarViewEventTestBase
{
1706 void DoTestOnMessageLoop() override
{
1707 // Move the mouse to the other folder on the bookmark bar and press the
1708 // left mouse button.
1709 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1710 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1711 ui_controls::DOWN
| ui_controls::UP
,
1712 CreateEventTask(this, &BookmarkBarViewTest18::Step2
));
1717 // Menu should be showing.
1718 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1719 ASSERT_TRUE(menu
!= NULL
);
1720 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1722 // Move the mouse to the first folder on the bookmark bar
1723 views::LabelButton
* button
= GetBookmarkButton(0);
1724 gfx::Point
button_center(button
->width() / 2, button
->height() / 2);
1725 views::View::ConvertPointToScreen(button
, &button_center
);
1726 ui_controls::SendMouseMoveNotifyWhenDone(
1727 button_center
.x(), button_center
.y(),
1728 CreateEventTask(this, &BookmarkBarViewTest18::Step3
));
1732 // Make sure the menu is showing.
1733 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1734 ASSERT_TRUE(menu
!= NULL
);
1735 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1737 // The menu for the first folder should be in the pressed state (since the
1738 // menu is showing for it).
1739 EXPECT_EQ(views::CustomButton::STATE_PRESSED
,
1740 GetBookmarkButton(0)->state());
1742 menu
->GetMenuController()->CancelAll();
1748 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1749 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1750 #define MAYBE_BookmarkBarViewTest18_SiblingMenu \
1751 DISABLED_BookmarkBarViewTest18_SiblingMenu
1753 #define MAYBE_BookmarkBarViewTest18_SiblingMenu \
1754 BookmarkBarViewTest18_SiblingMenu
1757 VIEW_TEST(BookmarkBarViewTest18
, MAYBE_BookmarkBarViewTest18_SiblingMenu
)
1759 // Verifies mousing over an already open sibling menu doesn't prematurely cancel
1761 class BookmarkBarViewTest19
: public BookmarkBarViewEventTestBase
{
1763 void DoTestOnMessageLoop() override
{
1764 // Move the mouse to the other folder on the bookmark bar and press the
1765 // left mouse button.
1766 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1767 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1768 ui_controls::DOWN
| ui_controls::UP
,
1769 CreateEventTask(this, &BookmarkBarViewTest19::Step2
));
1774 // Menu should be showing.
1775 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1776 ASSERT_TRUE(menu
!= NULL
);
1777 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1779 // Click on the first folder.
1780 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1781 ASSERT_TRUE(child_menu
!= NULL
);
1782 ui_test_utils::MoveMouseToCenterAndPress(
1783 child_menu
, ui_controls::LEFT
,
1784 ui_controls::DOWN
| ui_controls::UP
,
1785 CreateEventTask(this, &BookmarkBarViewTest19::Step3
));
1789 // Make sure the menu is showing.
1790 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1791 ASSERT_TRUE(menu
!= NULL
);
1792 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1794 // Move the mouse back to the "Other Bookmarks" button.
1795 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
1796 gfx::Point
button_center(button
->width() / 2, button
->height() / 2);
1797 views::View::ConvertPointToScreen(button
, &button_center
);
1798 ui_controls::SendMouseMoveNotifyWhenDone(
1799 button_center
.x() + 1, button_center
.y() + 1,
1800 CreateEventTask(this, &BookmarkBarViewTest19::Step4
));
1804 // Menu should be showing.
1805 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1806 ASSERT_TRUE(menu
!= NULL
);
1807 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1809 // Click on the first folder.
1810 views::MenuItemView
* child_menu
= menu
->GetSubmenu()->GetMenuItemAt(1);
1811 ASSERT_TRUE(child_menu
!= NULL
);
1812 ui_test_utils::MoveMouseToCenterAndPress(
1815 ui_controls::DOWN
| ui_controls::UP
,
1816 CreateEventTask(this, &BookmarkBarViewTest19::Step5
));
1820 // Make sure the menu is showing.
1821 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1822 ASSERT_TRUE(menu
!= NULL
);
1823 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1825 menu
->GetMenuController()->CancelAll();
1831 VIEW_TEST(BookmarkBarViewTest19
, BookmarkBarViewTest19_SiblingMenu
)
1833 // Verify that when clicking a mouse button outside a context menu,
1834 // the context menu is dismissed *and* the underlying view receives
1835 // the the mouse event (due to event reposting).
1836 class BookmarkBarViewTest20
: public BookmarkBarViewEventTestBase
{
1838 BookmarkBarViewTest20() : test_view_(new TestViewForMenuExit
) {}
1841 void DoTestOnMessageLoop() override
{
1842 // Add |test_view_| next to |bb_view_|.
1843 views::View
* parent
= bb_view_
->parent();
1844 views::View
* container_view
= new ContainerViewForMenuExit
;
1845 container_view
->AddChildView(bb_view_
.get());
1846 container_view
->AddChildView(test_view_
);
1847 parent
->AddChildView(container_view
);
1850 ASSERT_EQ(test_view_
->press_count(), 0);
1852 // Move the mouse to the Test View and press the left mouse button.
1853 ui_test_utils::MoveMouseToCenterAndPress(
1854 test_view_
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1855 CreateEventTask(this, &BookmarkBarViewTest20::Step1
));
1860 ASSERT_EQ(test_view_
->press_count(), 1);
1861 ASSERT_TRUE(bb_view_
->GetMenu() == NULL
);
1863 // Move the mouse to the first folder on the bookmark bar and press the
1864 // left mouse button.
1865 views::LabelButton
* button
= GetBookmarkButton(0);
1866 ui_test_utils::MoveMouseToCenterAndPress(
1867 button
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1868 CreateEventTask(this, &BookmarkBarViewTest20::Step2
));
1872 ASSERT_EQ(test_view_
->press_count(), 1);
1873 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1874 ASSERT_TRUE(menu
!= NULL
);
1875 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1877 // Move the mouse to the Test View and press the left mouse button.
1878 // The context menu will consume the event and exit. Thereafter,
1879 // the event is reposted and delivered to the Test View which
1880 // increases its press-count.
1881 ui_test_utils::MoveMouseToCenterAndPress(
1882 test_view_
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1883 CreateEventTask(this, &BookmarkBarViewTest20::Step3
));
1887 ASSERT_EQ(test_view_
->press_count(), 2);
1888 ASSERT_TRUE(bb_view_
->GetMenu() == NULL
);
1892 class ContainerViewForMenuExit
: public views::View
{
1894 ContainerViewForMenuExit() {
1897 void Layout() override
{
1898 DCHECK_EQ(2, child_count());
1899 views::View
* bb_view
= child_at(0);
1900 views::View
* test_view
= child_at(1);
1901 const int width
= bb_view
->width();
1902 const int height
= bb_view
->height();
1903 bb_view
->SetBounds(0,0, width
- 22, height
);
1904 test_view
->SetBounds(width
- 20, 0, 20, height
);
1909 DISALLOW_COPY_AND_ASSIGN(ContainerViewForMenuExit
);
1912 class TestViewForMenuExit
: public views::View
{
1914 TestViewForMenuExit() : press_count_(0) {
1916 bool OnMousePressed(const ui::MouseEvent
& event
) override
{
1920 int press_count() const { return press_count_
; }
1925 DISALLOW_COPY_AND_ASSIGN(TestViewForMenuExit
);
1928 TestViewForMenuExit
* test_view_
;
1931 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1932 // TODO(erg): linux_aura bringup: http://crbug.com/163931
1933 #define MAYBE_ContextMenuExitTest DISABLED_ContextMenuExitTest
1935 #define MAYBE_ContextMenuExitTest ContextMenuExitTest
1938 VIEW_TEST(BookmarkBarViewTest20
, MAYBE_ContextMenuExitTest
)
1940 // Tests context menu by way of opening a context menu for a empty folder menu.
1941 // The opened context menu should behave as it is from the folder button.
1942 class BookmarkBarViewTest21
: public BookmarkBarViewEventTestBase
{
1944 BookmarkBarViewTest21()
1945 : observer_(CreateEventTask(this, &BookmarkBarViewTest21::Step3
)) {
1949 // Move the mouse to the empty folder on the bookmark bar and press the
1950 // left mouse button.
1951 void DoTestOnMessageLoop() override
{
1952 views::LabelButton
* button
= GetBookmarkButton(5);
1953 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
1954 ui_controls::DOWN
| ui_controls::UP
,
1955 CreateEventTask(this, &BookmarkBarViewTest21::Step2
));
1959 // Confirm that a menu for empty folder shows and right click the menu.
1961 // Menu should be showing.
1962 views::MenuItemView
* menu
= bb_view_
->GetMenu();
1963 ASSERT_TRUE(menu
!= NULL
);
1965 views::SubmenuView
* submenu
= menu
->GetSubmenu();
1966 ASSERT_TRUE(submenu
->IsShowing());
1967 ASSERT_EQ(1, submenu
->child_count());
1969 views::View
* view
= submenu
->child_at(0);
1970 ASSERT_TRUE(view
!= NULL
);
1971 EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID
, view
->id());
1973 // Right click on the first child to get its context menu.
1974 ui_test_utils::MoveMouseToCenterAndPress(view
, ui_controls::RIGHT
,
1975 ui_controls::DOWN
| ui_controls::UP
, base::Closure());
1976 // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
1979 // Confirm that context menu shows and click REMOVE menu.
1981 // Make sure the context menu is showing.
1982 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
1983 ASSERT_TRUE(menu
!= NULL
);
1984 ASSERT_TRUE(menu
->GetSubmenu());
1985 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
1987 views::MenuItemView
* delete_menu
=
1988 menu
->GetMenuItemByID(IDC_BOOKMARK_BAR_REMOVE
);
1989 ASSERT_TRUE(delete_menu
);
1991 // Click on the delete menu item.
1992 ui_test_utils::MoveMouseToCenterAndPress(delete_menu
,
1993 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
1994 CreateEventTask(this, &BookmarkBarViewTest21::Step4
));
1997 // Confirm that the empty folder gets removed and menu doesn't show.
1999 views::LabelButton
* button
= GetBookmarkButton(5);
2000 ASSERT_TRUE(button
);
2001 EXPECT_EQ(ASCIIToUTF16("d"), button
->GetText());
2002 EXPECT_TRUE(bb_view_
->GetContextMenu() == NULL
);
2003 EXPECT_TRUE(bb_view_
->GetMenu() == NULL
);
2008 BookmarkContextMenuNotificationObserver observer_
;
2011 #if defined(OS_WIN) // flaky http://crbug.com/523255
2012 #define MAYBE_ContextMenusForEmptyFolder DISABLED_ContextMenusForEmptyFolder
2014 #define MAYBE_ContextMenusForEmptyFolder ContextMenusForEmptyFolder
2016 VIEW_TEST(BookmarkBarViewTest21
, MAYBE_ContextMenusForEmptyFolder
)
2018 // Test that closing the source browser window while dragging a bookmark does
2019 // not cause a crash.
2020 class BookmarkBarViewTest22
: public BookmarkBarViewEventTestBase
{
2022 void DoTestOnMessageLoop() override
{
2023 // Move the mouse to the first folder on the bookmark bar and press the
2025 views::LabelButton
* button
= GetBookmarkButton(0);
2026 ui_test_utils::MoveMouseToCenterAndPress(
2027 button
, ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
2028 CreateEventTask(this, &BookmarkBarViewTest22::Step2
));
2033 // Menu should be showing.
2034 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2036 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2038 views::MenuItemView
* child_menu
=
2039 menu
->GetSubmenu()->GetMenuItemAt(0);
2040 ASSERT_TRUE(child_menu
!= NULL
);
2042 // Move mouse to center of menu and press button.
2043 ui_test_utils::MoveMouseToCenterAndPress(
2044 child_menu
, ui_controls::LEFT
, ui_controls::DOWN
,
2045 CreateEventTask(this, &BookmarkBarViewTest22::Step3
));
2049 views::MenuItemView
* target_menu
=
2050 bb_view_
->GetMenu()->GetSubmenu()->GetMenuItemAt(1);
2051 gfx::Point
loc(1, target_menu
->height() - 1);
2052 views::View::ConvertPointToScreen(target_menu
, &loc
);
2055 ui_controls::SendMouseMoveNotifyWhenDone(loc
.x() + 10, loc
.y(),
2056 CreateEventTask(this, &BookmarkBarViewTest22::Step4
));
2057 ScheduleMouseMoveInBackground(loc
.x(), loc
.y());
2064 #if defined(OS_CHROMEOS)
2065 ui_controls::SendMouseEventsNotifyWhenDone(
2066 ui_controls::LEFT
, ui_controls::UP
,
2067 CreateEventTask(this, &BookmarkBarViewTest22::Done
));
2069 // There are no widgets to send the mouse release to.
2076 // This test times out on Windows. TODO(pkotwicz): Find out why.
2077 #define MAYBE_CloseSourceBrowserDuringDrag DISABLED_CloseSourceBrowserDuringDrag
2079 #define MAYBE_CloseSourceBrowserDuringDrag CloseSourceBrowserDuringDrag
2082 VIEW_TEST(BookmarkBarViewTest22
, MAYBE_CloseSourceBrowserDuringDrag
)
2084 // Tests opening a context menu for a bookmark node from the keyboard.
2085 class BookmarkBarViewTest23
: public BookmarkBarViewEventTestBase
{
2087 BookmarkBarViewTest23()
2088 : observer_(CreateEventTask(this, &BookmarkBarViewTest23::Step4
)) {
2092 void DoTestOnMessageLoop() override
{
2093 // Move the mouse to the first folder on the bookmark bar and press the
2095 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
2096 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
2097 ui_controls::DOWN
| ui_controls::UP
,
2098 CreateEventTask(this, &BookmarkBarViewTest23::Step2
));
2103 // Menu should be showing.
2104 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2106 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2108 // Navigate down to highlight the first menu item.
2109 ui_controls::SendKeyPressNotifyWhenDone(
2110 GetWidget()->GetNativeWindow(), ui::VKEY_DOWN
,
2111 false, false, false, false, // No modifer keys
2112 CreateEventTask(this, &BookmarkBarViewTest23::Step3
));
2116 // Menu should be showing.
2117 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2119 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2121 // Open the context menu via the keyboard.
2122 ui_controls::SendKeyPress(
2123 GetWidget()->GetNativeWindow(), ui::VKEY_APPS
,
2124 false, false, false, false); // No modifer keys
2125 // The BookmarkContextMenuNotificationObserver triggers Step4.
2129 // Make sure the context menu is showing.
2130 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
2132 ASSERT_TRUE(menu
->GetSubmenu());
2133 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2135 // Select the first menu item (open).
2136 ui_test_utils::MoveMouseToCenterAndPress(
2137 menu
->GetSubmenu()->GetMenuItemAt(0),
2138 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
,
2139 CreateEventTask(this, &BookmarkBarViewTest23::Step5
));
2143 EXPECT_EQ(navigator_
.url_
, model_
->other_node()->GetChild(0)->url());
2147 BookmarkContextMenuNotificationObserver observer_
;
2150 #if defined(USE_OZONE)
2151 // ozone bringup - http://crbug.com/401304
2152 #define MAYBE_ContextMenusKeyboard DISABLED_ContextMenusKeyboard
2154 #define MAYBE_ContextMenusKeyboard ContextMenusKeyboard
2156 VIEW_TEST(BookmarkBarViewTest23
, MAYBE_ContextMenusKeyboard
)
2158 // Test that pressing escape on a menu opened via the keyboard dismisses the
2159 // context menu but not the parent menu.
2160 class BookmarkBarViewTest24
: public BookmarkBarViewEventTestBase
{
2162 BookmarkBarViewTest24()
2163 : observer_(CreateEventTask(this, &BookmarkBarViewTest24::Step4
)) {}
2166 void DoTestOnMessageLoop() override
{
2167 // Move the mouse to the first folder on the bookmark bar and press the
2169 views::LabelButton
* button
= bb_view_
->other_bookmarks_button();
2170 ui_test_utils::MoveMouseToCenterAndPress(button
, ui_controls::LEFT
,
2171 ui_controls::DOWN
| ui_controls::UP
,
2172 CreateEventTask(this, &BookmarkBarViewTest24::Step2
));
2177 // Menu should be showing.
2178 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2180 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2182 // Navigate down to highlight the first menu item.
2183 ui_controls::SendKeyPressNotifyWhenDone(
2184 GetWidget()->GetNativeWindow(), ui::VKEY_DOWN
,
2185 false, false, false, false, // No modifer keys
2186 CreateEventTask(this, &BookmarkBarViewTest24::Step3
));
2190 // Menu should be showing.
2191 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2193 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2195 // Open the context menu via the keyboard.
2196 ui_controls::SendKeyPress(
2197 GetWidget()->GetNativeWindow(), ui::VKEY_APPS
,
2198 false, false, false, false); // No modifer keys
2199 // The BookmarkContextMenuNotificationObserver triggers Step4.
2203 // Make sure the context menu is showing.
2204 views::MenuItemView
* menu
= bb_view_
->GetContextMenu();
2206 ASSERT_TRUE(menu
->GetSubmenu());
2207 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2209 // Send escape to close the context menu.
2210 ui_controls::SendKeyPressNotifyWhenDone(
2211 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
2212 CreateEventTask(this, &BookmarkBarViewTest24::Step5
));
2216 // The context menu should be closed but the parent menu should still be
2218 ASSERT_FALSE(bb_view_
->GetContextMenu());
2220 views::MenuItemView
* menu
= bb_view_
->GetMenu();
2222 ASSERT_TRUE(menu
->GetSubmenu()->IsShowing());
2224 // Send escape to close the main menu.
2225 ui_controls::SendKeyPressNotifyWhenDone(
2226 window_
->GetNativeWindow(), ui::VKEY_ESCAPE
, false, false, false, false,
2227 CreateEventTask(this, &BookmarkBarViewTest24::Done
));
2230 BookmarkContextMenuNotificationObserver observer_
;
2233 #if defined(USE_OZONE)
2234 // ozone bringup - http://crbug.com/401304
2235 #define MAYBE_ContextMenusKeyboardEscape DISABLED_ContextMenusKeyboardEscape
2237 #define MAYBE_ContextMenusKeyboardEscape ContextMenusKeyboardEscape
2239 VIEW_TEST(BookmarkBarViewTest24
, MAYBE_ContextMenusKeyboardEscape
)