OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/aura/desktop.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/aura/event.h" | 8 #include "ui/aura/event.h" |
9 #include "ui/aura/test/aura_test_base.h" | 9 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/aura/test/test_window_delegate.h" | 10 #include "ui/aura/test/test_window_delegate.h" |
11 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
12 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
13 #include "ui/gfx/point.h" | 13 #include "ui/gfx/point.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 | 15 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 private: | 50 private: |
51 int non_client_count_; | 51 int non_client_count_; |
52 gfx::Point non_client_location_; | 52 gfx::Point non_client_location_; |
53 int mouse_event_count_; | 53 int mouse_event_count_; |
54 gfx::Point mouse_event_location_; | 54 gfx::Point mouse_event_location_; |
55 int mouse_event_flags_; | 55 int mouse_event_flags_; |
56 }; | 56 }; |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 typedef AuraTestBase DesktopTest; | 60 typedef AuraTestBase RootWindowTest; |
61 | 61 |
62 TEST_F(DesktopTest, DispatchMouseEvent) { | 62 TEST_F(RootWindowTest, DispatchMouseEvent) { |
63 // Create two non-overlapping windows so we don't have to worry about which | 63 // Create two non-overlapping windows so we don't have to worry about which |
64 // is on top. | 64 // is on top. |
65 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); | 65 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
66 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); | 66 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
67 const int kWindowWidth = 123; | 67 const int kWindowWidth = 123; |
68 const int kWindowHeight = 45; | 68 const int kWindowHeight = 45; |
69 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 69 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
70 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 70 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
71 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 71 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
72 delegate1.get(), -1234, bounds1, NULL)); | 72 delegate1.get(), -1234, bounds1, NULL)); |
73 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 73 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
74 delegate2.get(), -5678, bounds2, NULL)); | 74 delegate2.get(), -5678, bounds2, NULL)); |
75 | 75 |
76 // Send a mouse event to window1. | 76 // Send a mouse event to window1. |
77 gfx::Point point(101, 201); | 77 gfx::Point point(101, 201); |
78 MouseEvent event1(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_BUTTON_DOWN); | 78 MouseEvent event1(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_BUTTON_DOWN); |
79 Desktop::GetInstance()->DispatchMouseEvent(&event1); | 79 RootWindow::GetInstance()->DispatchMouseEvent(&event1); |
80 | 80 |
81 // Event was tested for non-client area for the target window. | 81 // Event was tested for non-client area for the target window. |
82 EXPECT_EQ(1, delegate1->non_client_count()); | 82 EXPECT_EQ(1, delegate1->non_client_count()); |
83 EXPECT_EQ(0, delegate2->non_client_count()); | 83 EXPECT_EQ(0, delegate2->non_client_count()); |
84 // The non-client component test was in local coordinates. | 84 // The non-client component test was in local coordinates. |
85 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 85 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
86 // Mouse event was received by target window. | 86 // Mouse event was received by target window. |
87 EXPECT_EQ(1, delegate1->mouse_event_count()); | 87 EXPECT_EQ(1, delegate1->mouse_event_count()); |
88 EXPECT_EQ(0, delegate2->mouse_event_count()); | 88 EXPECT_EQ(0, delegate2->mouse_event_count()); |
89 // Event was in local coordinates. | 89 // Event was in local coordinates. |
90 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); | 90 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
91 // Non-client flag was set. | 91 // Non-client flag was set. |
92 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); | 92 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
93 } | 93 } |
94 | 94 |
95 // Check that we correctly track the state of the mouse buttons in response to | 95 // Check that we correctly track the state of the mouse buttons in response to |
96 // button press and release events. | 96 // button press and release events. |
97 TEST_F(DesktopTest, MouseButtonState) { | 97 TEST_F(RootWindowTest, MouseButtonState) { |
98 Desktop* desktop = Desktop::GetInstance(); | 98 RootWindow* root_window = RootWindow::GetInstance(); |
99 EXPECT_FALSE(desktop->IsMouseButtonDown()); | 99 EXPECT_FALSE(root_window->IsMouseButtonDown()); |
100 | 100 |
101 gfx::Point location; | 101 gfx::Point location; |
102 scoped_ptr<MouseEvent> event; | 102 scoped_ptr<MouseEvent> event; |
103 | 103 |
104 // Press the left button. | 104 // Press the left button. |
105 event.reset(new MouseEvent( | 105 event.reset(new MouseEvent( |
106 ui::ET_MOUSE_PRESSED, | 106 ui::ET_MOUSE_PRESSED, |
107 location, | 107 location, |
108 ui::EF_LEFT_BUTTON_DOWN)); | 108 ui::EF_LEFT_BUTTON_DOWN)); |
109 desktop->DispatchMouseEvent(event.get()); | 109 root_window->DispatchMouseEvent(event.get()); |
110 EXPECT_TRUE(desktop->IsMouseButtonDown()); | 110 EXPECT_TRUE(root_window->IsMouseButtonDown()); |
111 | 111 |
112 // Additionally press the right. | 112 // Additionally press the right. |
113 event.reset(new MouseEvent( | 113 event.reset(new MouseEvent( |
114 ui::ET_MOUSE_PRESSED, | 114 ui::ET_MOUSE_PRESSED, |
115 location, | 115 location, |
116 ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); | 116 ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); |
117 desktop->DispatchMouseEvent(event.get()); | 117 root_window->DispatchMouseEvent(event.get()); |
118 EXPECT_TRUE(desktop->IsMouseButtonDown()); | 118 EXPECT_TRUE(root_window->IsMouseButtonDown()); |
119 | 119 |
120 // Release the left button. | 120 // Release the left button. |
121 event.reset(new MouseEvent( | 121 event.reset(new MouseEvent( |
122 ui::ET_MOUSE_RELEASED, | 122 ui::ET_MOUSE_RELEASED, |
123 location, | 123 location, |
124 ui::EF_RIGHT_BUTTON_DOWN)); | 124 ui::EF_RIGHT_BUTTON_DOWN)); |
125 desktop->DispatchMouseEvent(event.get()); | 125 root_window->DispatchMouseEvent(event.get()); |
126 EXPECT_TRUE(desktop->IsMouseButtonDown()); | 126 EXPECT_TRUE(root_window->IsMouseButtonDown()); |
127 | 127 |
128 // Release the right button. We should ignore the Shift-is-down flag. | 128 // Release the right button. We should ignore the Shift-is-down flag. |
129 event.reset(new MouseEvent( | 129 event.reset(new MouseEvent( |
130 ui::ET_MOUSE_RELEASED, | 130 ui::ET_MOUSE_RELEASED, |
131 location, | 131 location, |
132 ui::EF_SHIFT_DOWN)); | 132 ui::EF_SHIFT_DOWN)); |
133 desktop->DispatchMouseEvent(event.get()); | 133 root_window->DispatchMouseEvent(event.get()); |
134 EXPECT_FALSE(desktop->IsMouseButtonDown()); | 134 EXPECT_FALSE(root_window->IsMouseButtonDown()); |
135 | 135 |
136 // Press the middle button. | 136 // Press the middle button. |
137 event.reset(new MouseEvent( | 137 event.reset(new MouseEvent( |
138 ui::ET_MOUSE_PRESSED, | 138 ui::ET_MOUSE_PRESSED, |
139 location, | 139 location, |
140 ui::EF_MIDDLE_BUTTON_DOWN)); | 140 ui::EF_MIDDLE_BUTTON_DOWN)); |
141 desktop->DispatchMouseEvent(event.get()); | 141 root_window->DispatchMouseEvent(event.get()); |
142 EXPECT_TRUE(desktop->IsMouseButtonDown()); | 142 EXPECT_TRUE(root_window->IsMouseButtonDown()); |
143 } | 143 } |
144 | 144 |
145 } // namespace test | 145 } // namespace test |
146 } // namespace aura | 146 } // namespace aura |
OLD | NEW |