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

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

Issue 1759523002: mus: Server-side implementation of modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More cleanup Created 4 years, 9 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
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 ServerWindow* root_window() { return root_window_.get(); } 175 ServerWindow* root_window() { return root_window_.get(); }
176 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { 176 TestEventDispatcherDelegate* test_event_dispatcher_delegate() {
177 return test_event_dispatcher_delegate_.get(); 177 return test_event_dispatcher_delegate_.get();
178 } 178 }
179 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } 179 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); }
180 180
181 bool AreAnyPointersDown() const; 181 bool AreAnyPointersDown() const;
182 // Deletes everything created during SetUp() 182 // Deletes everything created during SetUp()
183 void ClearSetup(); 183 void ClearSetup();
184 // Creates a window which is a child of |root_window_|. It is not owned by 184 scoped_ptr<ServerWindow> CreateChildWindowWithParent(const WindowId& id,
185 // EventDispatcherTest. 185 ServerWindow* parent);
186 ServerWindow* CreateChildWindow(const WindowId& id); 186 // Creates a window which is a child of |root_window_|.
187 scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id);
187 bool IsMouseButtonDown() const; 188 bool IsMouseButtonDown() const;
188 bool IsWindowPointerTarget(ServerWindow* window) const; 189 bool IsWindowPointerTarget(ServerWindow* window) const;
189 int NumberPointerTargetsForWindow(ServerWindow* window) const; 190 int NumberPointerTargetsForWindow(ServerWindow* window) const;
190 191
191 protected: 192 protected:
192 // testing::Test: 193 // testing::Test:
193 void SetUp() override; 194 void SetUp() override;
194 195
195 private: 196 private:
196 scoped_ptr<TestServerWindowDelegate> window_delegate_; 197 scoped_ptr<TestServerWindowDelegate> window_delegate_;
197 scoped_ptr<ServerWindow> root_window_; 198 scoped_ptr<ServerWindow> root_window_;
198 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; 199 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_;
199 scoped_ptr<EventDispatcher> event_dispatcher_; 200 scoped_ptr<EventDispatcher> event_dispatcher_;
200 201
201 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); 202 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest);
202 }; 203 };
203 204
204 bool EventDispatcherTest::AreAnyPointersDown() const { 205 bool EventDispatcherTest::AreAnyPointersDown() const {
205 return event_dispatcher_->AreAnyPointersDown(); 206 return event_dispatcher_->AreAnyPointersDown();
206 } 207 }
207 208
208 void EventDispatcherTest::ClearSetup() { 209 void EventDispatcherTest::ClearSetup() {
209 window_delegate_.reset(); 210 window_delegate_.reset();
210 root_window_.reset(); 211 root_window_.reset();
211 test_event_dispatcher_delegate_.reset(); 212 test_event_dispatcher_delegate_.reset();
212 event_dispatcher_.reset(); 213 event_dispatcher_.reset();
213 } 214 }
214 215
215 ServerWindow* EventDispatcherTest::CreateChildWindow(const WindowId& id) { 216 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent(
216 ServerWindow* child = new ServerWindow(window_delegate_.get(), id); 217 const WindowId& id,
217 root_window_->Add(child); 218 ServerWindow* parent) {
219 scoped_ptr<ServerWindow> child(new ServerWindow(window_delegate_.get(), id));
220 parent->Add(child.get());
218 child->SetVisible(true); 221 child->SetVisible(true);
219 EnableHitTest(child); 222 EnableHitTest(child.get());
220 return child; 223 return child;
221 } 224 }
222 225
226 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow(
227 const WindowId& id) {
228 return CreateChildWindowWithParent(id, root_window_.get());
229 }
230
223 bool EventDispatcherTest::IsMouseButtonDown() const { 231 bool EventDispatcherTest::IsMouseButtonDown() const {
224 return event_dispatcher_->mouse_button_down_; 232 return event_dispatcher_->mouse_button_down_;
225 } 233 }
226 234
227 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { 235 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const {
228 return event_dispatcher_->IsObservingWindow(window); 236 return event_dispatcher_->IsObservingWindow(window);
229 } 237 }
230 238
231 int EventDispatcherTest::NumberPointerTargetsForWindow( 239 int EventDispatcherTest::NumberPointerTargetsForWindow(
232 ServerWindow* window) const { 240 ServerWindow* window) const {
(...skipping 13 matching lines...) Expand all
246 root_window_->SetVisible(true); 254 root_window_->SetVisible(true);
247 255
248 test_event_dispatcher_delegate_.reset( 256 test_event_dispatcher_delegate_.reset(
249 new TestEventDispatcherDelegate(root_window_.get())); 257 new TestEventDispatcherDelegate(root_window_.get()));
250 event_dispatcher_.reset( 258 event_dispatcher_.reset(
251 new EventDispatcher(test_event_dispatcher_delegate_.get())); 259 new EventDispatcher(test_event_dispatcher_delegate_.get()));
252 event_dispatcher_->set_root(root_window_.get()); 260 event_dispatcher_->set_root(root_window_.get());
253 } 261 }
254 262
255 TEST_F(EventDispatcherTest, ProcessEvent) { 263 TEST_F(EventDispatcherTest, ProcessEvent) {
256 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 264 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
257 265
258 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 266 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
259 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 267 child->SetBounds(gfx::Rect(10, 10, 20, 20));
260 268
261 // Send event that is over child. 269 // Send event that is over child.
262 const ui::PointerEvent ui_event(ui::MouseEvent( 270 const ui::PointerEvent ui_event(ui::MouseEvent(
263 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 271 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
264 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 272 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
265 event_dispatcher()->ProcessEvent(ui_event); 273 event_dispatcher()->ProcessEvent(ui_event);
266 274
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 378 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
371 dispatcher->ProcessEvent(key); 379 dispatcher->ProcessEvent(key);
372 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); 380 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
373 381
374 // TODO(jonross): Update this test to include actual invokation of PostTarget 382 // TODO(jonross): Update this test to include actual invokation of PostTarget
375 // acceleratos once events acking includes consuming. 383 // acceleratos once events acking includes consuming.
376 } 384 }
377 385
378 TEST_F(EventDispatcherTest, Capture) { 386 TEST_F(EventDispatcherTest, Capture) {
379 ServerWindow* root = root_window(); 387 ServerWindow* root = root_window();
380 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 388 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
381 389
382 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 390 root->SetBounds(gfx::Rect(0, 0, 100, 100));
383 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 391 child->SetBounds(gfx::Rect(10, 10, 20, 20));
384 392
385 MouseEventTest tests[] = { 393 MouseEventTest tests[] = {
386 // Send a mouse down event over child. 394 // Send a mouse down event over child.
387 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), 395 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
388 gfx::Point(20, 25), base::TimeDelta(), 396 gfx::Point(20, 25), base::TimeDelta(),
389 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 397 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
390 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, 398 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
(...skipping 21 matching lines...) Expand all
412 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 420 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
413 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, 421 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root,
414 gfx::Point(50, 50), gfx::Point(50, 50)}, 422 gfx::Point(50, 50), gfx::Point(50, 50)},
415 423
416 }; 424 };
417 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 425 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
418 tests, arraysize(tests)); 426 tests, arraysize(tests));
419 } 427 }
420 428
421 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) { 429 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) {
422 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 430 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
423 431
424 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 432 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
425 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 433 child->SetBounds(gfx::Rect(10, 10, 20, 20));
426 434
427 MouseEventTest tests[] = { 435 MouseEventTest tests[] = {
428 // Send a mouse down event over child with a left mouse button 436 // Send a mouse down event over child with a left mouse button
429 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), 437 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
430 gfx::Point(20, 25), base::TimeDelta(), 438 gfx::Point(20, 25), base::TimeDelta(),
431 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 439 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
432 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, 440 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
(...skipping 22 matching lines...) Expand all
455 ui::EF_LEFT_MOUSE_BUTTON, 0), 463 ui::EF_LEFT_MOUSE_BUTTON, 0),
456 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, 464 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
457 gfx::Point(), gfx::Point()}, 465 gfx::Point(), gfx::Point()},
458 466
459 }; 467 };
460 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 468 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
461 tests, arraysize(tests)); 469 tests, arraysize(tests));
462 } 470 }
463 471
464 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) { 472 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) {
465 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 473 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
466 474
467 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 475 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
468 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 476 child->SetBounds(gfx::Rect(10, 10, 20, 20));
469 477
470 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); 478 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
471 479
472 TestEventDispatcherDelegate* event_dispatcher_delegate = 480 TestEventDispatcherDelegate* event_dispatcher_delegate =
473 test_event_dispatcher_delegate(); 481 test_event_dispatcher_delegate();
474 EventDispatcher* dispatcher = event_dispatcher(); 482 EventDispatcher* dispatcher = event_dispatcher();
475 483
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); 532 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
525 533
526 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 534 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
527 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 535 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
528 ASSERT_EQ(child.get(), details->window); 536 ASSERT_EQ(child.get(), details->window);
529 EXPECT_FALSE(details->in_nonclient_area); 537 EXPECT_FALSE(details->in_nonclient_area);
530 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 538 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
531 } 539 }
532 540
533 TEST_F(EventDispatcherTest, AdditionalClientArea) { 541 TEST_F(EventDispatcherTest, AdditionalClientArea) {
534 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 542 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
535 543
536 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 544 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
537 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 545 child->SetBounds(gfx::Rect(10, 10, 20, 20));
538 546
539 std::vector<gfx::Rect> additional_client_areas; 547 std::vector<gfx::Rect> additional_client_areas;
540 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); 548 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2));
541 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); 549 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas);
542 550
543 TestEventDispatcherDelegate* event_dispatcher_delegate = 551 TestEventDispatcherDelegate* event_dispatcher_delegate =
544 test_event_dispatcher_delegate(); 552 test_event_dispatcher_delegate();
545 // Press in the additional client area, it should go to the child. 553 // Press in the additional client area, it should go to the child.
546 const ui::PointerEvent press_event(ui::MouseEvent( 554 const ui::PointerEvent press_event(ui::MouseEvent(
547 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), 555 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11),
548 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 556 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
549 event_dispatcher()->ProcessEvent(press_event); 557 event_dispatcher()->ProcessEvent(press_event);
550 558
551 // Events should target child and be in the client area. 559 // Events should target child and be in the client area.
552 scoped_ptr<DispatchedEventDetails> details = 560 scoped_ptr<DispatchedEventDetails> details =
553 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 561 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
554 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 562 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
555 ASSERT_EQ(child.get(), details->window); 563 ASSERT_EQ(child.get(), details->window);
556 EXPECT_FALSE(details->in_nonclient_area); 564 EXPECT_FALSE(details->in_nonclient_area);
557 } 565 }
558 566
559 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { 567 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) {
560 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); 568 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
561 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); 569 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
562 570
563 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 571 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
564 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 572 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
565 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 573 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
566 574
567 TestEventDispatcherDelegate* event_dispatcher_delegate = 575 TestEventDispatcherDelegate* event_dispatcher_delegate =
568 test_event_dispatcher_delegate(); 576 test_event_dispatcher_delegate();
569 EventDispatcher* dispatcher = event_dispatcher(); 577 EventDispatcher* dispatcher = event_dispatcher();
570 578
571 // Press on child1. First press event should change focus. 579 // Press on child1. First press event should change focus.
(...skipping 13 matching lines...) Expand all
585 const ui::PointerEvent touch_event(ui::TouchEvent( 593 const ui::PointerEvent touch_event(ui::TouchEvent(
586 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta())); 594 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta()));
587 dispatcher->ProcessEvent(touch_event); 595 dispatcher->ProcessEvent(touch_event);
588 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 596 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
589 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 597 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
590 EXPECT_EQ(child2.get(), details->window); 598 EXPECT_EQ(child2.get(), details->window);
591 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); 599 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow());
592 } 600 }
593 601
594 TEST_F(EventDispatcherTest, TwoPointersActive) { 602 TEST_F(EventDispatcherTest, TwoPointersActive) {
595 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); 603 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
596 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); 604 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
597 605
598 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 606 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
599 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 607 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
600 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 608 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
601 609
602 TestEventDispatcherDelegate* event_dispatcher_delegate = 610 TestEventDispatcherDelegate* event_dispatcher_delegate =
603 test_event_dispatcher_delegate(); 611 test_event_dispatcher_delegate();
604 EventDispatcher* dispatcher = event_dispatcher(); 612 EventDispatcher* dispatcher = event_dispatcher();
605 613
606 // Press on child1. 614 // Press on child1.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 652 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
645 EXPECT_EQ(child1.get(), details->window); 653 EXPECT_EQ(child1.get(), details->window);
646 const ui::PointerEvent touch_event3(ui::TouchEvent( 654 const ui::PointerEvent touch_event3(ui::TouchEvent(
647 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta())); 655 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta()));
648 dispatcher->ProcessEvent(touch_event3); 656 dispatcher->ProcessEvent(touch_event3);
649 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 657 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
650 EXPECT_EQ(child2.get(), details->window); 658 EXPECT_EQ(child2.get(), details->window);
651 } 659 }
652 660
653 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { 661 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) {
654 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 662 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
655 663
656 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 664 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
657 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 665 child->SetBounds(gfx::Rect(10, 10, 20, 20));
658 666
659 TestEventDispatcherDelegate* event_dispatcher_delegate = 667 TestEventDispatcherDelegate* event_dispatcher_delegate =
660 test_event_dispatcher_delegate(); 668 test_event_dispatcher_delegate();
661 EventDispatcher* dispatcher = event_dispatcher(); 669 EventDispatcher* dispatcher = event_dispatcher();
662 670
663 // Press on child. 671 // Press on child.
664 const ui::PointerEvent touch_event1(ui::TouchEvent( 672 const ui::PointerEvent touch_event1(ui::TouchEvent(
665 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); 673 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta()));
666 dispatcher->ProcessEvent(touch_event1); 674 dispatcher->ProcessEvent(touch_event1);
667 scoped_ptr<DispatchedEventDetails> details = 675 scoped_ptr<DispatchedEventDetails> details =
668 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 676 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
669 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 677 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
670 EXPECT_EQ(child.get(), details->window); 678 EXPECT_EQ(child.get(), details->window);
671 679
672 // Delete child, and continue the drag. Event should not be dispatched. 680 // Delete child, and continue the drag. Event should not be dispatched.
673 child.reset(); 681 child.reset();
674 682
675 const ui::PointerEvent drag_event1(ui::TouchEvent( 683 const ui::PointerEvent drag_event1(ui::TouchEvent(
676 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta())); 684 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta()));
677 dispatcher->ProcessEvent(drag_event1); 685 dispatcher->ProcessEvent(drag_event1);
678 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 686 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
679 EXPECT_EQ(nullptr, details.get()); 687 EXPECT_EQ(nullptr, details.get());
680 } 688 }
681 689
682 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { 690 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) {
683 ServerWindow* root = root_window(); 691 ServerWindow* root = root_window();
684 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 692 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
685 693
686 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 694 root->SetBounds(gfx::Rect(0, 0, 100, 100));
687 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 695 child->SetBounds(gfx::Rect(10, 10, 20, 20));
688 696
689 TestEventDispatcherDelegate* event_dispatcher_delegate = 697 TestEventDispatcherDelegate* event_dispatcher_delegate =
690 test_event_dispatcher_delegate(); 698 test_event_dispatcher_delegate();
691 EventDispatcher* dispatcher = event_dispatcher(); 699 EventDispatcher* dispatcher = event_dispatcher();
692 700
693 // Send event that is not over child. 701 // Send event that is not over child.
694 const ui::PointerEvent ui_event(ui::MouseEvent( 702 const ui::PointerEvent ui_event(ui::MouseEvent(
(...skipping 29 matching lines...) Expand all
724 ASSERT_EQ(child.get(), details->window); 732 ASSERT_EQ(child.get(), details->window);
725 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); 733 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
726 ASSERT_TRUE(details->event.get()); 734 ASSERT_TRUE(details->event.get());
727 ASSERT_TRUE(details->event->IsPointerEvent()); 735 ASSERT_TRUE(details->event->IsPointerEvent());
728 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); 736 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location());
729 } 737 }
730 738
731 // TODO(moshayedi): crbug.com/590226. Enable this after we support wheel events 739 // TODO(moshayedi): crbug.com/590226. Enable this after we support wheel events
732 // in mus event dispatcher. 740 // in mus event dispatcher.
733 TEST_F(EventDispatcherTest, DISABLED_WheelWhileDown) { 741 TEST_F(EventDispatcherTest, DISABLED_WheelWhileDown) {
734 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); 742 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
735 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); 743 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
736 744
737 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 745 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
738 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 746 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
739 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 747 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
740 748
741 MouseEventTest tests[] = { 749 MouseEventTest tests[] = {
742 // Send a mouse down event over child1. 750 // Send a mouse down event over child1.
743 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), 751 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15),
744 gfx::Point(15, 15), base::TimeDelta(), 752 gfx::Point(15, 15), base::TimeDelta(),
745 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), 753 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
746 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, 754 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr,
747 gfx::Point(), gfx::Point()}, 755 gfx::Point(), gfx::Point()},
748 // Send mouse wheel over child2, should go to child1 as it has capture. 756 // Send mouse wheel over child2, should go to child1 as it has capture.
749 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), 757 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54),
750 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE, 758 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE,
751 ui::EF_NONE), 759 ui::EF_NONE),
752 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, 760 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr,
753 gfx::Point(), gfx::Point()}, 761 gfx::Point(), gfx::Point()},
754 }; 762 };
755 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), 763 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
756 tests, arraysize(tests)); 764 tests, arraysize(tests));
757 } 765 }
758 766
759 // Tests that when explicit capture has been set that all events go to the 767 // Tests that when explicit capture has been set that all events go to the
760 // designated window, and that when capture is cleared, events find the 768 // designated window, and that when capture is cleared, events find the
761 // appropriate target window. 769 // appropriate target window.
762 TEST_F(EventDispatcherTest, SetExplicitCapture) { 770 TEST_F(EventDispatcherTest, SetExplicitCapture) {
763 ServerWindow* root = root_window(); 771 ServerWindow* root = root_window();
764 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 772 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
765 773
766 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 774 root->SetBounds(gfx::Rect(0, 0, 100, 100));
767 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 775 child->SetBounds(gfx::Rect(10, 10, 20, 20));
768 776
769 TestEventDispatcherDelegate* event_dispatcher_delegate = 777 TestEventDispatcherDelegate* event_dispatcher_delegate =
770 test_event_dispatcher_delegate(); 778 test_event_dispatcher_delegate();
771 EventDispatcher* dispatcher = event_dispatcher(); 779 EventDispatcher* dispatcher = event_dispatcher();
772 780
773 { 781 {
774 // Send all pointer events to the child. 782 // Send all pointer events to the child.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 856
849 ASSERT_TRUE(details); 857 ASSERT_TRUE(details);
850 ASSERT_EQ(root, details->window); 858 ASSERT_EQ(root, details->window);
851 } 859 }
852 } 860 }
853 861
854 // This test verifies that explicit capture overrides and resets implicit 862 // This test verifies that explicit capture overrides and resets implicit
855 // capture. 863 // capture.
856 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { 864 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) {
857 ServerWindow* root = root_window(); 865 ServerWindow* root = root_window();
858 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 866 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
859 867
860 root->SetBounds(gfx::Rect(0, 0, 100, 100)); 868 root->SetBounds(gfx::Rect(0, 0, 100, 100));
861 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 869 child->SetBounds(gfx::Rect(10, 10, 20, 20));
862 870
863 TestEventDispatcherDelegate* event_dispatcher_delegate = 871 TestEventDispatcherDelegate* event_dispatcher_delegate =
864 test_event_dispatcher_delegate(); 872 test_event_dispatcher_delegate();
865 EventDispatcher* dispatcher = event_dispatcher(); 873 EventDispatcher* dispatcher = event_dispatcher();
866 874
867 // Run some implicit capture tests. 875 // Run some implicit capture tests.
868 MouseEventTest tests[] = { 876 MouseEventTest tests[] = {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // Setting the capture should clear the implicit pointers for the specified 978 // Setting the capture should clear the implicit pointers for the specified
971 // window. 979 // window.
972 dispatcher->SetCaptureWindow(root, true); 980 dispatcher->SetCaptureWindow(root, true);
973 EXPECT_FALSE(AreAnyPointersDown()); 981 EXPECT_FALSE(AreAnyPointersDown());
974 EXPECT_FALSE(IsWindowPointerTarget(root)); 982 EXPECT_FALSE(IsWindowPointerTarget(root));
975 } 983 }
976 984
977 // Tests that when explicit capture is changed, that the previous window with 985 // Tests that when explicit capture is changed, that the previous window with
978 // capture is no longer being observed. 986 // capture is no longer being observed.
979 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { 987 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) {
980 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); 988 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3));
981 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); 989 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4));
982 990
983 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 991 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
984 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); 992 child1->SetBounds(gfx::Rect(10, 10, 20, 20));
985 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); 993 child2->SetBounds(gfx::Rect(50, 51, 11, 12));
986 994
987 EventDispatcher* dispatcher = event_dispatcher(); 995 EventDispatcher* dispatcher = event_dispatcher();
988 ASSERT_FALSE(AreAnyPointersDown()); 996 ASSERT_FALSE(AreAnyPointersDown());
989 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); 997 ASSERT_FALSE(IsWindowPointerTarget(child1.get()));
990 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); 998 ASSERT_FALSE(IsWindowPointerTarget(child2.get()));
991 dispatcher->SetCaptureWindow(child1.get(), false); 999 dispatcher->SetCaptureWindow(child1.get(), false);
992 dispatcher->SetCaptureWindow(child2.get(), false); 1000 dispatcher->SetCaptureWindow(child2.get(), false);
993 EXPECT_EQ(child1.get(), 1001 EXPECT_EQ(child1.get(),
994 test_event_dispatcher_delegate()->lost_capture_window()); 1002 test_event_dispatcher_delegate()->lost_capture_window());
995 1003
996 // If observing does not stop during the capture update this crashes. 1004 // If observing does not stop during the capture update this crashes.
997 child1->AddObserver(dispatcher); 1005 child1->AddObserver(dispatcher);
998 } 1006 }
999 1007
1000 // Tests that destroying a window with explicit capture clears the capture 1008 // Tests that destroying a window with explicit capture clears the capture
1001 // state. 1009 // state.
1002 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { 1010 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) {
1003 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 1011 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1004 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1012 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1005 1013
1006 EventDispatcher* dispatcher = event_dispatcher(); 1014 EventDispatcher* dispatcher = event_dispatcher();
1007 dispatcher->SetCaptureWindow(child.get(), false); 1015 dispatcher->SetCaptureWindow(child.get(), false);
1008 EXPECT_EQ(child.get(), dispatcher->capture_window()); 1016 EXPECT_EQ(child.get(), dispatcher->capture_window());
1009 1017
1010 ServerWindow* lost_capture_window = child.get(); 1018 ServerWindow* lost_capture_window = child.get();
1011 child.reset(); 1019 child.reset();
1012 EXPECT_EQ(nullptr, dispatcher->capture_window()); 1020 EXPECT_EQ(nullptr, dispatcher->capture_window());
1013 EXPECT_EQ(lost_capture_window, 1021 EXPECT_EQ(lost_capture_window,
(...skipping 21 matching lines...) Expand all
1035 1043
1036 // Events should target child and be in the client area. 1044 // Events should target child and be in the client area.
1037 scoped_ptr<DispatchedEventDetails> details = 1045 scoped_ptr<DispatchedEventDetails> details =
1038 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); 1046 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
1039 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); 1047 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
1040 ASSERT_EQ(root, details->window); 1048 ASSERT_EQ(root, details->window);
1041 EXPECT_TRUE(details->in_nonclient_area); 1049 EXPECT_TRUE(details->in_nonclient_area);
1042 } 1050 }
1043 1051
1044 TEST_F(EventDispatcherTest, ProcessPointerEvents) { 1052 TEST_F(EventDispatcherTest, ProcessPointerEvents) {
1045 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); 1053 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3));
1046 1054
1047 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 1055 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1048 child->SetBounds(gfx::Rect(10, 10, 20, 20)); 1056 child->SetBounds(gfx::Rect(10, 10, 20, 20));
1049 1057
1050 { 1058 {
1051 const ui::PointerEvent pointer_event(ui::MouseEvent( 1059 const ui::PointerEvent pointer_event(ui::MouseEvent(
1052 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), 1060 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
1053 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 1061 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1054 event_dispatcher()->ProcessEvent(pointer_event); 1062 event_dispatcher()->ProcessEvent(pointer_event);
1055 1063
(...skipping 25 matching lines...) Expand all
1081 ASSERT_TRUE(details->event); 1089 ASSERT_TRUE(details->event);
1082 ASSERT_TRUE(details->event->IsPointerEvent()); 1090 ASSERT_TRUE(details->event->IsPointerEvent());
1083 1091
1084 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); 1092 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1085 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); 1093 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location());
1086 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); 1094 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location());
1087 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); 1095 EXPECT_EQ(touch_id, dispatched_event->pointer_id());
1088 } 1096 }
1089 } 1097 }
1090 1098
1099 // Tests that events on a modal parent target the modal child.
1100 TEST_F(EventDispatcherTest, ModalWindowEventOnModalParent) {
1101 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1102 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1103
1104 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1105 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1106 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1107
1108 w1->AddTransientWindow(w2.get());
1109 w2->SetAsModal();
1110
1111 // Send event that is over |w1|.
1112 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1113 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
1114 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1115 event_dispatcher()->ProcessEvent(mouse_pressed);
1116
1117 scoped_ptr<DispatchedEventDetails> details =
1118 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1119 ASSERT_TRUE(details);
1120 EXPECT_EQ(w2.get(), details->window);
1121 EXPECT_TRUE(details->in_nonclient_area);
1122
1123 ASSERT_TRUE(details->event);
1124 ASSERT_TRUE(details->event->IsPointerEvent());
1125
1126 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1127 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
1128 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location());
1129 }
1130
1131 // Tests that events on a modal child target the modal child itself.
1132 TEST_F(EventDispatcherTest, ModalWindowEventOnModalChild) {
1133 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1134 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1135
1136 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1137 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1138 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1139
1140 w1->AddTransientWindow(w2.get());
1141 w2->SetAsModal();
1142
1143 // Send event that is over |w2|.
1144 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1145 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15),
1146 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1147 event_dispatcher()->ProcessEvent(mouse_pressed);
1148
1149 scoped_ptr<DispatchedEventDetails> details =
1150 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1151 ASSERT_TRUE(details);
1152 EXPECT_EQ(w2.get(), details->window);
1153 EXPECT_FALSE(details->in_nonclient_area);
1154
1155 ASSERT_TRUE(details->event);
1156 ASSERT_TRUE(details->event->IsPointerEvent());
1157
1158 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1159 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location());
1160 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1161 }
1162
1163 // Tests that events on an unrelated window are not affected by the modal
1164 // window.
1165 TEST_F(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) {
1166 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1167 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1168 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6));
1169
1170 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1171 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1172 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1173 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1174
1175 w1->AddTransientWindow(w2.get());
1176 w2->SetAsModal();
1177
1178 // Send event that is over |w3|.
1179 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1180 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15),
1181 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1182 event_dispatcher()->ProcessEvent(mouse_pressed);
1183
1184 scoped_ptr<DispatchedEventDetails> details =
1185 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1186 ASSERT_TRUE(details);
1187 EXPECT_EQ(w3.get(), details->window);
1188 EXPECT_FALSE(details->in_nonclient_area);
1189
1190 ASSERT_TRUE(details->event);
1191 ASSERT_TRUE(details->event->IsPointerEvent());
1192
1193 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1194 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location());
1195 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
1196 }
1197
1198 // Tests that events events on a descendant of a modal parent target the modal
1199 // child.
1200 TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) {
1201 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1202 scoped_ptr<ServerWindow> w11 =
1203 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1204 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1205
1206 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1207 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1208 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1209 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1210
1211 w1->AddTransientWindow(w2.get());
1212 w2->SetAsModal();
1213
1214 // Send event that is over |w11|.
1215 const ui::PointerEvent mouse_pressed(ui::MouseEvent(
1216 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25),
1217 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
1218 event_dispatcher()->ProcessEvent(mouse_pressed);
1219
1220 scoped_ptr<DispatchedEventDetails> details =
1221 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
1222 ASSERT_TRUE(details);
1223 EXPECT_EQ(w2.get(), details->window);
1224 EXPECT_TRUE(details->in_nonclient_area);
1225
1226 ASSERT_TRUE(details->event);
1227 ASSERT_TRUE(details->event->IsPointerEvent());
1228
1229 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
1230 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
1231 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location());
1232 }
1233
1234 // Tests that setting capture to a descendant of a modal parent fails.
1235 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) {
1236 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1237 scoped_ptr<ServerWindow> w11 =
1238 CreateChildWindowWithParent(WindowId(1, 4), w1.get());
1239 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1240
1241 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1242 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1243 w11->SetBounds(gfx::Rect(10, 10, 10, 10));
1244 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1245
1246 w1->AddTransientWindow(w2.get());
1247 w2->SetAsModal();
1248
1249 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false));
1250 EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
1251 }
1252
1253 // Tests that setting capture to a window unrelated to a modal parent works.
1254 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) {
1255 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3));
1256 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5));
1257 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6));
1258
1259 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
1260 w1->SetBounds(gfx::Rect(10, 10, 30, 30));
1261 w2->SetBounds(gfx::Rect(50, 10, 10, 10));
1262 w3->SetBounds(gfx::Rect(70, 10, 10, 10));
1263
1264 w1->AddTransientWindow(w2.get());
1265 w2->SetAsModal();
1266
1267 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false));
1268 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
1269 }
1270
1091 } // namespace ws 1271 } // namespace ws
1092 } // namespace mus 1272 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698