Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: ui/wm/core/capture_controller_unittest.cc

Issue 2466023003: Makes CaptureController be created and owned by WMState (Closed)
Patch Set: moar Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/wm/core/capture_controller.cc ('k') | ui/wm/core/wm_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 : aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate()); 89 : aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate());
90 window->set_id(id); 90 window->set_id(id);
91 window->Init(ui::LAYER_TEXTURED); 91 window->Init(ui::LAYER_TEXTURED);
92 parent->AddChild(window); 92 parent->AddChild(window);
93 window->SetBounds(bounds); 93 window->SetBounds(bounds);
94 window->Show(); 94 window->Show();
95 return window; 95 return window;
96 } 96 }
97 97
98 aura::Window* GetCaptureWindow() { 98 aura::Window* GetCaptureWindow() {
99 return capture_controller_->capture_client()->GetCaptureWindow(); 99 return CaptureController::Get()->GetCaptureWindow();
100 }
101
102 aura::Window* GetSecondCaptureWindow() {
103 return second_capture_controller_->capture_client()->GetCaptureWindow();
104 } 100 }
105 101
106 std::unique_ptr<ScopedCaptureClient> capture_controller_; 102 std::unique_ptr<ScopedCaptureClient> capture_controller_;
107 std::unique_ptr<aura::WindowTreeHost> second_host_; 103 std::unique_ptr<aura::WindowTreeHost> second_host_;
108 std::unique_ptr<ScopedCaptureClient> second_capture_controller_; 104 std::unique_ptr<ScopedCaptureClient> second_capture_controller_;
109 105
110 DISALLOW_COPY_AND_ASSIGN(CaptureControllerTest); 106 DISALLOW_COPY_AND_ASSIGN(CaptureControllerTest);
111 }; 107 };
112 108
113 // Makes sure that internal details that are set on mouse down (such as 109 // Makes sure that internal details that are set on mouse down (such as
(...skipping 20 matching lines...) Expand all
134 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); 130 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler());
135 } 131 }
136 132
137 // Makes sure that when one window gets capture, it forces the release on the 133 // Makes sure that when one window gets capture, it forces the release on the
138 // other. This is needed has to be handled explicitly on Linux, and is a sanity 134 // other. This is needed has to be handled explicitly on Linux, and is a sanity
139 // check on Windows. 135 // check on Windows.
140 TEST_F(CaptureControllerTest, ResetOtherWindowCaptureOnCapture) { 136 TEST_F(CaptureControllerTest, ResetOtherWindowCaptureOnCapture) {
141 // Create a window inside the WindowEventDispatcher. 137 // Create a window inside the WindowEventDispatcher.
142 std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); 138 std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL));
143 w1->SetCapture(); 139 w1->SetCapture();
144 // Both capture clients should return the same capture window.
145 EXPECT_EQ(w1.get(), GetCaptureWindow()); 140 EXPECT_EQ(w1.get(), GetCaptureWindow());
146 EXPECT_EQ(w1.get(), GetSecondCaptureWindow());
147 141
148 // Build a window in the second WindowEventDispatcher and give it capture. 142 // Build a window in the second WindowEventDispatcher and give it capture.
149 // Both capture clients should return the same capture window.
150 std::unique_ptr<aura::Window> w2( 143 std::unique_ptr<aura::Window> w2(
151 CreateNormalWindow(2, second_host_->window(), NULL)); 144 CreateNormalWindow(2, second_host_->window(), NULL));
152 w2->SetCapture(); 145 w2->SetCapture();
153 EXPECT_EQ(w2.get(), GetCaptureWindow()); 146 EXPECT_EQ(w2.get(), GetCaptureWindow());
154 EXPECT_EQ(w2.get(), GetSecondCaptureWindow());
155 } 147 }
156 148
157 // Verifies the touch target for the WindowEventDispatcher gets reset on 149 // Verifies the touch target for the WindowEventDispatcher gets reset on
158 // releasing capture. 150 // releasing capture.
159 TEST_F(CaptureControllerTest, TouchTargetResetOnCaptureChange) { 151 TEST_F(CaptureControllerTest, TouchTargetResetOnCaptureChange) {
160 // Create a window inside the WindowEventDispatcher. 152 // Create a window inside the WindowEventDispatcher.
161 std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); 153 std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL));
162 ui::test::EventGenerator event_generator1(root_window()); 154 ui::test::EventGenerator event_generator1(root_window());
163 event_generator1.PressTouch(); 155 event_generator1.PressTouch();
164 w1->SetCapture(); 156 w1->SetCapture();
165 // Both capture clients should return the same capture window.
166 EXPECT_EQ(w1.get(), GetCaptureWindow()); 157 EXPECT_EQ(w1.get(), GetCaptureWindow());
167 EXPECT_EQ(w1.get(), GetSecondCaptureWindow());
168 158
169 // Build a window in the second WindowEventDispatcher and give it capture. 159 // Build a window in the second WindowEventDispatcher and give it capture.
170 // Both capture clients should return the same capture window.
171 std::unique_ptr<aura::Window> w2( 160 std::unique_ptr<aura::Window> w2(
172 CreateNormalWindow(2, second_host_->window(), NULL)); 161 CreateNormalWindow(2, second_host_->window(), NULL));
173 w2->SetCapture(); 162 w2->SetCapture();
174 EXPECT_EQ(w2.get(), GetCaptureWindow()); 163 EXPECT_EQ(w2.get(), GetCaptureWindow());
175 EXPECT_EQ(w2.get(), GetSecondCaptureWindow());
176 164
177 // Release capture on the window. Releasing capture should reset the touch 165 // Release capture on the window. Releasing capture should reset the touch
178 // target of the first WindowEventDispatcher (as it no longer contains the 166 // target of the first WindowEventDispatcher (as it no longer contains the
179 // capture target). 167 // capture target).
180 w2->ReleaseCapture(); 168 w2->ReleaseCapture();
181 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetCaptureWindow()); 169 EXPECT_EQ(nullptr, GetCaptureWindow());
182 EXPECT_EQ(static_cast<aura::Window*>(NULL), GetSecondCaptureWindow());
183 } 170 }
184 171
185 // Test that native capture is released properly when the window with capture 172 // Test that native capture is released properly when the window with capture
186 // is reparented to a different root window while it has capture. 173 // is reparented to a different root window while it has capture.
187 TEST_F(CaptureControllerTest, ReparentedWhileCaptured) { 174 TEST_F(CaptureControllerTest, ReparentedWhileCaptured) {
188 std::unique_ptr<TestCaptureDelegate> delegate(new TestCaptureDelegate); 175 std::unique_ptr<TestCaptureDelegate> delegate(new TestCaptureDelegate);
189 ScopedCaptureClient::TestApi(capture_controller_.get()) 176 ScopedCaptureClient::TestApi(capture_controller_.get())
190 .SetDelegate(delegate.get()); 177 .SetDelegate(delegate.get());
191 std::unique_ptr<TestCaptureDelegate> delegate2(new TestCaptureDelegate); 178 std::unique_ptr<TestCaptureDelegate> delegate2(new TestCaptureDelegate);
192 ScopedCaptureClient::TestApi(second_capture_controller_.get()) 179 ScopedCaptureClient::TestApi(second_capture_controller_.get())
193 .SetDelegate(delegate2.get()); 180 .SetDelegate(delegate2.get());
194 181
195 std::unique_ptr<aura::Window> w(CreateNormalWindow(1, root_window(), NULL)); 182 std::unique_ptr<aura::Window> w(CreateNormalWindow(1, root_window(), NULL));
196 w->SetCapture(); 183 w->SetCapture();
197 EXPECT_EQ(w.get(), GetCaptureWindow()); 184 EXPECT_EQ(w.get(), GetCaptureWindow());
198 EXPECT_EQ(w.get(), GetSecondCaptureWindow());
199 EXPECT_TRUE(delegate->HasNativeCapture()); 185 EXPECT_TRUE(delegate->HasNativeCapture());
200 EXPECT_FALSE(delegate2->HasNativeCapture()); 186 EXPECT_FALSE(delegate2->HasNativeCapture());
201 187
202 second_host_->window()->AddChild(w.get()); 188 second_host_->window()->AddChild(w.get());
203 EXPECT_EQ(w.get(), GetCaptureWindow()); 189 EXPECT_EQ(w.get(), GetCaptureWindow());
204 EXPECT_EQ(w.get(), GetSecondCaptureWindow());
205 EXPECT_TRUE(delegate->HasNativeCapture()); 190 EXPECT_TRUE(delegate->HasNativeCapture());
206 EXPECT_FALSE(delegate2->HasNativeCapture()); 191 EXPECT_FALSE(delegate2->HasNativeCapture());
207 192
208 w->ReleaseCapture(); 193 w->ReleaseCapture();
209 EXPECT_EQ(nullptr, GetCaptureWindow()); 194 EXPECT_EQ(nullptr, GetCaptureWindow());
210 EXPECT_EQ(nullptr, GetSecondCaptureWindow());
211 EXPECT_FALSE(delegate->HasNativeCapture()); 195 EXPECT_FALSE(delegate->HasNativeCapture());
212 EXPECT_FALSE(delegate2->HasNativeCapture()); 196 EXPECT_FALSE(delegate2->HasNativeCapture());
213 } 197 }
214 198
215 // A delegate that deletes a window on scroll cancel gesture event. 199 // A delegate that deletes a window on scroll cancel gesture event.
216 class GestureEventDeleteWindowOnScrollEnd 200 class GestureEventDeleteWindowOnScrollEnd
217 : public aura::test::TestWindowDelegate { 201 : public aura::test::TestWindowDelegate {
218 public: 202 public:
219 GestureEventDeleteWindowOnScrollEnd() {} 203 GestureEventDeleteWindowOnScrollEnd() {}
220 204
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ASSERT_NE(nullptr, capture_client); 256 ASSERT_NE(nullptr, capture_client);
273 EXPECT_EQ(nullptr, capture_client->GetCaptureWindow()); 257 EXPECT_EQ(nullptr, capture_client->GetCaptureWindow());
274 258
275 // Send a mouse click. We no longer hold capture so this should not crash. 259 // Send a mouse click. We no longer hold capture so this should not crash.
276 ui::MouseEvent mouse_press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 260 ui::MouseEvent mouse_press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
277 base::TimeTicks(), 0, 0); 261 base::TimeTicks(), 0, 0);
278 DispatchEventUsingWindowDispatcher(&mouse_press); 262 DispatchEventUsingWindowDispatcher(&mouse_press);
279 } 263 }
280 264
281 } // namespace wm 265 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/capture_controller.cc ('k') | ui/wm/core/wm_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698