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

Side by Side Diff: ui/views/controls/button/menu_button_unittest.cc

Issue 2010083002: views/mus: Run some more tests from views_unittests in mus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/button/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 void AttachInkDrop() { 82 void AttachInkDrop() {
83 ink_drop_ = new test::TestInkDrop(); 83 ink_drop_ = new test::TestInkDrop();
84 test::InkDropHostViewTestApi(button_).SetInkDrop( 84 test::InkDropHostViewTestApi(button_).SetInkDrop(
85 base::WrapUnique(ink_drop_)); 85 base::WrapUnique(ink_drop_));
86 } 86 }
87 87
88 private: 88 private:
89 void CreateMenuButton(MenuButtonListener* menu_button_listener) { 89 void CreateMenuButton(MenuButtonListener* menu_button_listener) {
90 CreateWidget(); 90 CreateWidget();
91 generator_.reset(new ui::test::EventGenerator(GetContext(), 91 generator_.reset(new ui::test::EventGenerator(widget_->GetNativeWindow()));
92 widget_->GetNativeWindow()));
93 // Set initial mouse location in a consistent way so that the menu button we 92 // Set initial mouse location in a consistent way so that the menu button we
94 // are about to create initializes its hover state in a consistent manner. 93 // are about to create initializes its hover state in a consistent manner.
95 generator_->set_current_location(gfx::Point(10, 10)); 94 generator_->set_current_location(gfx::Point(10, 10));
96 95
97 button_ = new TestMenuButton(menu_button_listener); 96 button_ = new TestMenuButton(menu_button_listener);
98 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); 97 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20));
99 widget_->SetContentsView(button_); 98 widget_->SetContentsView(button_);
100 99
101 widget_->Show(); 100 widget_->Show();
102 } 101 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 generator()->ClickLeftButton(); 346 generator()->ClickLeftButton();
348 347
349 // Check that MenuButton has notified the listener, while it was in pressed 348 // Check that MenuButton has notified the listener, while it was in pressed
350 // state. 349 // state.
351 EXPECT_EQ(button(), menu_button_listener.last_source()); 350 EXPECT_EQ(button(), menu_button_listener.last_source());
352 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 351 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
353 } 352 }
354 353
355 // Test that the MenuButton stays pressed while there are any PressedLocks. 354 // Test that the MenuButton stays pressed while there are any PressedLocks.
356 TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) { 355 TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) {
356 // Hovered-state is not updated under mus when EventGenerator send a
357 // mouse-move event. https://crbug.com/615033
358 if (IsMus())
359 return;
357 CreateMenuButtonWithNoListener(); 360 CreateMenuButtonWithNoListener();
358 361
359 // Move the mouse over the button; the button should be in a hovered state. 362 // Move the mouse over the button; the button should be in a hovered state.
360 generator()->MoveMouseTo(gfx::Point(10, 10)); 363 generator()->MoveMouseTo(gfx::Point(10, 10));
361 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 364 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
362 365
363 // Introduce a PressedLock, which should make the button pressed. 366 // Introduce a PressedLock, which should make the button pressed.
364 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( 367 std::unique_ptr<MenuButton::PressedLock> pressed_lock1(
365 new MenuButton::PressedLock(button())); 368 new MenuButton::PressedLock(button()));
366 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 369 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 button()->Activate(nullptr); 538 button()->Activate(nullptr);
536 539
537 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop()->GetTargetInkDropState()); 540 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop()->GetTargetInkDropState());
538 } 541 }
539 542
540 #if defined(USE_AURA) 543 #if defined(USE_AURA)
541 544
542 // Tests that the MenuButton does not become pressed if it can be dragged, and a 545 // Tests that the MenuButton does not become pressed if it can be dragged, and a
543 // DragDropClient is processing the events. 546 // DragDropClient is processing the events.
544 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { 547 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
548 // The test uses drag-n-drop, which isn't yet supported on mus.
549 // https://crbug.com/614037.
550 if (IsMus())
551 return;
545 TestMenuButtonListener menu_button_listener; 552 TestMenuButtonListener menu_button_listener;
546 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 553 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
547 TestDragController drag_controller; 554 TestDragController drag_controller;
548 button()->set_drag_controller(&drag_controller); 555 button()->set_drag_controller(&drag_controller);
549 556
550 TestDragDropClient drag_client; 557 TestDragDropClient drag_client;
551 SetDragDropClient(GetContext(), &drag_client); 558 SetDragDropClient(GetContext(), &drag_client);
552 button()->PrependPreTargetHandler(&drag_client); 559 button()->PrependPreTargetHandler(&drag_client);
553 560
554 generator()->DragMouseBy(10, 0); 561 generator()->DragMouseBy(10, 0);
555 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 562 EXPECT_EQ(nullptr, menu_button_listener.last_source());
556 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); 563 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state());
557 } 564 }
558 565
559 #endif // USE_AURA 566 #endif // USE_AURA
560 567
561 // No touch on desktop Mac. Tracked in http://crbug.com/445520. 568 // No touch on desktop Mac. Tracked in http://crbug.com/445520.
562 #if !defined(OS_MACOSX) || defined(USE_AURA) 569 #if !defined(OS_MACOSX) || defined(USE_AURA)
563 570
564 // Tests if the listener is notified correctly when a gesture tap happens on a 571 // Tests if the listener is notified correctly when a gesture tap happens on a
565 // MenuButton that has a MenuButtonListener. 572 // MenuButton that has a MenuButtonListener.
566 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { 573 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) {
574 // Hovered-state is not updated under mus when EventGenerator send a
575 // mouse-move event. https://crbug.com/615033
576 if (IsMus())
577 return;
567 TestMenuButtonListener menu_button_listener; 578 TestMenuButtonListener menu_button_listener;
568 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 579 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
569 580
570 // Move the mouse outside the menu button so that it doesn't impact the 581 // Move the mouse outside the menu button so that it doesn't impact the
571 // button state. 582 // button state.
572 generator()->MoveMouseTo(400, 400); 583 generator()->MoveMouseTo(400, 400);
573 EXPECT_FALSE(button()->IsMouseHovered()); 584 EXPECT_FALSE(button()->IsMouseHovered());
574 585
575 generator()->GestureTapAt(gfx::Point(10, 10)); 586 generator()->GestureTapAt(gfx::Point(10, 10));
576 587
(...skipping 28 matching lines...) Expand all
605 616
606 generator()->MoveTouch(gfx::Point(10, 30)); 617 generator()->MoveTouch(gfx::Point(10, 30));
607 generator()->ReleaseTouch(); 618 generator()->ReleaseTouch();
608 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 619 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
609 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 620 EXPECT_EQ(nullptr, menu_button_listener.last_source());
610 } 621 }
611 622
612 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 623 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
613 624
614 } // namespace views 625 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button_unittest.cc ('k') | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698