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

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

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add basic tests Created 4 years, 7 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"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ui/base/dragdrop/drag_drop_types.h" 12 #include "ui/base/dragdrop/drag_drop_types.h"
13 #include "ui/events/test/event_generator.h" 13 #include "ui/events/test/event_generator.h"
14 #include "ui/views/animation/test/test_ink_drop_delegate.h" 14 #include "ui/views/animation/test/test_ink_drop_delegate.h"
15 #include "ui/views/controls/button/menu_button_listener.h" 15 #include "ui/views/controls/button/menu_button_listener.h"
16 #include "ui/views/controls/focusable_border.h"
16 #include "ui/views/drag_controller.h" 17 #include "ui/views/drag_controller.h"
18 #include "ui/views/style/platform_style.h"
17 #include "ui/views/test/views_test_base.h" 19 #include "ui/views/test/views_test_base.h"
18 20
19 #if defined(USE_AURA) 21 #if defined(USE_AURA)
20 #include "ui/events/event.h" 22 #include "ui/events/event.h"
21 #include "ui/events/event_handler.h" 23 #include "ui/events/event_handler.h"
22 #include "ui/wm/public/drag_drop_client.h" 24 #include "ui/wm/public/drag_drop_client.h"
23 #endif 25 #endif
24 26
25 using base::ASCIIToUTF16; 27 using base::ASCIIToUTF16;
26 28
27 namespace views { 29 namespace views {
28 class InkDropDelegate; 30 class InkDropDelegate;
29 31
30 namespace test { 32 namespace test {
31 33
32 // A MenuButton subclass that provides access to some MenuButton internals. 34 // A MenuButton subclass that provides access to some MenuButton internals.
33 class TestMenuButton : public MenuButton { 35 class TestMenuButton : public MenuButton {
34 public: 36 public:
35 explicit TestMenuButton(MenuButtonListener* menu_button_listener) 37 TestMenuButton(MenuButtonListener* menu_button_listener,
38 bool use_background,
tapted 2016/05/09 08:01:35 I don't think we need to pass in these arguments -
39 bool use_border)
36 : MenuButton(base::string16(ASCIIToUTF16("button")), 40 : MenuButton(base::string16(ASCIIToUTF16("button")),
37 menu_button_listener, 41 menu_button_listener,
38 false) {} 42 false),
43 use_background_(use_background),
44 use_border_(use_border) {}
39 45
40 ~TestMenuButton() override {} 46 ~TestMenuButton() override {}
41 47
48 // Overrides for MenuButton customization methods.
tapted 2016/05/09 08:01:35 nit: just // MenuButton:
49 bool ShouldUsePlatformStyleBackground() const override {
50 return use_background_;
51 }
52
53 bool ShouldUsePlatformStyleBorder() const override { return use_border_; }
54
42 // Accessors to protected MenuButton methods. 55 // Accessors to protected MenuButton methods.
43 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { 56 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) {
44 MenuButton::set_ink_drop_delegate(ink_drop_delegate); 57 MenuButton::set_ink_drop_delegate(ink_drop_delegate);
45 } 58 }
46 59
47 private: 60 private:
61 bool use_background_;
62 bool use_border_;
48 DISALLOW_COPY_AND_ASSIGN(TestMenuButton); 63 DISALLOW_COPY_AND_ASSIGN(TestMenuButton);
tapted 2016/05/09 08:01:35 nit: blank line before
49 }; 64 };
50 65
51 class MenuButtonTest : public ViewsTestBase { 66 class MenuButtonTest : public ViewsTestBase {
52 public: 67 public:
53 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} 68 MenuButtonTest() : widget_(nullptr), button_(nullptr) {}
54 ~MenuButtonTest() override {} 69 ~MenuButtonTest() override {}
55 70
56 void TearDown() override { 71 void TearDown() override {
57 generator_.reset(); 72 generator_.reset();
58 if (widget_ && !widget_->IsClosed()) 73 if (widget_ && !widget_->IsClosed())
59 widget_->Close(); 74 widget_->Close();
60 75
61 ViewsTestBase::TearDown(); 76 ViewsTestBase::TearDown();
62 } 77 }
63 78
64 Widget* widget() { return widget_; } 79 Widget* widget() { return widget_; }
65 TestMenuButton* button() { return button_; } 80 TestMenuButton* button() { return button_; }
66 ui::test::EventGenerator* generator() { return generator_.get(); } 81 ui::test::EventGenerator* generator() { return generator_.get(); }
67 82
68 protected: 83 protected:
69 // Creates a MenuButton with no button listener. 84 // Creates a MenuButton with no button listener.
70 void CreateMenuButtonWithNoListener() { CreateMenuButton(nullptr); } 85 void CreateMenuButtonWithNoListener(bool use_background = false,
86 bool use_border = false) {
87 CreateMenuButton(nullptr, use_background, use_border);
88 }
71 89
72 // Creates a MenuButton with a MenuButtonListener. In this case, when the 90 // Creates a MenuButton with a MenuButtonListener. In this case, when the
73 // MenuButton is pushed, it notifies the MenuButtonListener to open a 91 // MenuButton is pushed, it notifies the MenuButtonListener to open a
74 // drop-down menu. 92 // drop-down menu.
75 void CreateMenuButtonWithMenuButtonListener( 93 void CreateMenuButtonWithMenuButtonListener(
76 MenuButtonListener* menu_button_listener) { 94 MenuButtonListener* menu_button_listener,
77 CreateMenuButton(menu_button_listener); 95 bool use_background = false,
96 bool use_border = false) {
97 CreateMenuButton(menu_button_listener, use_background, use_border);
78 } 98 }
79 99
80 private: 100 private:
81 void CreateMenuButton(MenuButtonListener* menu_button_listener) { 101 void CreateMenuButton(MenuButtonListener* menu_button_listener,
102 bool use_background,
103 bool use_border) {
82 CreateWidget(); 104 CreateWidget();
83 generator_.reset(new ui::test::EventGenerator(GetContext(), 105 generator_.reset(new ui::test::EventGenerator(GetContext(),
84 widget_->GetNativeWindow())); 106 widget_->GetNativeWindow()));
85 // Set initial mouse location in a consistent way so that the menu button we 107 // Set initial mouse location in a consistent way so that the menu button we
86 // are about to create initializes its hover state in a consistent manner. 108 // are about to create initializes its hover state in a consistent manner.
87 generator_->set_current_location(gfx::Point(10, 10)); 109 generator_->set_current_location(gfx::Point(10, 10));
88 110
89 button_ = new TestMenuButton(menu_button_listener); 111 button_ =
112 new TestMenuButton(menu_button_listener, use_background, use_border);
90 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); 113 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20));
91 widget_->SetContentsView(button_); 114 widget_->SetContentsView(button_);
92 115
93 widget_->Show(); 116 widget_->Show();
94 } 117 }
95 118
96 void CreateWidget() { 119 void CreateWidget() {
97 DCHECK(!widget_); 120 DCHECK(!widget_);
98 121
99 widget_ = new Widget; 122 widget_ = new Widget;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 625 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
603 626
604 generator()->MoveTouch(gfx::Point(10, 30)); 627 generator()->MoveTouch(gfx::Point(10, 30));
605 generator()->ReleaseTouch(); 628 generator()->ReleaseTouch();
606 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 629 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
607 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 630 EXPECT_EQ(nullptr, menu_button_listener.last_source());
608 } 631 }
609 632
610 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 633 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
611 634
635 TEST_F(MenuButtonTest, UseBorderDoesApplyBorder) {
tapted 2016/05/09 08:01:35 tests should have a comment describing why they ex
636 CreateMenuButtonWithNoListener(false, true);
637 if (PlatformStyle::CreateMenuButtonBorder())
tapted 2016/05/09 08:01:35 I think it would be better to #if defined(platform
638 EXPECT_TRUE(button()->border());
639 }
tapted 2016/05/09 08:01:35 we also need to test something that calls SetBorde
640
641 TEST_F(MenuButtonTest, UseBackgroundDoesApplyBackground) {
642 CreateMenuButtonWithNoListener(true, false);
643 if (PlatformStyle::CreateMenuButtonBackground(10))
644 EXPECT_TRUE(button()->background());
645 }
646
612 } // namespace views 647 } // namespace views
613 } // namespace test 648 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698