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/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 private: | 89 private: |
90 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); | 90 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); |
91 }; | 91 }; |
92 | 92 |
93 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { | 93 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { |
94 Window* window = new Window( | 94 Window* window = new Window( |
95 delegate ? delegate : | 95 delegate ? delegate : |
96 test::TestWindowDelegate::CreateSelfDestroyingDelegate()); | 96 test::TestWindowDelegate::CreateSelfDestroyingDelegate()); |
97 window->set_id(id); | 97 window->set_id(id); |
98 window->Init(ui::LAYER_TEXTURED); | 98 window->Init(ui::LAYER_TEXTURED); |
99 window->SetParent(parent); | 99 parent->AddChild(window); |
100 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 100 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
101 window->Show(); | 101 window->Show(); |
102 return window; | 102 return window; |
103 } | 103 } |
104 | 104 |
105 bool IsFocusedWindow(aura::Window* window) { | 105 bool IsFocusedWindow(aura::Window* window) { |
106 return client::GetFocusClient(window)->GetFocusedWindow() == window; | 106 return client::GetFocusClient(window)->GetFocusedWindow() == window; |
107 } | 107 } |
108 | 108 |
109 } // namespace | 109 } // namespace |
110 | 110 |
111 typedef test::AuraTestBase RootWindowTest; | 111 typedef test::AuraTestBase RootWindowTest; |
112 | 112 |
113 TEST_F(RootWindowTest, OnHostMouseEvent) { | 113 TEST_F(RootWindowTest, OnHostMouseEvent) { |
114 // Create two non-overlapping windows so we don't have to worry about which | 114 // Create two non-overlapping windows so we don't have to worry about which |
115 // is on top. | 115 // is on top. |
116 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); | 116 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
117 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); | 117 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
118 const int kWindowWidth = 123; | 118 const int kWindowWidth = 123; |
119 const int kWindowHeight = 45; | 119 const int kWindowHeight = 45; |
120 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 120 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
121 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 121 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
122 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 122 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
123 delegate1.get(), -1234, bounds1, NULL)); | 123 delegate1.get(), -1234, bounds1, root_window())); |
124 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 124 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
125 delegate2.get(), -5678, bounds2, NULL)); | 125 delegate2.get(), -5678, bounds2, root_window())); |
126 | 126 |
127 // Send a mouse event to window1. | 127 // Send a mouse event to window1. |
128 gfx::Point point(101, 201); | 128 gfx::Point point(101, 201); |
129 ui::MouseEvent event1( | 129 ui::MouseEvent event1( |
130 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); | 130 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); |
131 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); | 131 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); |
132 | 132 |
133 // Event was tested for non-client area for the target window. | 133 // Event was tested for non-client area for the target window. |
134 EXPECT_EQ(1, delegate1->non_client_count()); | 134 EXPECT_EQ(1, delegate1->non_client_count()); |
135 EXPECT_EQ(0, delegate2->non_client_count()); | 135 EXPECT_EQ(0, delegate2->non_client_count()); |
(...skipping 12 matching lines...) Expand all Loading... |
148 // Temporarily disabled for windows. See crbug.com/112222. | 148 // Temporarily disabled for windows. See crbug.com/112222. |
149 TEST_F(RootWindowTest, DISABLED_HideCursor) { | 149 TEST_F(RootWindowTest, DISABLED_HideCursor) { |
150 #else | 150 #else |
151 TEST_F(RootWindowTest, HideCursor) { | 151 TEST_F(RootWindowTest, HideCursor) { |
152 #endif // defined(OS_WIN) | 152 #endif // defined(OS_WIN) |
153 scoped_ptr<NonClientDelegate> delegate(new NonClientDelegate()); | 153 scoped_ptr<NonClientDelegate> delegate(new NonClientDelegate()); |
154 const int kWindowWidth = 123; | 154 const int kWindowWidth = 123; |
155 const int kWindowHeight = 45; | 155 const int kWindowHeight = 45; |
156 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 156 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
157 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 157 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
158 delegate.get(), -1234, bounds, NULL)); | 158 delegate.get(), -1234, bounds, root_window())); |
159 aura::Window* window_ptr = &*window; | 159 aura::Window* window_ptr = &*window; |
160 | 160 |
161 root_window()->OnCursorVisibilityChanged(true); | 161 root_window()->OnCursorVisibilityChanged(true); |
162 // Send a mouse event to window. | 162 // Send a mouse event to window. |
163 gfx::Point point(101, 201); | 163 gfx::Point point(101, 201); |
164 gfx::Point local_point; | 164 gfx::Point local_point; |
165 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); | 165 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); |
166 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); | 166 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); |
167 | 167 |
168 // Location was in window. | 168 // Location was in window. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ui::ET_MOUSE_PRESSED, | 234 ui::ET_MOUSE_PRESSED, |
235 location, | 235 location, |
236 location, | 236 location, |
237 ui::EF_MIDDLE_MOUSE_BUTTON)); | 237 ui::EF_MIDDLE_MOUSE_BUTTON)); |
238 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 238 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
239 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); | 239 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); |
240 } | 240 } |
241 | 241 |
242 TEST_F(RootWindowTest, TranslatedEvent) { | 242 TEST_F(RootWindowTest, TranslatedEvent) { |
243 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 243 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
244 gfx::Rect(50, 50, 100, 100), NULL)); | 244 gfx::Rect(50, 50, 100, 100), root_window())); |
245 | 245 |
246 gfx::Point origin(100, 100); | 246 gfx::Point origin(100, 100); |
247 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); | 247 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); |
248 | 248 |
249 EXPECT_EQ("100,100", root.location().ToString()); | 249 EXPECT_EQ("100,100", root.location().ToString()); |
250 EXPECT_EQ("100,100", root.root_location().ToString()); | 250 EXPECT_EQ("100,100", root.root_location().ToString()); |
251 | 251 |
252 ui::MouseEvent translated_event( | 252 ui::MouseEvent translated_event( |
253 root, static_cast<Window*>(root_window()), w1.get(), | 253 root, static_cast<Window*>(root_window()), w1.get(), |
254 ui::ET_MOUSE_ENTERED, root.flags()); | 254 ui::ET_MOUSE_ENTERED, root.flags()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 541 } |
542 | 542 |
543 } // namespace | 543 } // namespace |
544 | 544 |
545 TEST_F(RootWindowTest, HoldMouseMove) { | 545 TEST_F(RootWindowTest, HoldMouseMove) { |
546 EventFilterRecorder* filter = new EventFilterRecorder; | 546 EventFilterRecorder* filter = new EventFilterRecorder; |
547 root_window()->SetEventFilter(filter); // passes ownership | 547 root_window()->SetEventFilter(filter); // passes ownership |
548 | 548 |
549 test::TestWindowDelegate delegate; | 549 test::TestWindowDelegate delegate; |
550 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 550 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
551 &delegate, 1, gfx::Rect(0, 0, 100, 100), NULL)); | 551 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
552 | 552 |
553 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 553 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
554 gfx::Point(0, 0), 0); | 554 gfx::Point(0, 0), 0); |
555 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 555 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
556 &mouse_move_event); | 556 &mouse_move_event); |
557 // Discard MOUSE_ENTER. | 557 // Discard MOUSE_ENTER. |
558 filter->events().clear(); | 558 filter->events().clear(); |
559 | 559 |
560 root_window()->HoldMouseMoves(); | 560 root_window()->HoldMouseMoves(); |
561 | 561 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { | 768 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { |
769 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 769 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
770 DetachesParentOnTapDelegate delegate; | 770 DetachesParentOnTapDelegate delegate; |
771 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); | 771 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); |
772 Window* child = CreateWindow(11, parent.get(), &delegate); | 772 Window* child = CreateWindow(11, parent.get(), &delegate); |
773 test::EventGenerator generator(root_window(), child); | 773 test::EventGenerator generator(root_window(), child); |
774 generator.GestureTapAt(gfx::Point(40, 40)); | 774 generator.GestureTapAt(gfx::Point(40, 40)); |
775 } | 775 } |
776 | 776 |
777 } // namespace aura | 777 } // namespace aura |
OLD | NEW |