Index: ui/views/controls/button/custom_button_unittest.cc |
diff --git a/ui/views/controls/button/custom_button_unittest.cc b/ui/views/controls/button/custom_button_unittest.cc |
index e6e2ffc269aacdb3cf8cf7e16c0e7f7f31821558..441dba71fd4659db70ea780125aa533ccca7788f 100644 |
--- a/ui/views/controls/button/custom_button_unittest.cc |
+++ b/ui/views/controls/button/custom_button_unittest.cc |
@@ -49,6 +49,19 @@ class TestCustomButton : public CustomButton, public ButtonListener { |
DISALLOW_COPY_AND_ASSIGN(TestCustomButton); |
}; |
+class TestWidget : public Widget { |
+ public: |
+ TestWidget() : Widget() {} |
+ |
+ bool IsActive() const override { return active_; } |
sky
2015/11/12 23:42:57
nit: generally we prefix overrides with what class
|
+ void set_active(bool active) { active_ = active; } |
+ |
+ private: |
+ bool active_ = false; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestWidget); |
+}; |
+ |
class CustomButtonTest : public ViewsTestBase { |
public: |
CustomButtonTest() {} |
@@ -59,7 +72,7 @@ class CustomButtonTest : public ViewsTestBase { |
// Create a widget so that the CustomButton can query the hover state |
// correctly. |
- widget_.reset(new Widget); |
+ widget_.reset(new TestWidget); |
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
params.bounds = gfx::Rect(0, 0, 650, 650); |
@@ -82,11 +95,11 @@ class CustomButtonTest : public ViewsTestBase { |
ViewsTestBase::TearDown(); |
} |
- Widget* widget() { return widget_.get(); } |
+ TestWidget* widget() { return widget_.get(); } |
TestCustomButton* button() { return button_; } |
private: |
- scoped_ptr<Widget> widget_; |
+ scoped_ptr<TestWidget> widget_; |
TestCustomButton* button_; |
DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); |
@@ -204,6 +217,22 @@ TEST_F(CustomButtonTest, NotifyAction) { |
EXPECT_FALSE(button()->notified()); |
} |
+TEST_F(CustomButtonTest, HandleAcceleratorWhenFocused) { |
+ // Shouldn't handle accelerators when not active. |
+ EXPECT_FALSE(widget()->IsActive()); |
+ button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
+ EXPECT_FALSE(button()->notified()); |
+ // Should handle accelerators when active. |
+ widget()->set_active(true); |
+ button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
+ EXPECT_TRUE(button()->notified()); |
+ // Not active again. |
+ button()->Reset(); |
+ widget()->set_active(false); |
+ button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
+ EXPECT_FALSE(button()->notified()); |
+} |
+ |
// No touch on desktop Mac. Tracked in http://crbug.com/445520. |
#if !defined(OS_MACOSX) || defined(USE_AURA) |