| 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 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 typedef test::AuraTestBase RootWindowTest; | 107 typedef test::AuraTestBase RootWindowTest; |
| 108 | 108 |
| 109 TEST_F(RootWindowTest, OnHostMouseEvent) { | 109 TEST_F(RootWindowTest, OnHostMouseEvent) { |
| 110 // Create two non-overlapping windows so we don't have to worry about which | 110 // Create two non-overlapping windows so we don't have to worry about which |
| 111 // is on top. | 111 // is on top. |
| 112 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); | 112 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
| 113 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); | 113 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
| 114 const int kWindowWidth = 123; | 114 const int kWindowWidth = 123; |
| 115 const int kWindowHeight = 45; | 115 const int kWindowHeight = 45; |
| 116 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 116 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 117 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 117 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 118 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 118 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 119 delegate1.get(), -1234, bounds1, NULL)); | 119 delegate1.get(), -1234, bounds1, root_window())); |
| 120 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 120 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 121 delegate2.get(), -5678, bounds2, NULL)); | 121 delegate2.get(), -5678, bounds2, root_window())); |
| 122 | 122 |
| 123 // Send a mouse event to window1. | 123 // Send a mouse event to window1. |
| 124 gfx::Point point(101, 201); | 124 gfx::Point point(101, 201); |
| 125 ui::MouseEvent event1( | 125 ui::MouseEvent event1( |
| 126 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); | 126 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); |
| 127 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); | 127 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); |
| 128 | 128 |
| 129 // Event was tested for non-client area for the target window. | 129 // Event was tested for non-client area for the target window. |
| 130 EXPECT_EQ(1, delegate1->non_client_count()); | 130 EXPECT_EQ(1, delegate1->non_client_count()); |
| 131 EXPECT_EQ(0, delegate2->non_client_count()); | 131 EXPECT_EQ(0, delegate2->non_client_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 // Temporarily disabled for windows. See crbug.com/112222. | 144 // Temporarily disabled for windows. See crbug.com/112222. |
| 145 TEST_F(RootWindowTest, DISABLED_HideCursor) { | 145 TEST_F(RootWindowTest, DISABLED_HideCursor) { |
| 146 #else | 146 #else |
| 147 TEST_F(RootWindowTest, HideCursor) { | 147 TEST_F(RootWindowTest, HideCursor) { |
| 148 #endif // defined(OS_WIN) | 148 #endif // defined(OS_WIN) |
| 149 scoped_ptr<NonClientDelegate> delegate(new NonClientDelegate()); | 149 scoped_ptr<NonClientDelegate> delegate(new NonClientDelegate()); |
| 150 const int kWindowWidth = 123; | 150 const int kWindowWidth = 123; |
| 151 const int kWindowHeight = 45; | 151 const int kWindowHeight = 45; |
| 152 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 152 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 153 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 153 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 154 delegate.get(), -1234, bounds, NULL)); | 154 delegate.get(), -1234, bounds, root_window())); |
| 155 aura::Window* window_ptr = &*window; | 155 aura::Window* window_ptr = &*window; |
| 156 | 156 |
| 157 root_window()->OnCursorVisibilityChanged(true); | 157 root_window()->OnCursorVisibilityChanged(true); |
| 158 // Send a mouse event to window. | 158 // Send a mouse event to window. |
| 159 gfx::Point point(101, 201); | 159 gfx::Point point(101, 201); |
| 160 gfx::Point local_point; | 160 gfx::Point local_point; |
| 161 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); | 161 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); |
| 162 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); | 162 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); |
| 163 | 163 |
| 164 // Location was in window. | 164 // Location was in window. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ui::ET_MOUSE_PRESSED, | 230 ui::ET_MOUSE_PRESSED, |
| 231 location, | 231 location, |
| 232 location, | 232 location, |
| 233 ui::EF_MIDDLE_MOUSE_BUTTON)); | 233 ui::EF_MIDDLE_MOUSE_BUTTON)); |
| 234 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 234 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 235 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); | 235 EXPECT_TRUE(Env::GetInstance()->is_mouse_button_down()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 TEST_F(RootWindowTest, TranslatedEvent) { | 238 TEST_F(RootWindowTest, TranslatedEvent) { |
| 239 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 239 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
| 240 gfx::Rect(50, 50, 100, 100), NULL)); | 240 gfx::Rect(50, 50, 100, 100), root_window())); |
| 241 | 241 |
| 242 gfx::Point origin(100, 100); | 242 gfx::Point origin(100, 100); |
| 243 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); | 243 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); |
| 244 | 244 |
| 245 EXPECT_EQ("100,100", root.location().ToString()); | 245 EXPECT_EQ("100,100", root.location().ToString()); |
| 246 EXPECT_EQ("100,100", root.root_location().ToString()); | 246 EXPECT_EQ("100,100", root.root_location().ToString()); |
| 247 | 247 |
| 248 ui::MouseEvent translated_event( | 248 ui::MouseEvent translated_event( |
| 249 root, static_cast<Window*>(root_window()), w1.get(), | 249 root, static_cast<Window*>(root_window()), w1.get(), |
| 250 ui::ET_MOUSE_ENTERED, root.flags()); | 250 ui::ET_MOUSE_ENTERED, root.flags()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 } | 537 } |
| 538 | 538 |
| 539 } // namespace | 539 } // namespace |
| 540 | 540 |
| 541 TEST_F(RootWindowTest, HoldMouseMove) { | 541 TEST_F(RootWindowTest, HoldMouseMove) { |
| 542 EventFilterRecorder* filter = new EventFilterRecorder; | 542 EventFilterRecorder* filter = new EventFilterRecorder; |
| 543 root_window()->SetEventFilter(filter); // passes ownership | 543 root_window()->SetEventFilter(filter); // passes ownership |
| 544 | 544 |
| 545 test::TestWindowDelegate delegate; | 545 test::TestWindowDelegate delegate; |
| 546 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 546 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 547 &delegate, 1, gfx::Rect(0, 0, 100, 100), NULL)); | 547 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 548 | 548 |
| 549 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 549 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
| 550 gfx::Point(0, 0), 0); | 550 gfx::Point(0, 0), 0); |
| 551 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 551 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 552 &mouse_move_event); | 552 &mouse_move_event); |
| 553 // Discard MOUSE_ENTER. | 553 // Discard MOUSE_ENTER. |
| 554 filter->events().clear(); | 554 filter->events().clear(); |
| 555 | 555 |
| 556 root_window()->HoldMouseMoves(); | 556 root_window()->HoldMouseMoves(); |
| 557 | 557 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { | 764 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { |
| 765 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 765 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
| 766 DetachesParentOnTapDelegate delegate; | 766 DetachesParentOnTapDelegate delegate; |
| 767 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); | 767 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); |
| 768 Window* child = CreateWindow(11, parent.get(), &delegate); | 768 Window* child = CreateWindow(11, parent.get(), &delegate); |
| 769 test::EventGenerator generator(root_window(), child); | 769 test::EventGenerator generator(root_window(), child); |
| 770 generator.GestureTapAt(gfx::Point(40, 40)); | 770 generator.GestureTapAt(gfx::Point(40, 40)); |
| 771 } | 771 } |
| 772 | 772 |
| 773 } // namespace aura | 773 } // namespace aura |
| OLD | NEW |