OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/desktop.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/event.h" |
| 9 #include "ui/aura/test/aura_test_base.h" |
| 10 #include "ui/aura/test/test_window_delegate.h" |
| 11 #include "ui/aura/test/test_windows.h" |
| 12 #include "ui/base/hit_test.h" |
| 13 #include "ui/gfx/point.h" |
| 14 #include "ui/gfx/rect.h" |
| 15 |
| 16 namespace aura { |
| 17 namespace test { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // A delegate that always returns a non-client component for hit tests. |
| 22 class NonClientDelegate : public TestWindowDelegate { |
| 23 public: |
| 24 NonClientDelegate() |
| 25 : non_client_count_(0), |
| 26 mouse_event_count_(0), |
| 27 mouse_event_flags_(0x0) { |
| 28 } |
| 29 virtual ~NonClientDelegate() {} |
| 30 |
| 31 int non_client_count() const { return non_client_count_; } |
| 32 gfx::Point non_client_location() const { return non_client_location_; } |
| 33 int mouse_event_count() const { return mouse_event_count_; } |
| 34 gfx::Point mouse_event_location() const { return mouse_event_location_; } |
| 35 int mouse_event_flags() const { return mouse_event_flags_; } |
| 36 |
| 37 virtual int GetNonClientComponent(const gfx::Point& location) const OVERRIDE { |
| 38 NonClientDelegate* self = const_cast<NonClientDelegate*>(this); |
| 39 self->non_client_count_++; |
| 40 self->non_client_location_ = location; |
| 41 return HTTOPLEFT; |
| 42 } |
| 43 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { |
| 44 mouse_event_count_++; |
| 45 mouse_event_location_ = event->location(); |
| 46 mouse_event_flags_ = event->flags(); |
| 47 return true; |
| 48 } |
| 49 |
| 50 private: |
| 51 int non_client_count_; |
| 52 gfx::Point non_client_location_; |
| 53 int mouse_event_count_; |
| 54 gfx::Point mouse_event_location_; |
| 55 int mouse_event_flags_; |
| 56 }; |
| 57 |
| 58 } // namespace |
| 59 |
| 60 class DesktopTest : public AuraTestBase { |
| 61 }; |
| 62 |
| 63 TEST_F(DesktopTest, DispatchMouseEvent) { |
| 64 // Create two non-overlapping windows so we don't have to worry about which |
| 65 // is on top. |
| 66 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
| 67 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
| 68 const int kWindowWidth = 123; |
| 69 const int kWindowHeight = 45; |
| 70 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 71 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 72 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 73 delegate1.get(), -1234, bounds1, NULL)); |
| 74 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 75 delegate2.get(), -5678, bounds2, NULL)); |
| 76 |
| 77 // Send a mouse event to window1. |
| 78 gfx::Point point(101, 201); |
| 79 MouseEvent event1(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_BUTTON_DOWN); |
| 80 Desktop::GetInstance()->DispatchMouseEvent(&event1); |
| 81 |
| 82 // Event was tested for non-client area for the target window. |
| 83 EXPECT_EQ(1, delegate1->non_client_count()); |
| 84 EXPECT_EQ(0, delegate2->non_client_count()); |
| 85 // The non-client component test was in local coordinates. |
| 86 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
| 87 // Mouse event was received by target window. |
| 88 EXPECT_EQ(1, delegate1->mouse_event_count()); |
| 89 EXPECT_EQ(0, delegate2->mouse_event_count()); |
| 90 // Event was in local coordinates. |
| 91 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
| 92 // Non-client flag was set. |
| 93 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
| 94 } |
| 95 |
| 96 } // namespace test |
| 97 } // namespace aura |
OLD | NEW |