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

Side by Side Diff: components/mus/ws/event_dispatcher_unittest.cc

Issue 1906623003: Convert //components/mus from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/focus_controller.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/mus/ws/event_dispatcher.h" 5 #include "components/mus/ws/event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 15 matching lines...) Expand all
26 namespace test { 26 namespace test {
27 namespace { 27 namespace {
28 28
29 // Identifies a generated event. 29 // Identifies a generated event.
30 struct DispatchedEventDetails { 30 struct DispatchedEventDetails {
31 DispatchedEventDetails() 31 DispatchedEventDetails()
32 : window(nullptr), in_nonclient_area(false), accelerator(nullptr) {} 32 : window(nullptr), in_nonclient_area(false), accelerator(nullptr) {}
33 33
34 ServerWindow* window; 34 ServerWindow* window;
35 bool in_nonclient_area; 35 bool in_nonclient_area;
36 scoped_ptr<ui::Event> event; 36 std::unique_ptr<ui::Event> event;
37 Accelerator* accelerator; 37 Accelerator* accelerator;
38 }; 38 };
39 39
40 class TestEventDispatcherDelegate : public EventDispatcherDelegate { 40 class TestEventDispatcherDelegate : public EventDispatcherDelegate {
41 public: 41 public:
42 explicit TestEventDispatcherDelegate(ServerWindow* root) 42 explicit TestEventDispatcherDelegate(ServerWindow* root)
43 : root_(root), 43 : root_(root),
44 focused_window_(nullptr), 44 focused_window_(nullptr),
45 lost_capture_window_(nullptr), 45 lost_capture_window_(nullptr),
46 last_accelerator_(0) {} 46 last_accelerator_(0) {}
47 ~TestEventDispatcherDelegate() override {} 47 ~TestEventDispatcherDelegate() override {}
48 48
49 uint32_t GetAndClearLastAccelerator() { 49 uint32_t GetAndClearLastAccelerator() {
50 uint32_t return_value = last_accelerator_; 50 uint32_t return_value = last_accelerator_;
51 last_accelerator_ = 0; 51 last_accelerator_ = 0;
52 return return_value; 52 return return_value;
53 } 53 }
54 54
55 // Returns the last dispatched event, or null if there are no more. 55 // Returns the last dispatched event, or null if there are no more.
56 scoped_ptr<DispatchedEventDetails> GetAndAdvanceDispatchedEventDetails() { 56 std::unique_ptr<DispatchedEventDetails>
57 GetAndAdvanceDispatchedEventDetails() {
57 if (dispatched_event_queue_.empty()) 58 if (dispatched_event_queue_.empty())
58 return nullptr; 59 return nullptr;
59 60
60 scoped_ptr<DispatchedEventDetails> details = 61 std::unique_ptr<DispatchedEventDetails> details =
61 std::move(dispatched_event_queue_.front()); 62 std::move(dispatched_event_queue_.front());
62 dispatched_event_queue_.pop(); 63 dispatched_event_queue_.pop();
63 return details; 64 return details;
64 } 65 }
65 66
66 ServerWindow* GetAndClearLastFocusedWindow() { 67 ServerWindow* GetAndClearLastFocusedWindow() {
67 ServerWindow* result = focused_window_; 68 ServerWindow* result = focused_window_;
68 focused_window_ = nullptr; 69 focused_window_ = nullptr;
69 return result; 70 return result;
70 } 71 }
(...skipping 17 matching lines...) Expand all
88 } 89 }
89 void SetNativeCapture() override {} 90 void SetNativeCapture() override {}
90 void ReleaseNativeCapture() override {} 91 void ReleaseNativeCapture() override {}
91 void OnServerWindowCaptureLost(ServerWindow* window) override { 92 void OnServerWindowCaptureLost(ServerWindow* window) override {
92 lost_capture_window_ = window; 93 lost_capture_window_ = window;
93 } 94 }
94 void DispatchInputEventToWindow(ServerWindow* target, 95 void DispatchInputEventToWindow(ServerWindow* target,
95 bool in_nonclient_area, 96 bool in_nonclient_area,
96 const ui::Event& event, 97 const ui::Event& event,
97 Accelerator* accelerator) override { 98 Accelerator* accelerator) override {
98 scoped_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); 99 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails);
99 details->window = target; 100 details->window = target;
100 details->in_nonclient_area = in_nonclient_area; 101 details->in_nonclient_area = in_nonclient_area;
101 details->event = ui::Event::Clone(event); 102 details->event = ui::Event::Clone(event);
102 details->accelerator = accelerator; 103 details->accelerator = accelerator;
103 dispatched_event_queue_.push(std::move(details)); 104 dispatched_event_queue_.push(std::move(details));
104 } 105 }
105 106
106 ServerWindow* root_; 107 ServerWindow* root_;
107 ServerWindow* focused_window_; 108 ServerWindow* focused_window_;
108 ServerWindow* lost_capture_window_; 109 ServerWindow* lost_capture_window_;
109 uint32_t last_accelerator_; 110 uint32_t last_accelerator_;
110 std::queue<scoped_ptr<DispatchedEventDetails>> dispatched_event_queue_; 111 std::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_;
111 112
112 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate); 113 DISALLOW_COPY_AND_ASSIGN(TestEventDispatcherDelegate);
113 }; 114 };
114 115
115 // Used by RunMouseEventTests(). Can identify up to two generated events. The 116 // Used by RunMouseEventTests(). Can identify up to two generated events. The
116 // first ServerWindow and two points identify the first event, the second 117 // first ServerWindow and two points identify the first event, the second
117 // ServerWindow and points identify the second event. If only one event is 118 // ServerWindow and points identify the second event. If only one event is
118 // generated set the second window to null. 119 // generated set the second window to null.
119 struct MouseEventTest { 120 struct MouseEventTest {
120 ui::MouseEvent input_event; 121 ui::MouseEvent input_event;
(...skipping 29 matching lines...) Expand all
150 size_t test_count) { 151 size_t test_count) {
151 for (size_t i = 0; i < test_count; ++i) { 152 for (size_t i = 0; i < test_count; ++i) {
152 const MouseEventTest& test = tests[i]; 153 const MouseEventTest& test = tests[i];
153 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) 154 ASSERT_FALSE(dispatcher_delegate->has_queued_events())
154 << " unexpected queued events before running " << i; 155 << " unexpected queued events before running " << i;
155 if (test.input_event.IsMouseWheelEvent()) 156 if (test.input_event.IsMouseWheelEvent())
156 dispatcher->ProcessEvent(test.input_event); 157 dispatcher->ProcessEvent(test.input_event);
157 else 158 else
158 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event)); 159 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event));
159 160
160 scoped_ptr<DispatchedEventDetails> details = 161 std::unique_ptr<DispatchedEventDetails> details =
161 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 162 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
162 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( 163 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
163 details.get(), test.expected_target_window1, 164 details.get(), test.expected_target_window1,
164 test.expected_root_location1, test.expected_location1)) 165 test.expected_root_location1, test.expected_location1))
165 << " details don't match " << i; 166 << " details don't match " << i;
166 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 167 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
167 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( 168 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
168 details.get(), test.expected_target_window2, 169 details.get(), test.expected_target_window2,
169 test.expected_root_location2, test.expected_location2)) 170 test.expected_root_location2, test.expected_location2))
170 << " details2 don't match " << i; 171 << " details2 don't match " << i;
(...skipping 14 matching lines...) Expand all
185 186
186 ServerWindow* root_window() { return root_window_.get(); } 187 ServerWindow* root_window() { return root_window_.get(); }
187 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { 188 TestEventDispatcherDelegate* test_event_dispatcher_delegate() {
188 return test_event_dispatcher_delegate_.get(); 189 return test_event_dispatcher_delegate_.get();
189 } 190 }
190 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } 191 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); }
191 192
192 bool AreAnyPointersDown() const; 193 bool AreAnyPointersDown() const;
193 // Deletes everything created during SetUp() 194 // Deletes everything created during SetUp()
194 void ClearSetup(); 195 void ClearSetup();
195 scoped_ptr<ServerWindow> CreateChildWindowWithParent(const WindowId& id, 196 std::unique_ptr<ServerWindow> CreateChildWindowWithParent(
196 ServerWindow* parent); 197 const WindowId& id,
198 ServerWindow* parent);
197 // Creates a window which is a child of |root_window_|. 199 // Creates a window which is a child of |root_window_|.
198 scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id); 200 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id);
199 bool IsMouseButtonDown() const; 201 bool IsMouseButtonDown() const;
200 bool IsWindowPointerTarget(ServerWindow* window) const; 202 bool IsWindowPointerTarget(ServerWindow* window) const;
201 int NumberPointerTargetsForWindow(ServerWindow* window) const; 203 int NumberPointerTargetsForWindow(ServerWindow* window) const;
202 204
203 protected: 205 protected:
204 // testing::Test: 206 // testing::Test:
205 void SetUp() override; 207 void SetUp() override;
206 208
207 private: 209 private:
208 scoped_ptr<TestServerWindowDelegate> window_delegate_; 210 std::unique_ptr<TestServerWindowDelegate> window_delegate_;
209 scoped_ptr<ServerWindow> root_window_; 211 std::unique_ptr<ServerWindow> root_window_;
210 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; 212 std::unique_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_;
211 scoped_ptr<EventDispatcher> event_dispatcher_; 213 std::unique_ptr<EventDispatcher> event_dispatcher_;
212 214
213 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); 215 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest);
214 }; 216 };
215 217
216 bool EventDispatcherTest::AreAnyPointersDown() const { 218 bool EventDispatcherTest::AreAnyPointersDown() const {
217 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); 219 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown();
218 } 220 }
219 221
220 void EventDispatcherTest::ClearSetup() { 222 void EventDispatcherTest::ClearSetup() {
221 window_delegate_.reset(); 223 window_delegate_.reset();
222 root_window_.reset(); 224 root_window_.reset();
223 test_event_dispatcher_delegate_.reset(); 225 test_event_dispatcher_delegate_.reset();
224 event_dispatcher_.reset(); 226 event_dispatcher_.reset();
225 } 227 }
226 228
227 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent( 229 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent(
228 const WindowId& id, 230 const WindowId& id,
229 ServerWindow* parent) { 231 ServerWindow* parent) {
230 scoped_ptr<ServerWindow> child(new ServerWindow(window_delegate_.get(), id)); 232 std::unique_ptr<ServerWindow> child(
233 new ServerWindow(window_delegate_.get(), id));
231 parent->Add(child.get()); 234 parent->Add(child.get());
232 child->SetVisible(true); 235 child->SetVisible(true);
233 EnableHitTest(child.get()); 236 EnableHitTest(child.get());
234 return child; 237 return child;
235 } 238 }
236 239
237 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( 240 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow(
238 const WindowId& id) { 241 const WindowId& id) {
239 return CreateChildWindowWithParent(id, root_window_.get()); 242 return CreateChildWindowWithParent(id, root_window_.get());
240 } 243 }
241 244
242 bool EventDispatcherTest::IsMouseButtonDown() const { 245 bool EventDispatcherTest::IsMouseButtonDown() const {
243 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); 246 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down();
244 } 247 }
245 248
246 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { 249 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const {
247 return EventDispatcherTestApi(event_dispatcher_.get()) 250 return EventDispatcherTestApi(event_dispatcher_.get())
(...skipping 15 matching lines...) Expand all
263 root_window_->SetVisible(true); 266 root_window_->SetVisible(true);
264 267
265 test_event_dispatcher_delegate_.reset( 268 test_event_dispatcher_delegate_.reset(
266 new TestEventDispatcherDelegate(root_window_.get())); 269 new TestEventDispatcherDelegate(root_window_.get()));
267 event_dispatcher_.reset( 270 event_dispatcher_.reset(
268 new EventDispatcher(test_event_dispatcher_delegate_.get())); 271 new EventDispatcher(test_event_dispatcher_delegate_.get()));
269 event_dispatcher_->set_root(root_window_.get()); 272 event_dispatcher_->set_root(root_window_.get());
270 } 273 }
271 274
272 TEST_F(EventDispatcherTest, ProcessEvent) { 275 TEST_F(EventDispatcherTest, ProcessEvent) {
273 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 276 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
274 277
275 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 278 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
276 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 279 child->SetBounds(gfx::Rect(10, 10, 20, 20));
277 280
278 // Send event that is over child. 281 // Send event that is over child.
279 const ui::PointerEvent ui_event(ui::MouseEvent( 282 const ui::PointerEvent ui_event(ui::MouseEvent(
280 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 283 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
281 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 284 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
282 event_dispatcher()->ProcessEvent(ui_event); 285 event_dispatcher()->ProcessEvent(ui_event);
283 286
284 scoped_ptr<DispatchedEventDetails> details = 287 std::unique_ptr<DispatchedEventDetails> details =
285 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 288 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
286 ASSERT_TRUE(details); 289 ASSERT_TRUE(details);
287 ASSERT_EQ(child.get(), details->window); 290 ASSERT_EQ(child.get(), details->window);
288 291
289 ASSERT_TRUE(details->event); 292 ASSERT_TRUE(details->event);
290 ASSERT_TRUE(details->event->IsPointerEvent()); 293 ASSERT_TRUE(details->event->IsPointerEvent());
291 294
292 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 295 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
293 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); 296 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
294 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); 297 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown); 385 mus::mojom::KeyboardCode::W, mus::mojom::kEventFlagControlDown);
383 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET; 386 matcher->accelerator_phase = mojom::AcceleratorPhase::POST_TARGET;
384 uint32_t accelerator_1 = 1; 387 uint32_t accelerator_1 = 1;
385 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); 388 dispatcher->AddAccelerator(accelerator_1, std::move(matcher));
386 389
387 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 390 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
388 // The post-target accelerator should be fired if there is no focused window. 391 // The post-target accelerator should be fired if there is no focused window.
389 dispatcher->ProcessEvent(key); 392 dispatcher->ProcessEvent(key);
390 EXPECT_EQ(accelerator_1, 393 EXPECT_EQ(accelerator_1,
391 event_dispatcher_delegate->GetAndClearLastAccelerator()); 394 event_dispatcher_delegate->GetAndClearLastAccelerator());
392 scoped_ptr<DispatchedEventDetails> details = 395 std::unique_ptr<DispatchedEventDetails> details =
393 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 396 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
394 EXPECT_FALSE(details); 397 EXPECT_FALSE(details);
395 398
396 // Set focused window for EventDispatcher dispatches key events. 399 // Set focused window for EventDispatcher dispatches key events.
397 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 400 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
398 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); 401 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get());
399 402
400 // With a focused window the event should be dispatched. 403 // With a focused window the event should be dispatched.
401 dispatcher->ProcessEvent(key); 404 dispatcher->ProcessEvent(key);
402 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 405 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
403 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 406 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
404 EXPECT_TRUE(details); 407 EXPECT_TRUE(details);
405 EXPECT_TRUE(details->accelerator); 408 EXPECT_TRUE(details->accelerator);
406 409
407 base::WeakPtr<Accelerator> accelerator_weak_ptr = 410 base::WeakPtr<Accelerator> accelerator_weak_ptr =
408 details->accelerator->GetWeakPtr(); 411 details->accelerator->GetWeakPtr();
409 dispatcher->RemoveAccelerator(accelerator_1); 412 dispatcher->RemoveAccelerator(accelerator_1);
410 EXPECT_FALSE(accelerator_weak_ptr); 413 EXPECT_FALSE(accelerator_weak_ptr);
411 414
412 // Post deletion there should be no accelerator 415 // Post deletion there should be no accelerator
413 dispatcher->ProcessEvent(key); 416 dispatcher->ProcessEvent(key);
414 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 417 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
415 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 418 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
416 EXPECT_TRUE(details); 419 EXPECT_TRUE(details);
417 EXPECT_FALSE(details->accelerator); 420 EXPECT_FALSE(details->accelerator);
418 } 421 }
419 422
420 TEST_F(EventDispatcherTest, Capture) { 423 TEST_F(EventDispatcherTest, Capture) {
421 ServerWindow* root = root_window(); 424 ServerWindow* root = root_window();
422 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 425 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
423 426
424 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 427 root->SetBounds(gfx::Rect(0, 0, 100, 100));
425 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 428 child->SetBounds(gfx::Rect(10, 10, 20, 20));
426 429
427 MouseEventTest tests[] = { 430 MouseEventTest tests[] = {
428 // Send a mouse down event over child. 431 // Send a mouse down event over child.
429 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), 432 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
430 gfx::Point(20, 25), base::TimeDelta(), 433 gfx::Point(20, 25), base::TimeDelta(),
431 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 434 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
432 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, 435 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
(...skipping 21 matching lines...) Expand all
454 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 457 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
455 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, 458 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root,
456 gfx::Point(50, 50), gfx::Point(50, 50)}, 459 gfx::Point(50, 50), gfx::Point(50, 50)},
457 460
458 }; 461 };
459 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 462 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
460 tests, arraysize(tests)); 463 tests, arraysize(tests));
461 } 464 }
462 465
463 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) { 466 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) {
464 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 467 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
465 468
466 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 469 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
467 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 470 child->SetBounds(gfx::Rect(10, 10, 20, 20));
468 471
469 MouseEventTest tests[] = { 472 MouseEventTest tests[] = {
470 // Send a mouse down event over child with a left mouse button 473 // Send a mouse down event over child with a left mouse button
471 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), 474 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
472 gfx::Point(20, 25), base::TimeDelta(), 475 gfx::Point(20, 25), base::TimeDelta(),
473 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 476 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
474 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, 477 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
(...skipping 22 matching lines...) Expand all
497 ui::EF_LEFT_MOUSE_BUTTON, 0), 500 ui::EF_LEFT_MOUSE_BUTTON, 0),
498 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, 501 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
499 gfx::Point(), gfx::Point()}, 502 gfx::Point(), gfx::Point()},
500 503
501 }; 504 };
502 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 505 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
503 tests, arraysize(tests)); 506 tests, arraysize(tests));
504 } 507 }
505 508
506 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) { 509 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) {
507 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 510 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
508 511
509 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 512 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
510 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 513 child->SetBounds(gfx::Rect(10, 10, 20, 20));
511 514
512 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); 515 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
513 516
514 TestEventDispatcherDelegate* event_dispatcher_delegate = 517 TestEventDispatcherDelegate* event_dispatcher_delegate =
515 test_event_dispatcher_delegate(); 518 test_event_dispatcher_delegate();
516 EventDispatcher* dispatcher = event_dispatcher(); 519 EventDispatcher* dispatcher = event_dispatcher();
517 520
518 // Start move loop by sending mouse event over non-client area. 521 // Start move loop by sending mouse event over non-client area.
519 const ui::PointerEvent press_event(ui::MouseEvent( 522 const ui::PointerEvent press_event(ui::MouseEvent(
520 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), 523 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
521 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 524 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
522 dispatcher->ProcessEvent(press_event); 525 dispatcher->ProcessEvent(press_event);
523 526
524 // Events should target child and be in the non-client area. 527 // Events should target child and be in the non-client area.
525 scoped_ptr<DispatchedEventDetails> details = 528 std::unique_ptr<DispatchedEventDetails> details =
526 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 529 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
527 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 530 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
528 ASSERT_TRUE(details); 531 ASSERT_TRUE(details);
529 ASSERT_EQ(child.get(), details->window); 532 ASSERT_EQ(child.get(), details->window);
530 EXPECT_TRUE(details->in_nonclient_area); 533 EXPECT_TRUE(details->in_nonclient_area);
531 534
532 // Move the mouse 5,6 pixels and target is the same. 535 // Move the mouse 5,6 pixels and target is the same.
533 const ui::PointerEvent move_event( 536 const ui::PointerEvent move_event(
534 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18), 537 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18),
535 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, 0)); 538 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, 0));
(...skipping 30 matching lines...) Expand all
566 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); 569 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
567 570
568 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 571 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
569 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 572 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
570 ASSERT_EQ(child.get(), details->window); 573 ASSERT_EQ(child.get(), details->window);
571 EXPECT_FALSE(details->in_nonclient_area); 574 EXPECT_FALSE(details->in_nonclient_area);
572 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 575 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
573 } 576 }
574 577
575 TEST_F(EventDispatcherTest, AdditionalClientArea) { 578 TEST_F(EventDispatcherTest, AdditionalClientArea) {
576 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 579 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
577 580
578 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 581 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
579 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 582 child->SetBounds(gfx::Rect(10, 10, 20, 20));
580 583
581 std::vector<gfx::Rect> additional_client_areas; 584 std::vector<gfx::Rect> additional_client_areas;
582 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); 585 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2));
583 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); 586 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas);
584 587
585 TestEventDispatcherDelegate* event_dispatcher_delegate = 588 TestEventDispatcherDelegate* event_dispatcher_delegate =
586 test_event_dispatcher_delegate(); 589 test_event_dispatcher_delegate();
587 // Press in the additional client area, it should go to the child. 590 // Press in the additional client area, it should go to the child.
588 const ui::PointerEvent press_event(ui::MouseEvent( 591 const ui::PointerEvent press_event(ui::MouseEvent(
589 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), 592 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11),
590 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 593 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
591 event_dispatcher()->ProcessEvent(press_event); 594 event_dispatcher()->ProcessEvent(press_event);
592 595
593 // Events should target child and be in the client area. 596 // Events should target child and be in the client area.
594 scoped_ptr<DispatchedEventDetails> details = 597 std::unique_ptr<DispatchedEventDetails> details =
595 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 598 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
596 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 599 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
597 ASSERT_EQ(child.get(), details->window); 600 ASSERT_EQ(child.get(), details->window);
598 EXPECT_FALSE(details->in_nonclient_area); 601 EXPECT_FALSE(details->in_nonclient_area);
599 } 602 }
600 603
601 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { 604 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) {
602 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 605 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
603 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 606 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
604 607
605 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 608 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
606 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 609 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
607 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 610 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
608 611
609 TestEventDispatcherDelegate* event_dispatcher_delegate = 612 TestEventDispatcherDelegate* event_dispatcher_delegate =
610 test_event_dispatcher_delegate(); 613 test_event_dispatcher_delegate();
611 EventDispatcher* dispatcher = event_dispatcher(); 614 EventDispatcher* dispatcher = event_dispatcher();
612 615
613 // Press on child1. First press event should change focus. 616 // Press on child1. First press event should change focus.
614 const ui::PointerEvent press_event(ui::MouseEvent( 617 const ui::PointerEvent press_event(ui::MouseEvent(
615 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), 618 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
616 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 619 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
617 dispatcher->ProcessEvent(press_event); 620 dispatcher->ProcessEvent(press_event);
618 scoped_ptr<DispatchedEventDetails> details = 621 std::unique_ptr<DispatchedEventDetails> details =
619 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 622 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
620 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 623 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
621 EXPECT_EQ(child1.get(), details->window); 624 EXPECT_EQ(child1.get(), details->window);
622 EXPECT_EQ(child1.get(), 625 EXPECT_EQ(child1.get(),
623 event_dispatcher_delegate->GetAndClearLastFocusedWindow()); 626 event_dispatcher_delegate->GetAndClearLastFocusedWindow());
624 627
625 // Press (with a different pointer id) on child2. Event should go to child2, 628 // Press (with a different pointer id) on child2. Event should go to child2,
626 // but focus should not change. 629 // but focus should not change.
627 const ui::PointerEvent touch_event(ui::TouchEvent( 630 const ui::PointerEvent touch_event(ui::TouchEvent(
628 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta())); 631 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta()));
629 dispatcher->ProcessEvent(touch_event); 632 dispatcher->ProcessEvent(touch_event);
630 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 633 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
631 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 634 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
632 EXPECT_EQ(child2.get(), details->window); 635 EXPECT_EQ(child2.get(), details->window);
633 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); 636 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow());
634 } 637 }
635 638
636 TEST_F(EventDispatcherTest, TwoPointersActive) { 639 TEST_F(EventDispatcherTest, TwoPointersActive) {
637 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 640 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
638 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 641 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
639 642
640 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 643 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
641 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 644 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
642 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 645 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
643 646
644 TestEventDispatcherDelegate* event_dispatcher_delegate = 647 TestEventDispatcherDelegate* event_dispatcher_delegate =
645 test_event_dispatcher_delegate(); 648 test_event_dispatcher_delegate();
646 EventDispatcher* dispatcher = event_dispatcher(); 649 EventDispatcher* dispatcher = event_dispatcher();
647 650
648 // Press on child1. 651 // Press on child1.
649 const ui::PointerEvent touch_event1(ui::TouchEvent( 652 const ui::PointerEvent touch_event1(ui::TouchEvent(
650 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); 653 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta()));
651 dispatcher->ProcessEvent(touch_event1); 654 dispatcher->ProcessEvent(touch_event1);
652 scoped_ptr<DispatchedEventDetails> details = 655 std::unique_ptr<DispatchedEventDetails> details =
653 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 656 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
654 EXPECT_EQ(child1.get(), details->window); 657 EXPECT_EQ(child1.get(), details->window);
655 658
656 // Drag over child2, child1 should get the drag. 659 // Drag over child2, child1 should get the drag.
657 const ui::PointerEvent drag_event1(ui::TouchEvent( 660 const ui::PointerEvent drag_event1(ui::TouchEvent(
658 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta())); 661 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta()));
659 dispatcher->ProcessEvent(drag_event1); 662 dispatcher->ProcessEvent(drag_event1);
660 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 663 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
661 EXPECT_EQ(child1.get(), details->window); 664 EXPECT_EQ(child1.get(), details->window);
662 665
(...skipping 23 matching lines...) Expand all
686 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 689 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
687 EXPECT_EQ(child1.get(), details->window); 690 EXPECT_EQ(child1.get(), details->window);
688 const ui::PointerEvent touch_event3(ui::TouchEvent( 691 const ui::PointerEvent touch_event3(ui::TouchEvent(
689 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta())); 692 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta()));
690 dispatcher->ProcessEvent(touch_event3); 693 dispatcher->ProcessEvent(touch_event3);
691 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 694 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
692 EXPECT_EQ(child2.get(), details->window); 695 EXPECT_EQ(child2.get(), details->window);
693 } 696 }
694 697
695 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { 698 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) {
696 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 699 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
697 700
698 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 701 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
699 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 702 child->SetBounds(gfx::Rect(10, 10, 20, 20));
700 703
701 TestEventDispatcherDelegate* event_dispatcher_delegate = 704 TestEventDispatcherDelegate* event_dispatcher_delegate =
702 test_event_dispatcher_delegate(); 705 test_event_dispatcher_delegate();
703 EventDispatcher* dispatcher = event_dispatcher(); 706 EventDispatcher* dispatcher = event_dispatcher();
704 707
705 // Press on child. 708 // Press on child.
706 const ui::PointerEvent touch_event1(ui::TouchEvent( 709 const ui::PointerEvent touch_event1(ui::TouchEvent(
707 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); 710 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta()));
708 dispatcher->ProcessEvent(touch_event1); 711 dispatcher->ProcessEvent(touch_event1);
709 scoped_ptr<DispatchedEventDetails> details = 712 std::unique_ptr<DispatchedEventDetails> details =
710 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 713 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
711 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 714 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
712 EXPECT_EQ(child.get(), details->window); 715 EXPECT_EQ(child.get(), details->window);
713 716
714 // Delete child, and continue the drag. Event should not be dispatched. 717 // Delete child, and continue the drag. Event should not be dispatched.
715 child.reset(); 718 child.reset();
716 719
717 const ui::PointerEvent drag_event1(ui::TouchEvent( 720 const ui::PointerEvent drag_event1(ui::TouchEvent(
718 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta())); 721 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta()));
719 dispatcher->ProcessEvent(drag_event1); 722 dispatcher->ProcessEvent(drag_event1);
720 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 723 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
721 EXPECT_EQ(nullptr, details.get()); 724 EXPECT_EQ(nullptr, details.get());
722 } 725 }
723 726
724 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { 727 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) {
725 ServerWindow* root = root_window(); 728 ServerWindow* root = root_window();
726 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 729 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
727 730
728 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 731 root->SetBounds(gfx::Rect(0, 0, 100, 100));
729 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 732 child->SetBounds(gfx::Rect(10, 10, 20, 20));
730 733
731 TestEventDispatcherDelegate* event_dispatcher_delegate = 734 TestEventDispatcherDelegate* event_dispatcher_delegate =
732 test_event_dispatcher_delegate(); 735 test_event_dispatcher_delegate();
733 EventDispatcher* dispatcher = event_dispatcher(); 736 EventDispatcher* dispatcher = event_dispatcher();
734 737
735 // Send event that is not over child. 738 // Send event that is not over child.
736 const ui::PointerEvent ui_event(ui::MouseEvent( 739 const ui::PointerEvent ui_event(ui::MouseEvent(
737 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9), 740 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9),
738 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 741 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
739 dispatcher->ProcessEvent(ui_event); 742 dispatcher->ProcessEvent(ui_event);
740 scoped_ptr<DispatchedEventDetails> details = 743 std::unique_ptr<DispatchedEventDetails> details =
741 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 744 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
742 ASSERT_EQ(root, details->window); 745 ASSERT_EQ(root, details->window);
743 746
744 // Release the mouse. 747 // Release the mouse.
745 const ui::PointerEvent release_event(ui::MouseEvent( 748 const ui::PointerEvent release_event(ui::MouseEvent(
746 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9), 749 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9),
747 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 750 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
748 dispatcher->ProcessEvent(release_event); 751 dispatcher->ProcessEvent(release_event);
749 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 752 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
750 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 753 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
(...skipping 13 matching lines...) Expand all
764 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 767 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
765 EXPECT_TRUE(details->in_nonclient_area); 768 EXPECT_TRUE(details->in_nonclient_area);
766 ASSERT_EQ(child.get(), details->window); 769 ASSERT_EQ(child.get(), details->window);
767 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 770 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
768 ASSERT_TRUE(details->event.get()); 771 ASSERT_TRUE(details->event.get());
769 ASSERT_TRUE(details->event->IsPointerEvent()); 772 ASSERT_TRUE(details->event->IsPointerEvent());
770 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); 773 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location());
771 } 774 }
772 775
773 TEST_F(EventDispatcherTest, WheelWhileDown) { 776 TEST_F(EventDispatcherTest, WheelWhileDown) {
774 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 777 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
775 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 778 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
776 779
777 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 780 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
778 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 781 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
779 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 782 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
780 783
781 MouseEventTest tests[] = { 784 MouseEventTest tests[] = {
782 // Send a mouse down event over child1. 785 // Send a mouse down event over child1.
783 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), 786 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15),
784 gfx::Point(15, 15), base::TimeDelta(), 787 gfx::Point(15, 15), base::TimeDelta(),
785 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 788 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
786 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, 789 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr,
787 gfx::Point(), gfx::Point()}, 790 gfx::Point(), gfx::Point()},
788 // Send mouse wheel over child2, should go to child1 as it has capture. 791 // Send mouse wheel over child2, should go to child1 as it has capture.
789 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), 792 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54),
790 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE, 793 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE,
791 ui::EF_NONE), 794 ui::EF_NONE),
792 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, 795 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr,
793 gfx::Point(), gfx::Point()}, 796 gfx::Point(), gfx::Point()},
794 }; 797 };
795 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 798 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
796 tests, arraysize(tests)); 799 tests, arraysize(tests));
797 } 800 }
798 801
799 // Tests that when explicit capture has been set that all events go to the 802 // Tests that when explicit capture has been set that all events go to the
800 // designated window, and that when capture is cleared, events find the 803 // designated window, and that when capture is cleared, events find the
801 // appropriate target window. 804 // appropriate target window.
802 TEST_F(EventDispatcherTest, SetExplicitCapture) { 805 TEST_F(EventDispatcherTest, SetExplicitCapture) {
803 ServerWindow* root = root_window(); 806 ServerWindow* root = root_window();
804 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 807 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
805 808
806 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 809 root->SetBounds(gfx::Rect(0, 0, 100, 100));
807 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 810 child->SetBounds(gfx::Rect(10, 10, 20, 20));
808 811
809 TestEventDispatcherDelegate* event_dispatcher_delegate = 812 TestEventDispatcherDelegate* event_dispatcher_delegate =
810 test_event_dispatcher_delegate(); 813 test_event_dispatcher_delegate();
811 EventDispatcher* dispatcher = event_dispatcher(); 814 EventDispatcher* dispatcher = event_dispatcher();
812 815
813 { 816 {
814 // Send all pointer events to the child. 817 // Send all pointer events to the child.
815 dispatcher->SetCaptureWindow(child.get(), false); 818 dispatcher->SetCaptureWindow(child.get(), false);
816 819
817 // The mouse press should go to the child even though its outside its 820 // The mouse press should go to the child even though its outside its
818 // bounds. 821 // bounds.
819 const ui::PointerEvent left_press_event(ui::MouseEvent( 822 const ui::PointerEvent left_press_event(ui::MouseEvent(
820 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 823 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
821 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 824 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
822 dispatcher->ProcessEvent(left_press_event); 825 dispatcher->ProcessEvent(left_press_event);
823 826
824 // Events should target child. 827 // Events should target child.
825 scoped_ptr<DispatchedEventDetails> details = 828 std::unique_ptr<DispatchedEventDetails> details =
826 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 829 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
827 830
828 ASSERT_TRUE(details); 831 ASSERT_TRUE(details);
829 ASSERT_EQ(child.get(), details->window); 832 ASSERT_EQ(child.get(), details->window);
830 EXPECT_FALSE(details->in_nonclient_area); 833 EXPECT_FALSE(details->in_nonclient_area);
831 EXPECT_TRUE(IsMouseButtonDown()); 834 EXPECT_TRUE(IsMouseButtonDown());
832 835
833 // The mouse down state should update while capture is set. 836 // The mouse down state should update while capture is set.
834 const ui::PointerEvent right_press_event(ui::MouseEvent( 837 const ui::PointerEvent right_press_event(ui::MouseEvent(
835 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 838 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 879
877 { 880 {
878 // Releasing capture and sending the same event will go to the root. 881 // Releasing capture and sending the same event will go to the root.
879 dispatcher->SetCaptureWindow(nullptr, false); 882 dispatcher->SetCaptureWindow(nullptr, false);
880 const ui::PointerEvent press_event(ui::MouseEvent( 883 const ui::PointerEvent press_event(ui::MouseEvent(
881 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 884 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
882 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 885 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
883 dispatcher->ProcessEvent(press_event); 886 dispatcher->ProcessEvent(press_event);
884 887
885 // Events should target the root. 888 // Events should target the root.
886 scoped_ptr<DispatchedEventDetails> details = 889 std::unique_ptr<DispatchedEventDetails> details =
887 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 890 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
888 891
889 ASSERT_TRUE(details); 892 ASSERT_TRUE(details);
890 ASSERT_EQ(root, details->window); 893 ASSERT_EQ(root, details->window);
891 } 894 }
892 } 895 }
893 896
894 // This test verifies that explicit capture overrides and resets implicit 897 // This test verifies that explicit capture overrides and resets implicit
895 // capture. 898 // capture.
896 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { 899 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) {
897 ServerWindow* root = root_window(); 900 ServerWindow* root = root_window();
898 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 901 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
899 902
900 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 903 root->SetBounds(gfx::Rect(0, 0, 100, 100));
901 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 904 child->SetBounds(gfx::Rect(10, 10, 20, 20));
902 905
903 TestEventDispatcherDelegate* event_dispatcher_delegate = 906 TestEventDispatcherDelegate* event_dispatcher_delegate =
904 test_event_dispatcher_delegate(); 907 test_event_dispatcher_delegate();
905 EventDispatcher* dispatcher = event_dispatcher(); 908 EventDispatcher* dispatcher = event_dispatcher();
906 909
907 // Run some implicit capture tests. 910 // Run some implicit capture tests.
908 MouseEventTest tests[] = { 911 MouseEventTest tests[] = {
(...skipping 25 matching lines...) Expand all
934 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests, 937 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests,
935 arraysize(tests)); 938 arraysize(tests));
936 939
937 // Add a second pointer target to the child. 940 // Add a second pointer target to the child.
938 { 941 {
939 const ui::PointerEvent touch_event(ui::TouchEvent( 942 const ui::PointerEvent touch_event(ui::TouchEvent(
940 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); 943 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta()));
941 dispatcher->ProcessEvent(touch_event); 944 dispatcher->ProcessEvent(touch_event);
942 } 945 }
943 946
944 scoped_ptr<DispatchedEventDetails> details = 947 std::unique_ptr<DispatchedEventDetails> details =
945 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 948 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
946 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 949 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
947 EXPECT_EQ(child.get(), details->window); 950 EXPECT_EQ(child.get(), details->window);
948 951
949 // Verify that no window has explicit capture and hence we did indeed do 952 // Verify that no window has explicit capture and hence we did indeed do
950 // implicit capture. 953 // implicit capture.
951 ASSERT_EQ(nullptr, dispatcher->capture_window()); 954 ASSERT_EQ(nullptr, dispatcher->capture_window());
952 955
953 // Give the root window explicit capture and verify input events over the 956 // Give the root window explicit capture and verify input events over the
954 // child go to the root instead. 957 // child go to the root instead.
(...skipping 30 matching lines...) Expand all
985 ServerWindow* root = root_window(); 988 ServerWindow* root = root_window();
986 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 989 root->SetBounds(gfx::Rect(0, 0, 100, 100));
987 990
988 EventDispatcher* dispatcher = event_dispatcher(); 991 EventDispatcher* dispatcher = event_dispatcher();
989 { 992 {
990 const ui::PointerEvent press_event(ui::MouseEvent( 993 const ui::PointerEvent press_event(ui::MouseEvent(
991 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), 994 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
992 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 995 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
993 dispatcher->ProcessEvent(press_event); 996 dispatcher->ProcessEvent(press_event);
994 997
995 scoped_ptr<DispatchedEventDetails> details = 998 std::unique_ptr<DispatchedEventDetails> details =
996 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 999 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
997 ASSERT_TRUE(details); 1000 ASSERT_TRUE(details);
998 ASSERT_EQ(root, details->window); 1001 ASSERT_EQ(root, details->window);
999 } 1002 }
1000 { 1003 {
1001 const ui::PointerEvent touch_event(ui::TouchEvent( 1004 const ui::PointerEvent touch_event(ui::TouchEvent(
1002 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); 1005 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta()));
1003 dispatcher->ProcessEvent(touch_event); 1006 dispatcher->ProcessEvent(touch_event);
1004 } 1007 }
1005 1008
1006 ASSERT_TRUE(AreAnyPointersDown()); 1009 ASSERT_TRUE(AreAnyPointersDown());
1007 ASSERT_TRUE(IsWindowPointerTarget(root)); 1010 ASSERT_TRUE(IsWindowPointerTarget(root));
1008 EXPECT_EQ(2, NumberPointerTargetsForWindow(root)); 1011 EXPECT_EQ(2, NumberPointerTargetsForWindow(root));
1009 1012
1010 // Setting the capture should clear the implicit pointers for the specified 1013 // Setting the capture should clear the implicit pointers for the specified
1011 // window. 1014 // window.
1012 dispatcher->SetCaptureWindow(root, true); 1015 dispatcher->SetCaptureWindow(root, true);
1013 EXPECT_FALSE(AreAnyPointersDown()); 1016 EXPECT_FALSE(AreAnyPointersDown());
1014 EXPECT_FALSE(IsWindowPointerTarget(root)); 1017 EXPECT_FALSE(IsWindowPointerTarget(root));
1015 } 1018 }
1016 1019
1017 // Tests that when explicit capture is changed, that the previous window with 1020 // Tests that when explicit capture is changed, that the previous window with
1018 // capture is no longer being observed. 1021 // capture is no longer being observed.
1019 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { 1022 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) {
1020 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); 1023 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
1021 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); 1024 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
1022 1025
1023 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1026 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1024 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 1027 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
1025 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 1028 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
1026 1029
1027 EventDispatcher* dispatcher = event_dispatcher(); 1030 EventDispatcher* dispatcher = event_dispatcher();
1028 ASSERT_FALSE(AreAnyPointersDown()); 1031 ASSERT_FALSE(AreAnyPointersDown());
1029 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); 1032 ASSERT_FALSE(IsWindowPointerTarget(child1.get()));
1030 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); 1033 ASSERT_FALSE(IsWindowPointerTarget(child2.get()));
1031 dispatcher->SetCaptureWindow(child1.get(), false); 1034 dispatcher->SetCaptureWindow(child1.get(), false);
1032 dispatcher->SetCaptureWindow(child2.get(), false); 1035 dispatcher->SetCaptureWindow(child2.get(), false);
1033 EXPECT_EQ(child1.get(), 1036 EXPECT_EQ(child1.get(),
1034 test_event_dispatcher_delegate()->lost_capture_window()); 1037 test_event_dispatcher_delegate()->lost_capture_window());
1035 1038
1036 // If observing does not stop during the capture update this crashes. 1039 // If observing does not stop during the capture update this crashes.
1037 child1->AddObserver(dispatcher); 1040 child1->AddObserver(dispatcher);
1038 } 1041 }
1039 1042
1040 // Tests that destroying a window with explicit capture clears the capture 1043 // Tests that destroying a window with explicit capture clears the capture
1041 // state. 1044 // state.
1042 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { 1045 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) {
1043 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1046 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1044 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1047 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1045 1048
1046 EventDispatcher* dispatcher = event_dispatcher(); 1049 EventDispatcher* dispatcher = event_dispatcher();
1047 dispatcher->SetCaptureWindow(child.get(), false); 1050 dispatcher->SetCaptureWindow(child.get(), false);
1048 EXPECT_EQ(child.get(), dispatcher->capture_window()); 1051 EXPECT_EQ(child.get(), dispatcher->capture_window());
1049 1052
1050 ServerWindow* lost_capture_window = child.get(); 1053 ServerWindow* lost_capture_window = child.get();
1051 child.reset(); 1054 child.reset();
1052 EXPECT_EQ(nullptr, dispatcher->capture_window()); 1055 EXPECT_EQ(nullptr, dispatcher->capture_window());
1053 EXPECT_EQ(lost_capture_window, 1056 EXPECT_EQ(lost_capture_window,
(...skipping 13 matching lines...) Expand all
1067 1070
1068 TestEventDispatcherDelegate* event_dispatcher_delegate = 1071 TestEventDispatcherDelegate* event_dispatcher_delegate =
1069 test_event_dispatcher_delegate(); 1072 test_event_dispatcher_delegate();
1070 // Press in the client area, it should be marked as non client. 1073 // Press in the client area, it should be marked as non client.
1071 const ui::PointerEvent press_event(ui::MouseEvent( 1074 const ui::PointerEvent press_event(ui::MouseEvent(
1072 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6), 1075 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6),
1073 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1076 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1074 event_dispatcher()->ProcessEvent(press_event); 1077 event_dispatcher()->ProcessEvent(press_event);
1075 1078
1076 // Events should target child and be in the client area. 1079 // Events should target child and be in the client area.
1077 scoped_ptr<DispatchedEventDetails> details = 1080 std::unique_ptr<DispatchedEventDetails> details =
1078 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1081 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1079 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 1082 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
1080 ASSERT_EQ(root, details->window); 1083 ASSERT_EQ(root, details->window);
1081 EXPECT_TRUE(details->in_nonclient_area); 1084 EXPECT_TRUE(details->in_nonclient_area);
1082 } 1085 }
1083 1086
1084 TEST_F(EventDispatcherTest, ProcessPointerEvents) { 1087 TEST_F(EventDispatcherTest, ProcessPointerEvents) {
1085 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1088 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1086 1089
1087 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1090 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1088 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1091 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1089 1092
1090 { 1093 {
1091 const ui::PointerEvent pointer_event(ui::MouseEvent( 1094 const ui::PointerEvent pointer_event(ui::MouseEvent(
1092 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 1095 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
1093 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1096 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1094 event_dispatcher()->ProcessEvent(pointer_event); 1097 event_dispatcher()->ProcessEvent(pointer_event);
1095 1098
1096 scoped_ptr<DispatchedEventDetails> details = 1099 std::unique_ptr<DispatchedEventDetails> details =
1097 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1100 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1098 ASSERT_TRUE(details); 1101 ASSERT_TRUE(details);
1099 ASSERT_EQ(child.get(), details->window); 1102 ASSERT_EQ(child.get(), details->window);
1100 1103
1101 ASSERT_TRUE(details->event); 1104 ASSERT_TRUE(details->event);
1102 ASSERT_TRUE(details->event->IsPointerEvent()); 1105 ASSERT_TRUE(details->event->IsPointerEvent());
1103 1106
1104 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1107 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1105 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); 1108 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
1106 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); 1109 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
1107 } 1110 }
1108 1111
1109 { 1112 {
1110 const int touch_id = 3; 1113 const int touch_id = 3;
1111 const ui::PointerEvent pointer_event( 1114 const ui::PointerEvent pointer_event(
1112 ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), touch_id, 1115 ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), touch_id,
1113 base::TimeDelta())); 1116 base::TimeDelta()));
1114 event_dispatcher()->ProcessEvent(pointer_event); 1117 event_dispatcher()->ProcessEvent(pointer_event);
1115 1118
1116 scoped_ptr<DispatchedEventDetails> details = 1119 std::unique_ptr<DispatchedEventDetails> details =
1117 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1120 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1118 ASSERT_TRUE(details); 1121 ASSERT_TRUE(details);
1119 ASSERT_EQ(child.get(), details->window); 1122 ASSERT_EQ(child.get(), details->window);
1120 1123
1121 ASSERT_TRUE(details->event); 1124 ASSERT_TRUE(details->event);
1122 ASSERT_TRUE(details->event->IsPointerEvent()); 1125 ASSERT_TRUE(details->event->IsPointerEvent());
1123 1126
1124 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1127 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1125 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); 1128 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location());
1126 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); 1129 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location());
1127 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); 1130 EXPECT_EQ(touch_id, dispatched_event->pointer_id());
1128 } 1131 }
1129 } 1132 }
1130 1133
1131 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { 1134 TEST_F(EventDispatcherTest, ResetClearsPointerDown) {
1132 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); 1135 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1133 1136
1134 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1137 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1135 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1138 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1136 1139
1137 // Send event that is over child. 1140 // Send event that is over child.
1138 const ui::PointerEvent ui_event(ui::MouseEvent( 1141 const ui::PointerEvent ui_event(ui::MouseEvent(
1139 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 1142 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
1140 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1143 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1141 event_dispatcher()->ProcessEvent(ui_event); 1144 event_dispatcher()->ProcessEvent(ui_event);
1142 1145
1143 scoped_ptr<DispatchedEventDetails> details = 1146 std::unique_ptr<DispatchedEventDetails> details =
1144 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1147 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1145 ASSERT_TRUE(details); 1148 ASSERT_TRUE(details);
1146 ASSERT_EQ(child.get(), details->window); 1149 ASSERT_EQ(child.get(), details->window);
1147 1150
1148 EXPECT_TRUE(AreAnyPointersDown()); 1151 EXPECT_TRUE(AreAnyPointersDown());
1149 1152
1150 event_dispatcher()->Reset(); 1153 event_dispatcher()->Reset();
1151 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); 1154 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
1152 EXPECT_FALSE(AreAnyPointersDown()); 1155 EXPECT_FALSE(AreAnyPointersDown());
1153 } 1156 }
1154 1157
1155 TEST_F(EventDispatcherTest, ResetClearsCapture) { 1158 TEST_F(EventDispatcherTest, ResetClearsCapture) {
1156 ServerWindow* root = root_window(); 1159 ServerWindow* root = root_window();
1157 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 1160 root->SetBounds(gfx::Rect(0, 0, 100, 100));
1158 1161
1159 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); 1162 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
1160 EventDispatcher* dispatcher = event_dispatcher(); 1163 EventDispatcher* dispatcher = event_dispatcher();
1161 dispatcher->SetCaptureWindow(root, true); 1164 dispatcher->SetCaptureWindow(root, true);
1162 1165
1163 event_dispatcher()->Reset(); 1166 event_dispatcher()->Reset();
1164 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); 1167 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
1165 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); 1168 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1166 } 1169 }
1167 1170
1168 // Tests that events on a modal parent target the modal child. 1171 // Tests that events on a modal parent target the modal child.
1169 TEST_F(EventDispatcherTest, ModalWindowEventOnModalParent) { 1172 TEST_F(EventDispatcherTest, ModalWindowEventOnModalParent) {
1170 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1173 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1171 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1174 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1172 1175
1173 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1176 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1174 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1177 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1175 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1178 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1176 1179
1177 w1->AddTransientWindow(w2.get()); 1180 w1->AddTransientWindow(w2.get());
1178 w2->SetModal(); 1181 w2->SetModal();
1179 1182
1180 // Send event that is over |w1|. 1183 // Send event that is over |w1|.
1181 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1184 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1182 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), 1185 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1183 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1186 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1184 event_dispatcher()->ProcessEvent(mouse_pressed); 1187 event_dispatcher()->ProcessEvent(mouse_pressed);
1185 1188
1186 scoped_ptr<DispatchedEventDetails> details = 1189 std::unique_ptr<DispatchedEventDetails> details =
1187 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1190 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1188 ASSERT_TRUE(details); 1191 ASSERT_TRUE(details);
1189 EXPECT_EQ(w2.get(), details->window); 1192 EXPECT_EQ(w2.get(), details->window);
1190 EXPECT_TRUE(details->in_nonclient_area); 1193 EXPECT_TRUE(details->in_nonclient_area);
1191 1194
1192 ASSERT_TRUE(details->event); 1195 ASSERT_TRUE(details->event);
1193 ASSERT_TRUE(details->event->IsPointerEvent()); 1196 ASSERT_TRUE(details->event->IsPointerEvent());
1194 1197
1195 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1198 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1196 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); 1199 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
1197 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location()); 1200 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location());
1198 } 1201 }
1199 1202
1200 // Tests that events on a modal child target the modal child itself. 1203 // Tests that events on a modal child target the modal child itself.
1201 TEST_F(EventDispatcherTest, ModalWindowEventOnModalChild) { 1204 TEST_F(EventDispatcherTest, ModalWindowEventOnModalChild) {
1202 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1205 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1203 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1206 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1204 1207
1205 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1208 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1206 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1209 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1207 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1210 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1208 1211
1209 w1->AddTransientWindow(w2.get()); 1212 w1->AddTransientWindow(w2.get());
1210 w2->SetModal(); 1213 w2->SetModal();
1211 1214
1212 // Send event that is over |w2|. 1215 // Send event that is over |w2|.
1213 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1216 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1214 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15), 1217 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15),
1215 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1218 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1216 event_dispatcher()->ProcessEvent(mouse_pressed); 1219 event_dispatcher()->ProcessEvent(mouse_pressed);
1217 1220
1218 scoped_ptr<DispatchedEventDetails> details = 1221 std::unique_ptr<DispatchedEventDetails> details =
1219 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1222 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1220 ASSERT_TRUE(details); 1223 ASSERT_TRUE(details);
1221 EXPECT_EQ(w2.get(), details->window); 1224 EXPECT_EQ(w2.get(), details->window);
1222 EXPECT_FALSE(details->in_nonclient_area); 1225 EXPECT_FALSE(details->in_nonclient_area);
1223 1226
1224 ASSERT_TRUE(details->event); 1227 ASSERT_TRUE(details->event);
1225 ASSERT_TRUE(details->event->IsPointerEvent()); 1228 ASSERT_TRUE(details->event->IsPointerEvent());
1226 1229
1227 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1230 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1228 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location()); 1231 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location());
1229 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); 1232 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1230 } 1233 }
1231 1234
1232 // Tests that events on an unrelated window are not affected by the modal 1235 // Tests that events on an unrelated window are not affected by the modal
1233 // window. 1236 // window.
1234 TEST_F(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) { 1237 TEST_F(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) {
1235 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1238 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1236 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1239 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1237 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); 1240 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6));
1238 1241
1239 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1242 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1240 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1243 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1241 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1244 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1242 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); 1245 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1243 1246
1244 w1->AddTransientWindow(w2.get()); 1247 w1->AddTransientWindow(w2.get());
1245 w2->SetModal(); 1248 w2->SetModal();
1246 1249
1247 // Send event that is over |w3|. 1250 // Send event that is over |w3|.
1248 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1251 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1249 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15), 1252 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15),
1250 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1253 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1251 event_dispatcher()->ProcessEvent(mouse_pressed); 1254 event_dispatcher()->ProcessEvent(mouse_pressed);
1252 1255
1253 scoped_ptr<DispatchedEventDetails> details = 1256 std::unique_ptr<DispatchedEventDetails> details =
1254 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1257 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1255 ASSERT_TRUE(details); 1258 ASSERT_TRUE(details);
1256 EXPECT_EQ(w3.get(), details->window); 1259 EXPECT_EQ(w3.get(), details->window);
1257 EXPECT_FALSE(details->in_nonclient_area); 1260 EXPECT_FALSE(details->in_nonclient_area);
1258 1261
1259 ASSERT_TRUE(details->event); 1262 ASSERT_TRUE(details->event);
1260 ASSERT_TRUE(details->event->IsPointerEvent()); 1263 ASSERT_TRUE(details->event->IsPointerEvent());
1261 1264
1262 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1265 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1263 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location()); 1266 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location());
1264 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); 1267 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1265 } 1268 }
1266 1269
1267 // Tests that events events on a descendant of a modal parent target the modal 1270 // Tests that events events on a descendant of a modal parent target the modal
1268 // child. 1271 // child.
1269 TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) { 1272 TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) {
1270 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1273 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1271 scoped_ptr<ServerWindow> w11 = 1274 std::unique_ptr<ServerWindow> w11 =
1272 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); 1275 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1273 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1276 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1274 1277
1275 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1278 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1276 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1279 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1277 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1280 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1278 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1281 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1279 1282
1280 w1->AddTransientWindow(w2.get()); 1283 w1->AddTransientWindow(w2.get());
1281 w2->SetModal(); 1284 w2->SetModal();
1282 1285
1283 // Send event that is over |w11|. 1286 // Send event that is over |w11|.
1284 const ui::PointerEvent mouse_pressed(ui::MouseEvent( 1287 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1285 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25), 1288 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25),
1286 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1289 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1287 event_dispatcher()->ProcessEvent(mouse_pressed); 1290 event_dispatcher()->ProcessEvent(mouse_pressed);
1288 1291
1289 scoped_ptr<DispatchedEventDetails> details = 1292 std::unique_ptr<DispatchedEventDetails> details =
1290 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); 1293 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1291 ASSERT_TRUE(details); 1294 ASSERT_TRUE(details);
1292 EXPECT_EQ(w2.get(), details->window); 1295 EXPECT_EQ(w2.get(), details->window);
1293 EXPECT_TRUE(details->in_nonclient_area); 1296 EXPECT_TRUE(details->in_nonclient_area);
1294 1297
1295 ASSERT_TRUE(details->event); 1298 ASSERT_TRUE(details->event);
1296 ASSERT_TRUE(details->event->IsPointerEvent()); 1299 ASSERT_TRUE(details->event->IsPointerEvent());
1297 1300
1298 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1301 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1299 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); 1302 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
1300 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); 1303 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
1301 } 1304 }
1302 1305
1303 1306
1304 // Tests that setting capture to a descendant of a modal parent fails. 1307 // Tests that setting capture to a descendant of a modal parent fails.
1305 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { 1308 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) {
1306 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1309 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1307 scoped_ptr<ServerWindow> w11 = 1310 std::unique_ptr<ServerWindow> w11 =
1308 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); 1311 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1309 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1312 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1310 1313
1311 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1314 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1312 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1315 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1313 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); 1316 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1314 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1317 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1315 1318
1316 w1->AddTransientWindow(w2.get()); 1319 w1->AddTransientWindow(w2.get());
1317 w2->SetModal(); 1320 w2->SetModal();
1318 1321
1319 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false)); 1322 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false));
1320 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); 1323 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1321 } 1324 }
1322 1325
1323 // Tests that setting capture to a window unrelated to a modal parent works. 1326 // Tests that setting capture to a window unrelated to a modal parent works.
1324 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { 1327 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) {
1325 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); 1328 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1326 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); 1329 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1327 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); 1330 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6));
1328 1331
1329 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1332 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1330 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); 1333 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1331 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); 1334 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1332 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); 1335 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1333 1336
1334 w1->AddTransientWindow(w2.get()); 1337 w1->AddTransientWindow(w2.get());
1335 w2->SetModal(); 1338 w2->SetModal();
1336 1339
1337 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); 1340 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false));
1338 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); 1341 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
1339 } 1342 }
1340 1343
1341 } // namespace test 1344 } // namespace test
1342 } // namespace ws 1345 } // namespace ws
1343 } // namespace mus 1346 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/focus_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698