| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/base/layout.h" | 8 #include "ui/base/layout.h" |
| 9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
| 10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); | 92 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 // Tests that hover state changes correctly when visiblity/enableness changes. | 97 // Tests that hover state changes correctly when visiblity/enableness changes. |
| 98 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { | 98 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { |
| 99 gfx::Point center(10, 10); | 99 gfx::Point center(10, 10); |
| 100 button()->OnMousePressed(ui::MouseEvent( | 100 button()->OnMousePressed(ui::MouseEvent( |
| 101 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 101 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 102 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 102 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 103 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 103 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 104 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 104 | 105 |
| 105 button()->OnMouseReleased(ui::MouseEvent( | 106 button()->OnMouseReleased(ui::MouseEvent( |
| 106 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 107 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 107 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 108 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 109 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 108 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 110 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 109 | 111 |
| 110 button()->SetEnabled(false); | 112 button()->SetEnabled(false); |
| 111 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); | 113 EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state()); |
| 112 | 114 |
| 113 button()->SetEnabled(true); | 115 button()->SetEnabled(true); |
| 114 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 116 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 115 | 117 |
| 116 button()->SetVisible(false); | 118 button()->SetVisible(false); |
| 117 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 119 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 143 #endif // !defined(OS_MACOSX) || defined(USE_AURA) | 145 #endif // !defined(OS_MACOSX) || defined(USE_AURA) |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Tests the different types of NotifyActions. | 148 // Tests the different types of NotifyActions. |
| 147 TEST_F(CustomButtonTest, NotifyAction) { | 149 TEST_F(CustomButtonTest, NotifyAction) { |
| 148 gfx::Point center(10, 10); | 150 gfx::Point center(10, 10); |
| 149 | 151 |
| 150 // By default the button should notify its listener on mouse release. | 152 // By default the button should notify its listener on mouse release. |
| 151 button()->OnMousePressed(ui::MouseEvent( | 153 button()->OnMousePressed(ui::MouseEvent( |
| 152 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 154 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 153 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 155 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 156 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 154 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 157 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 155 EXPECT_FALSE(button()->notified()); | 158 EXPECT_FALSE(button()->notified()); |
| 156 | 159 |
| 157 button()->OnMouseReleased(ui::MouseEvent( | 160 button()->OnMouseReleased(ui::MouseEvent( |
| 158 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 161 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 159 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 162 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 163 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 160 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 164 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 161 EXPECT_TRUE(button()->notified()); | 165 EXPECT_TRUE(button()->notified()); |
| 162 | 166 |
| 163 // Set the notify action to its listener on mouse press. | 167 // Set the notify action to its listener on mouse press. |
| 164 button()->Reset(); | 168 button()->Reset(); |
| 165 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 169 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 166 button()->OnMousePressed(ui::MouseEvent( | 170 button()->OnMousePressed(ui::MouseEvent( |
| 167 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 171 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 168 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 172 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 173 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 169 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 174 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 170 EXPECT_TRUE(button()->notified()); | 175 EXPECT_TRUE(button()->notified()); |
| 171 | 176 |
| 172 // The button should no longer notify on mouse release. | 177 // The button should no longer notify on mouse release. |
| 173 button()->Reset(); | 178 button()->Reset(); |
| 174 button()->OnMouseReleased(ui::MouseEvent( | 179 button()->OnMouseReleased(ui::MouseEvent( |
| 175 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 180 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 176 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 181 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 182 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 177 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 183 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 178 EXPECT_FALSE(button()->notified()); | 184 EXPECT_FALSE(button()->notified()); |
| 179 } | 185 } |
| 180 | 186 |
| 181 // No touch on desktop Mac. Tracked in http://crbug.com/445520. | 187 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
| 182 #if !defined(OS_MACOSX) || defined(USE_AURA) | 188 #if !defined(OS_MACOSX) || defined(USE_AURA) |
| 183 | 189 |
| 184 namespace { | 190 namespace { |
| 185 | 191 |
| 186 void PerformGesture(CustomButton* button, ui::EventType event_type) { | 192 void PerformGesture(CustomButton* button, ui::EventType event_type) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); | 240 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); |
| 235 | 241 |
| 236 Link link(text); | 242 Link link(text); |
| 237 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); | 243 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); |
| 238 | 244 |
| 239 Textfield textfield; | 245 Textfield textfield; |
| 240 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); | 246 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); |
| 241 } | 247 } |
| 242 | 248 |
| 243 } // namespace views | 249 } // namespace views |
| OLD | NEW |