OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/wm/core/capture_controller.h" | 5 #include "ui/wm/core/capture_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 params.bounds = gfx::Rect(0, 0, 200, 100); | 79 params.bounds = gfx::Rect(0, 0, 200, 100); |
80 widget->Init(params); | 80 widget->Init(params); |
81 widget->Show(); | 81 widget->Show(); |
82 return widget; | 82 return widget; |
83 } | 83 } |
84 | 84 |
85 // Verifies mouse handlers are reset when a window gains capture. Specifically | 85 // Verifies mouse handlers are reset when a window gains capture. Specifically |
86 // creates two widgets, does a mouse press in one, sets capture in the other and | 86 // creates two widgets, does a mouse press in one, sets capture in the other and |
87 // verifies state is reset in the first. | 87 // verifies state is reset in the first. |
88 TEST_F(DesktopCaptureControllerTest, ResetMouseHandlers) { | 88 TEST_F(DesktopCaptureControllerTest, ResetMouseHandlers) { |
89 scoped_ptr<Widget> w1(CreateWidget()); | 89 std::unique_ptr<Widget> w1(CreateWidget()); |
90 scoped_ptr<Widget> w2(CreateWidget()); | 90 std::unique_ptr<Widget> w2(CreateWidget()); |
91 ui::test::EventGenerator generator1(w1->GetNativeView()->GetRootWindow()); | 91 ui::test::EventGenerator generator1(w1->GetNativeView()->GetRootWindow()); |
92 generator1.MoveMouseToCenterOf(w1->GetNativeView()); | 92 generator1.MoveMouseToCenterOf(w1->GetNativeView()); |
93 generator1.PressLeftButton(); | 93 generator1.PressLeftButton(); |
94 EXPECT_FALSE(w1->HasCapture()); | 94 EXPECT_FALSE(w1->HasCapture()); |
95 aura::WindowEventDispatcher* w1_dispatcher = | 95 aura::WindowEventDispatcher* w1_dispatcher = |
96 w1->GetNativeView()->GetHost()->dispatcher(); | 96 w1->GetNativeView()->GetHost()->dispatcher(); |
97 EXPECT_TRUE(w1_dispatcher->mouse_pressed_handler() != NULL); | 97 EXPECT_TRUE(w1_dispatcher->mouse_pressed_handler() != NULL); |
98 EXPECT_TRUE(w1_dispatcher->mouse_moved_handler() != NULL); | 98 EXPECT_TRUE(w1_dispatcher->mouse_moved_handler() != NULL); |
99 w2->SetCapture(w2->GetRootView()); | 99 w2->SetCapture(w2->GetRootView()); |
100 EXPECT_TRUE(w2->HasCapture()); | 100 EXPECT_TRUE(w2->HasCapture()); |
101 EXPECT_TRUE(w1_dispatcher->mouse_pressed_handler() == NULL); | 101 EXPECT_TRUE(w1_dispatcher->mouse_pressed_handler() == NULL); |
102 EXPECT_TRUE(w1_dispatcher->mouse_moved_handler() == NULL); | 102 EXPECT_TRUE(w1_dispatcher->mouse_moved_handler() == NULL); |
103 w2->ReleaseCapture(); | 103 w2->ReleaseCapture(); |
104 RunPendingMessages(); | 104 RunPendingMessages(); |
105 } | 105 } |
106 | 106 |
107 // Tests aura::Window capture and whether gesture events are sent to the window | 107 // Tests aura::Window capture and whether gesture events are sent to the window |
108 // which has capture. | 108 // which has capture. |
109 // The test case creates two visible widgets and sets capture to the underlying | 109 // The test case creates two visible widgets and sets capture to the underlying |
110 // aura::Windows one by one. It then sends a gesture event and validates whether | 110 // aura::Windows one by one. It then sends a gesture event and validates whether |
111 // the window which had capture receives the gesture. | 111 // the window which had capture receives the gesture. |
112 // TODO(sky): move this test, it should be part of ScopedCaptureClient tests. | 112 // TODO(sky): move this test, it should be part of ScopedCaptureClient tests. |
113 TEST_F(DesktopCaptureControllerTest, CaptureWindowInputEventTest) { | 113 TEST_F(DesktopCaptureControllerTest, CaptureWindowInputEventTest) { |
114 scoped_ptr<aura::client::ScreenPositionClient> desktop_position_client1; | 114 std::unique_ptr<aura::client::ScreenPositionClient> desktop_position_client1; |
115 scoped_ptr<aura::client::ScreenPositionClient> desktop_position_client2; | 115 std::unique_ptr<aura::client::ScreenPositionClient> desktop_position_client2; |
116 | 116 |
117 scoped_ptr<Widget> widget1(new Widget()); | 117 std::unique_ptr<Widget> widget1(new Widget()); |
118 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 118 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
119 scoped_ptr<wm::ScopedCaptureClient> scoped_capture_client( | 119 std::unique_ptr<wm::ScopedCaptureClient> scoped_capture_client( |
120 new wm::ScopedCaptureClient(params.context->GetRootWindow())); | 120 new wm::ScopedCaptureClient(params.context->GetRootWindow())); |
121 aura::client::CaptureClient* capture_client = | 121 aura::client::CaptureClient* capture_client = |
122 scoped_capture_client->capture_client(); | 122 scoped_capture_client->capture_client(); |
123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
124 params.bounds = gfx::Rect(50, 50, 650, 650); | 124 params.bounds = gfx::Rect(50, 50, 650, 650); |
125 widget1->Init(params); | 125 widget1->Init(params); |
126 internal::RootView* root1 = | 126 internal::RootView* root1 = |
127 static_cast<internal::RootView*>(widget1->GetRootView()); | 127 static_cast<internal::RootView*>(widget1->GetRootView()); |
128 | 128 |
129 desktop_position_client1.reset( | 129 desktop_position_client1.reset( |
130 new DesktopScreenPositionClient(params.context->GetRootWindow())); | 130 new DesktopScreenPositionClient(params.context->GetRootWindow())); |
131 aura::client::SetScreenPositionClient( | 131 aura::client::SetScreenPositionClient( |
132 widget1->GetNativeView()->GetRootWindow(), | 132 widget1->GetNativeView()->GetRootWindow(), |
133 desktop_position_client1.get()); | 133 desktop_position_client1.get()); |
134 | 134 |
135 DesktopViewInputTest* v1 = new DesktopViewInputTest(); | 135 DesktopViewInputTest* v1 = new DesktopViewInputTest(); |
136 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 136 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
137 root1->AddChildView(v1); | 137 root1->AddChildView(v1); |
138 widget1->Show(); | 138 widget1->Show(); |
139 | 139 |
140 scoped_ptr<Widget> widget2(new Widget()); | 140 std::unique_ptr<Widget> widget2(new Widget()); |
141 | 141 |
142 params = CreateParams(Widget::InitParams::TYPE_POPUP); | 142 params = CreateParams(Widget::InitParams::TYPE_POPUP); |
143 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 143 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
144 params.bounds = gfx::Rect(50, 50, 650, 650); | 144 params.bounds = gfx::Rect(50, 50, 650, 650); |
145 widget2->Init(params); | 145 widget2->Init(params); |
146 | 146 |
147 internal::RootView* root2 = | 147 internal::RootView* root2 = |
148 static_cast<internal::RootView*>(widget2->GetRootView()); | 148 static_cast<internal::RootView*>(widget2->GetRootView()); |
149 desktop_position_client2.reset( | 149 desktop_position_client2.reset( |
150 new DesktopScreenPositionClient(params.context->GetRootWindow())); | 150 new DesktopScreenPositionClient(params.context->GetRootWindow())); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 EXPECT_TRUE(v2->received_gesture_event()); | 195 EXPECT_TRUE(v2->received_gesture_event()); |
196 EXPECT_FALSE(v1->received_gesture_event()); | 196 EXPECT_FALSE(v1->received_gesture_event()); |
197 | 197 |
198 widget1->CloseNow(); | 198 widget1->CloseNow(); |
199 widget2->CloseNow(); | 199 widget2->CloseNow(); |
200 RunPendingMessages(); | 200 RunPendingMessages(); |
201 } | 201 } |
202 | 202 |
203 } // namespace views | 203 } // namespace views |
OLD | NEW |