OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
12 #include "ui/display/screen.h" | 12 #include "ui/display/screen.h" |
13 #include "ui/events/event_utils.h" | 13 #include "ui/events/event_utils.h" |
14 #include "ui/events/test/event_generator.h" | 14 #include "ui/events/test/event_generator.h" |
15 #include "ui/views/animation/ink_drop_host.h" | 15 #include "ui/views/animation/ink_drop_host.h" |
16 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" | 16 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
17 #include "ui/views/animation/test/test_ink_drop.h" | 17 #include "ui/views/animation/test/test_ink_drop.h" |
18 #include "ui/views/animation/test/test_ink_drop_host.h" | 18 #include "ui/views/animation/test/test_ink_drop_host.h" |
19 #include "ui/views/context_menu_controller.h" | 19 #include "ui/views/context_menu_controller.h" |
20 #include "ui/views/controls/button/checkbox.h" | 20 #include "ui/views/controls/button/checkbox.h" |
21 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
22 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
23 #include "ui/views/controls/button/menu_button.h" | 23 #include "ui/views/controls/button/menu_button.h" |
24 #include "ui/views/controls/button/radio_button.h" | 24 #include "ui/views/controls/button/radio_button.h" |
| 25 #include "ui/views/controls/button/toggle_button.h" |
25 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
27 #include "ui/views/test/views_test_base.h" | 28 #include "ui/views/test/views_test_base.h" |
28 | 29 |
29 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
30 #include "ui/aura/test/test_cursor_client.h" | 31 #include "ui/aura/test/test_cursor_client.h" |
31 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
32 #include "ui/aura/window_event_dispatcher.h" | 33 #include "ui/aura/window_event_dispatcher.h" |
33 #endif | 34 #endif |
34 | 35 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 Widget* widget() { return widget_.get(); } | 130 Widget* widget() { return widget_.get(); } |
130 TestCustomButton* button() { return button_; } | 131 TestCustomButton* button() { return button_; } |
131 void SetDraggedView(View* dragged_view) { | 132 void SetDraggedView(View* dragged_view) { |
132 widget_->dragged_view_ = dragged_view; | 133 widget_->dragged_view_ = dragged_view; |
133 } | 134 } |
134 | 135 |
135 void SimulateKeyEvent(ui::KeyEvent* event) { widget()->OnKeyEvent(event); } | 136 void SimulateKeyEvent(ui::KeyEvent* event) { widget()->OnKeyEvent(event); } |
136 | 137 |
137 private: | 138 private: |
138 std::unique_ptr<Widget> widget_; | 139 std::unique_ptr<Widget> widget_; |
139 TestCustomButton* button_; | 140 TestCustomButton* button_ = nullptr; |
140 | 141 |
141 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); | 142 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); |
142 }; | 143 }; |
143 | 144 |
144 // Tests that hover state changes correctly when visiblity/enableness changes. | 145 // Tests that hover state changes correctly when visiblity/enableness changes. |
145 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { | 146 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { |
146 ui::test::EventGenerator generator(widget()->GetNativeWindow()); | 147 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
147 | 148 |
148 generator.PressLeftButton(); | 149 generator.PressLeftButton(); |
149 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 150 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 329 |
329 Checkbox checkbox(text); | 330 Checkbox checkbox(text); |
330 EXPECT_TRUE(CustomButton::AsCustomButton(&checkbox)); | 331 EXPECT_TRUE(CustomButton::AsCustomButton(&checkbox)); |
331 | 332 |
332 RadioButton radio_button(text, 0); | 333 RadioButton radio_button(text, 0); |
333 EXPECT_TRUE(CustomButton::AsCustomButton(&radio_button)); | 334 EXPECT_TRUE(CustomButton::AsCustomButton(&radio_button)); |
334 | 335 |
335 MenuButton menu_button(text, NULL, false); | 336 MenuButton menu_button(text, NULL, false); |
336 EXPECT_TRUE(CustomButton::AsCustomButton(&menu_button)); | 337 EXPECT_TRUE(CustomButton::AsCustomButton(&menu_button)); |
337 | 338 |
| 339 ToggleButton toggle_button(NULL); |
| 340 EXPECT_TRUE(CustomButton::AsCustomButton(&toggle_button)); |
| 341 |
338 Label label; | 342 Label label; |
339 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); | 343 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); |
340 | 344 |
341 Link link(text); | 345 Link link(text); |
342 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); | 346 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); |
343 | 347 |
344 Textfield textfield; | 348 Textfield textfield; |
345 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); | 349 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); |
346 } | 350 } |
347 | 351 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 585 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
582 EXPECT_FALSE(button()->pressed()); | 586 EXPECT_FALSE(button()->pressed()); |
583 | 587 |
584 ui::KeyEvent space_release(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE); | 588 ui::KeyEvent space_release(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE); |
585 SimulateKeyEvent(&space_release); | 589 SimulateKeyEvent(&space_release); |
586 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 590 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
587 EXPECT_TRUE(button()->pressed()); | 591 EXPECT_TRUE(button()->pressed()); |
588 } | 592 } |
589 | 593 |
590 } // namespace views | 594 } // namespace views |
OLD | NEW |