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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 3175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3186 // Drargging. Cover HasCapture() and NativeWidgetPrivate::IsMouseButtonDown(). | 3186 // Drargging. Cover HasCapture() and NativeWidgetPrivate::IsMouseButtonDown(). |
3187 generator.DragMouseTo(gfx::Point(40, 40)); | 3187 generator.DragMouseTo(gfx::Point(40, 40)); |
3188 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 3188 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
3189 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); | 3189 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); |
3190 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); | 3190 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
3191 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); | 3191 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); |
3192 | 3192 |
3193 widget->CloseNow(); | 3193 widget->CloseNow(); |
3194 } | 3194 } |
3195 | 3195 |
3196 // Tests that a view does not receive entered, dragged, or moved events if | |
3197 // a mouse cursor is moved into it while the left mouse button is pressed. | |
3198 TEST_F(WidgetTest, DragIntoView) { | |
3199 EventCountView* container = new EventCountView; | |
3200 container->SetBounds(0, 0, 100, 80); | |
3201 | |
3202 EventCountView* consume_view = new EventCountView; | |
3203 consume_view->set_handle_mode(EventCountView::CONSUME_EVENTS); | |
3204 consume_view->SetBounds(10, 10, 50, 40); | |
3205 | |
3206 Widget* widget = CreateTopLevelFramelessPlatformWidget(); | |
3207 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); | |
3208 widget->SetContentsView(container); | |
3209 container->AddChildView(consume_view); | |
3210 | |
3211 widget->Show(); | |
3212 | |
3213 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); | |
3214 generator.set_current_location(gfx::Point(75, 15)); | |
3215 | |
3216 generator.PressLeftButton(); | |
3217 generator.MoveMouseTo(gfx::Point(20, 20)); | |
3218 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_ENTERED)); | |
3219 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); | |
3220 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); | |
3221 | |
3222 widget->CloseNow(); | |
3223 } | |
3224 | |
3225 // Tests that a view receives the correct mouse events if a mouse cursor | |
3226 // is moved out of its bounds while the left mouse button is pressed. | |
3227 TEST_F(WidgetTest, DragOutOfView) { | |
3228 EventCountView* container = new EventCountView; | |
3229 container->SetBounds(0, 0, 100, 80); | |
3230 | |
3231 EventCountView* consume_view = new EventCountView; | |
3232 consume_view->set_handle_mode(EventCountView::CONSUME_EVENTS); | |
3233 consume_view->SetBounds(10, 10, 50, 40); | |
3234 | |
3235 Widget* widget = CreateTopLevelFramelessPlatformWidget(); | |
3236 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); | |
3237 widget->SetContentsView(container); | |
3238 container->AddChildView(consume_view); | |
3239 | |
3240 widget->Show(); | |
3241 | |
3242 ui::test::EventGenerator generator(GetContext(), widget->GetNativeWindow()); | |
3243 generator.set_current_location(gfx::Point(20, 20)); | |
3244 | |
3245 generator.PressLeftButton(); | |
3246 EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | |
3247 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_PRESSED)); | |
3248 consume_view->ResetCounts(); | |
3249 | |
3250 generator.MoveMouseTo(gfx::Point(70, 70)); | |
3251 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_EXITED)); | |
3252 EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); | |
3253 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); | |
3254 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_ENTERED)); | |
3255 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_DRAGGED)); | |
3256 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_MOVED)); | |
3257 consume_view->ResetCounts(); | |
3258 | |
3259 generator.MoveMouseTo(gfx::Point(71, 71)); | |
3260 EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_DRAGGED)); | |
3261 EXPECT_EQ(0, consume_view->GetEventCount(ui::ET_MOUSE_MOVED)); | |
3262 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_DRAGGED)); | |
3263 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_MOVED)); | |
3264 consume_view->ResetCounts(); | |
3265 | |
3266 generator.ReleaseLeftButton(); | |
3267 EXPECT_EQ(1, consume_view->GetEventCount(ui::ET_MOUSE_RELEASED)); | |
3268 EXPECT_EQ(0, container->GetEventCount(ui::ET_MOUSE_RELEASED)); | |
sadrul
2014/09/26 20:59:13
Should we be sending an EXIT event here?
tdanderson
2014/09/29 18:38:13
From what I can see, we don't send an EXIT on ToT
| |
3269 consume_view->ResetCounts(); | |
3270 | |
3271 widget->CloseNow(); | |
3272 } | |
3273 | |
3196 // Tests that the root view is correctly set up for Widget types that do not | 3274 // Tests that the root view is correctly set up for Widget types that do not |
3197 // require a non-client view, before any other views are added to the widget. | 3275 // require a non-client view, before any other views are added to the widget. |
3198 // That is, before Widget::ReorderNativeViews() is called which, if called with | 3276 // That is, before Widget::ReorderNativeViews() is called which, if called with |
3199 // a root view not set, could cause the root view to get resized to the widget. | 3277 // a root view not set, could cause the root view to get resized to the widget. |
3200 TEST_F(WidgetTest, NonClientWindowValidAfterInit) { | 3278 TEST_F(WidgetTest, NonClientWindowValidAfterInit) { |
3201 Widget* widget = CreateTopLevelFramelessPlatformWidget(); | 3279 Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
3202 View* root_view = widget->GetRootView(); | 3280 View* root_view = widget->GetRootView(); |
3203 | 3281 |
3204 // Size the root view to exceed the widget bounds. | 3282 // Size the root view to exceed the widget bounds. |
3205 const gfx::Rect test_rect(0, 0, 500, 500); | 3283 const gfx::Rect test_rect(0, 0, 500, 500); |
3206 root_view->SetBoundsRect(test_rect); | 3284 root_view->SetBoundsRect(test_rect); |
3207 | 3285 |
3208 EXPECT_NE(test_rect.size(), widget->GetWindowBoundsInScreen().size()); | 3286 EXPECT_NE(test_rect.size(), widget->GetWindowBoundsInScreen().size()); |
3209 | 3287 |
3210 EXPECT_EQ(test_rect, root_view->bounds()); | 3288 EXPECT_EQ(test_rect, root_view->bounds()); |
3211 widget->ReorderNativeViews(); | 3289 widget->ReorderNativeViews(); |
3212 EXPECT_EQ(test_rect, root_view->bounds()); | 3290 EXPECT_EQ(test_rect, root_view->bounds()); |
3213 | 3291 |
3214 widget->CloseNow(); | 3292 widget->CloseNow(); |
3215 } | 3293 } |
3216 | 3294 |
3217 } // namespace test | 3295 } // namespace test |
3218 } // namespace views | 3296 } // namespace views |
OLD | NEW |