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 "ui/aura/client/capture_delegate.h" |
8 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
9 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/aura/test/test_screen.h" | 11 #include "ui/aura/test/test_screen.h" |
11 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
15 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
16 #include "ui/events/test/event_generator.h" | 17 #include "ui/events/test/event_generator.h" |
17 #include "ui/views/test/views_test_base.h" | |
18 #include "ui/views/view.h" | |
19 #include "ui/views/widget/root_view.h" | |
20 #include "ui/views/widget/widget.h" | |
21 | 18 |
22 #if !defined(OS_CHROMEOS) | 19 namespace wm { |
23 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | |
24 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" | |
25 #endif | |
26 | 20 |
27 namespace views { | 21 namespace { |
| 22 |
| 23 // aura::client::CaptureDelegate which allows querying whether native capture |
| 24 // has been acquired. |
| 25 class TestCaptureDelegate : public aura::client::CaptureDelegate { |
| 26 public: |
| 27 TestCaptureDelegate() : has_capture_(false) {} |
| 28 ~TestCaptureDelegate() override {} |
| 29 |
| 30 bool HasNativeCapture() const { |
| 31 return has_capture_; |
| 32 } |
| 33 |
| 34 // aura::client::CaptureDelegate: |
| 35 void UpdateCapture(aura::Window* old_capture, |
| 36 aura::Window* new_capture) override {} |
| 37 void OnOtherRootGotCapture() override {} |
| 38 void SetNativeCapture() override { has_capture_ = true; } |
| 39 void ReleaseNativeCapture() override { has_capture_ = false; } |
| 40 |
| 41 private: |
| 42 bool has_capture_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestCaptureDelegate); |
| 45 }; |
| 46 |
| 47 } // namespace |
28 | 48 |
29 class CaptureControllerTest : public aura::test::AuraTestBase { | 49 class CaptureControllerTest : public aura::test::AuraTestBase { |
30 public: | 50 public: |
31 CaptureControllerTest() {} | 51 CaptureControllerTest() {} |
32 | 52 |
33 void SetUp() override { | 53 void SetUp() override { |
34 AuraTestBase::SetUp(); | 54 AuraTestBase::SetUp(); |
35 capture_controller_.reset(new wm::ScopedCaptureClient(root_window())); | 55 capture_controller_.reset(new ScopedCaptureClient(root_window())); |
36 | 56 |
37 second_host_.reset(aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600))); | 57 second_host_.reset(aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600))); |
38 second_host_->InitHost(); | 58 second_host_->InitHost(); |
39 second_host_->window()->Show(); | 59 second_host_->window()->Show(); |
40 second_host_->SetBounds(gfx::Rect(800, 600)); | 60 second_host_->SetBounds(gfx::Rect(800, 600)); |
41 second_capture_controller_.reset( | 61 second_capture_controller_.reset( |
42 new wm::ScopedCaptureClient(second_host_->window())); | 62 new ScopedCaptureClient(second_host_->window())); |
43 | |
44 #if !defined(OS_CHROMEOS) | |
45 desktop_position_client_.reset( | |
46 new DesktopScreenPositionClient(root_window())); | |
47 | |
48 second_desktop_position_client_.reset( | |
49 new DesktopScreenPositionClient(second_host_->window())); | |
50 #endif | |
51 } | 63 } |
52 | 64 |
53 void TearDown() override { | 65 void TearDown() override { |
54 RunAllPendingInMessageLoop(); | 66 RunAllPendingInMessageLoop(); |
55 | 67 |
56 #if !defined(OS_CHROMEOS) | |
57 second_desktop_position_client_.reset(); | |
58 #endif | |
59 second_capture_controller_.reset(); | 68 second_capture_controller_.reset(); |
60 | 69 |
61 // Kill any active compositors before we hit the compositor shutdown paths. | 70 // Kill any active compositors before we hit the compositor shutdown paths. |
62 second_host_.reset(); | 71 second_host_.reset(); |
63 | 72 |
64 #if !defined(OS_CHROMEOS) | |
65 desktop_position_client_.reset(); | |
66 #endif | |
67 capture_controller_.reset(); | 73 capture_controller_.reset(); |
68 | 74 |
69 AuraTestBase::TearDown(); | 75 AuraTestBase::TearDown(); |
70 } | 76 } |
71 | 77 |
72 aura::Window* GetCaptureWindow() { | 78 aura::Window* GetCaptureWindow() { |
73 return capture_controller_->capture_client()->GetCaptureWindow(); | 79 return capture_controller_->capture_client()->GetCaptureWindow(); |
74 } | 80 } |
75 | 81 |
76 aura::Window* GetSecondCaptureWindow() { | 82 aura::Window* GetSecondCaptureWindow() { |
77 return second_capture_controller_->capture_client()->GetCaptureWindow(); | 83 return second_capture_controller_->capture_client()->GetCaptureWindow(); |
78 } | 84 } |
79 | 85 |
80 scoped_ptr<wm::ScopedCaptureClient> capture_controller_; | 86 scoped_ptr<ScopedCaptureClient> capture_controller_; |
81 scoped_ptr<aura::WindowTreeHost> second_host_; | 87 scoped_ptr<aura::WindowTreeHost> second_host_; |
82 scoped_ptr<wm::ScopedCaptureClient> second_capture_controller_; | 88 scoped_ptr<ScopedCaptureClient> second_capture_controller_; |
83 #if !defined(OS_CHROMEOS) | |
84 scoped_ptr<aura::client::ScreenPositionClient> desktop_position_client_; | |
85 scoped_ptr<aura::client::ScreenPositionClient> | |
86 second_desktop_position_client_; | |
87 #endif | |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(CaptureControllerTest); | 90 DISALLOW_COPY_AND_ASSIGN(CaptureControllerTest); |
90 }; | 91 }; |
91 | 92 |
92 // Makes sure that internal details that are set on mouse down (such as | 93 // Makes sure that internal details that are set on mouse down (such as |
93 // mouse_pressed_handler()) are cleared when another root window takes capture. | 94 // mouse_pressed_handler()) are cleared when another root window takes capture. |
94 TEST_F(CaptureControllerTest, ResetMouseEventHandlerOnCapture) { | 95 TEST_F(CaptureControllerTest, ResetMouseEventHandlerOnCapture) { |
95 // Create a window inside the WindowEventDispatcher. | 96 // Create a window inside the WindowEventDispatcher. |
96 scoped_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 97 scoped_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
97 | 98 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 w2->ReleaseCapture(); | 159 w2->ReleaseCapture(); |
159 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetCaptureWindow()); | 160 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetCaptureWindow()); |
160 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetSecondCaptureWindow()); | 161 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetSecondCaptureWindow()); |
161 ui::TouchEvent touch_event( | 162 ui::TouchEvent touch_event( |
162 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, 0, ui::EventTimeForNow(), 1.0f, | 163 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, 0, ui::EventTimeForNow(), 1.0f, |
163 1.0f, 1.0f, 1.0f); | 164 1.0f, 1.0f, 1.0f); |
164 EXPECT_EQ(static_cast<ui::GestureConsumer*>(w2.get()), | 165 EXPECT_EQ(static_cast<ui::GestureConsumer*>(w2.get()), |
165 ui::GestureRecognizer::Get()->GetTouchLockedTarget(touch_event)); | 166 ui::GestureRecognizer::Get()->GetTouchLockedTarget(touch_event)); |
166 } | 167 } |
167 | 168 |
168 } // namespace views | 169 // Test that native capture is released properly when the window with capture |
| 170 // is reparented to a different root window while it has capture. |
| 171 TEST_F(CaptureControllerTest, ReparentedWhileCaptured) { |
| 172 scoped_ptr<TestCaptureDelegate> delegate(new TestCaptureDelegate); |
| 173 ScopedCaptureClient::TestApi(capture_controller_.get()) |
| 174 .SetDelegate(delegate.get()); |
| 175 scoped_ptr<TestCaptureDelegate> delegate2(new TestCaptureDelegate); |
| 176 ScopedCaptureClient::TestApi(second_capture_controller_.get()) |
| 177 .SetDelegate(delegate2.get()); |
| 178 |
| 179 scoped_ptr<aura::Window> w(CreateNormalWindow(1, root_window(), NULL)); |
| 180 w->SetCapture(); |
| 181 EXPECT_EQ(w.get(), GetCaptureWindow()); |
| 182 EXPECT_EQ(w.get(), GetSecondCaptureWindow()); |
| 183 EXPECT_TRUE(delegate->HasNativeCapture()); |
| 184 EXPECT_FALSE(delegate2->HasNativeCapture()); |
| 185 |
| 186 second_host_->window()->AddChild(w.get()); |
| 187 EXPECT_EQ(w.get(), GetCaptureWindow()); |
| 188 EXPECT_EQ(w.get(), GetSecondCaptureWindow()); |
| 189 EXPECT_TRUE(delegate->HasNativeCapture()); |
| 190 EXPECT_FALSE(delegate2->HasNativeCapture()); |
| 191 |
| 192 w->ReleaseCapture(); |
| 193 EXPECT_EQ(nullptr, GetCaptureWindow()); |
| 194 EXPECT_EQ(nullptr, GetSecondCaptureWindow()); |
| 195 EXPECT_FALSE(delegate->HasNativeCapture()); |
| 196 EXPECT_FALSE(delegate2->HasNativeCapture()); |
| 197 } |
| 198 |
| 199 } // namespace wm |
OLD | NEW |