Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 // Get rid of X11 macros which conflict with gtest. | 10 // Get rid of X11 macros which conflict with gtest. |
| 11 // It is necessary to include this header before the rest so that Bool can be | |
| 12 // undefined. | |
| 13 #include "ui/events/test/events_test_utils_x11.h" | |
| 11 #undef Bool | 14 #undef Bool |
| 12 #undef None | 15 #undef None |
| 13 | 16 |
| 17 #include "base/command_line.h" | |
| 14 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 16 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 18 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
| 19 #include "ui/base/x/x11_util.h" | 23 #include "ui/base/x/x11_util.h" |
| 24 #include "ui/events/devices/x11/touch_factory_x11.h" | |
| 20 #include "ui/events/platform/x11/x11_event_source.h" | 25 #include "ui/events/platform/x11/x11_event_source.h" |
| 21 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/path.h" | 28 #include "ui/gfx/path.h" |
| 29 #include "ui/gfx/switches.h" | |
| 24 #include "ui/gfx/x/x11_atom_cache.h" | 30 #include "ui/gfx/x/x11_atom_cache.h" |
| 25 #include "ui/views/test/views_test_base.h" | 31 #include "ui/views/test/views_test_base.h" |
| 26 #include "ui/views/test/x11_property_change_waiter.h" | 32 #include "ui/views/test/x11_property_change_waiter.h" |
| 27 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 34 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | |
| 28 #include "ui/views/widget/widget_delegate.h" | 35 #include "ui/views/widget/widget_delegate.h" |
| 29 #include "ui/views/window/non_client_view.h" | 36 #include "ui/views/window/non_client_view.h" |
| 30 | 37 |
| 31 namespace views { | 38 namespace views { |
| 32 | 39 |
| 33 namespace { | 40 namespace { |
| 34 | 41 |
| 42 const int kPointerDeviceId = 1; | |
| 43 | |
| 35 // Blocks till the window state hint, |hint|, is set or unset. | 44 // Blocks till the window state hint, |hint|, is set or unset. |
| 36 class WMStateWaiter : public X11PropertyChangeWaiter { | 45 class WMStateWaiter : public X11PropertyChangeWaiter { |
| 37 public: | 46 public: |
| 38 WMStateWaiter(XID window, | 47 WMStateWaiter(XID window, |
| 39 const char* hint, | 48 const char* hint, |
| 40 bool wait_till_set) | 49 bool wait_till_set) |
| 41 : X11PropertyChangeWaiter(window, "_NET_WM_STATE"), | 50 : X11PropertyChangeWaiter(window, "_NET_WM_STATE"), |
| 42 hint_(hint), | 51 hint_(hint), |
| 43 wait_till_set_(wait_till_set) { | 52 wait_till_set_(wait_till_set) { |
| 44 | 53 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 XSendEvent(display, DefaultRootWindow(display), False, | 456 XSendEvent(display, DefaultRootWindow(display), False, |
| 448 SubstructureRedirectMask | SubstructureNotifyMask, | 457 SubstructureRedirectMask | SubstructureNotifyMask, |
| 449 &xevent); | 458 &xevent); |
| 450 | 459 |
| 451 WMStateWaiter waiter(xid, "_NET_WM_STATE_FOCUSED", true); | 460 WMStateWaiter waiter(xid, "_NET_WM_STATE_FOCUSED", true); |
| 452 waiter.Wait(); | 461 waiter.Wait(); |
| 453 } | 462 } |
| 454 EXPECT_TRUE(widget.GetNativeWindow()->IsVisible()); | 463 EXPECT_TRUE(widget.GetNativeWindow()->IsVisible()); |
| 455 } | 464 } |
| 456 | 465 |
| 466 class MouseEventRecorder : public ui::EventHandler { | |
| 467 public: | |
| 468 MouseEventRecorder() {} | |
| 469 ~MouseEventRecorder() override {} | |
| 470 | |
| 471 void Reset() { mouse_events_.clear(); } | |
| 472 | |
| 473 const std::vector<ui::MouseEvent>& mouse_events() const { | |
| 474 return mouse_events_; | |
| 475 } | |
| 476 | |
| 477 private: | |
| 478 // ui::EventHandler: | |
| 479 void OnMouseEvent(ui::MouseEvent* mouse) override { | |
| 480 mouse_events_.push_back(*mouse); | |
| 481 } | |
| 482 | |
| 483 std::vector<ui::MouseEvent> mouse_events_; | |
| 484 | |
| 485 DISALLOW_COPY_AND_ASSIGN(MouseEventRecorder); | |
| 486 }; | |
| 487 | |
| 488 // A custom event-source that can be used to directly dispatch synthetic X11 | |
| 489 // events. | |
| 490 class CustomX11EventSource : public ui::X11EventSource { | |
| 491 public: | |
| 492 CustomX11EventSource() : X11EventSource(gfx::GetXDisplay()) {} | |
| 493 ~CustomX11EventSource() override {} | |
| 494 | |
| 495 void DispatchSingleEvent(XEvent* xevent) { | |
| 496 PlatformEventSource::DispatchEvent(xevent); | |
| 497 } | |
| 498 | |
| 499 private: | |
| 500 DISALLOW_COPY_AND_ASSIGN(CustomX11EventSource); | |
| 501 }; | |
| 502 | |
| 503 class DesktopWindowTreeHostX11HighDPITest | |
| 504 : public DesktopWindowTreeHostX11Test { | |
| 505 public: | |
| 506 DesktopWindowTreeHostX11HighDPITest() {} | |
| 507 ~DesktopWindowTreeHostX11HighDPITest() override {} | |
| 508 | |
| 509 void DispatchSingleEventToWidget(XEvent* event, Widget* widget) { | |
| 510 DCHECK_EQ(GenericEvent, event->type); | |
| 511 XIDeviceEvent* device_event = | |
| 512 static_cast<XIDeviceEvent*>(event->xcookie.data); | |
| 513 device_event->event = | |
| 514 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | |
| 515 event_source_.DispatchSingleEvent(event); | |
| 516 } | |
| 517 | |
| 518 void PretendCapture(views::Widget* capture_widget) { | |
| 519 DesktopWindowTreeHostX11* capture_host = nullptr; | |
| 520 if (capture_widget) { | |
| 521 capture_host = static_cast<DesktopWindowTreeHostX11*>( | |
| 522 capture_widget->GetNativeWindow()->GetHost()); | |
| 523 } | |
| 524 DesktopWindowTreeHostX11::g_current_capture = capture_host; | |
| 525 if (capture_widget) | |
| 526 capture_widget->GetNativeWindow()->SetCapture(); | |
| 527 } | |
| 528 | |
| 529 private: | |
| 530 void SetUp() override { | |
| 531 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 532 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); | |
| 533 std::vector<unsigned int> pointer_devices; | |
| 534 pointer_devices.push_back(kPointerDeviceId); | |
| 535 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(pointer_devices); | |
| 536 | |
| 537 DesktopWindowTreeHostX11Test::SetUp(); | |
| 538 } | |
| 539 | |
| 540 CustomX11EventSource event_source_; | |
| 541 DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostX11HighDPITest); | |
| 542 }; | |
| 543 | |
| 544 TEST_F(DesktopWindowTreeHostX11HighDPITest, LocatedEventDispatchWithCapture) { | |
|
pkotwicz
2015/02/13 20:15:35
This test must be an interactive ui test. (Because
sadrul
2015/02/13 20:27:36
That's why this test doesn't actually do native ca
| |
| 545 Widget first; | |
| 546 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 547 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 548 params.native_widget = new DesktopNativeWidgetAura(&first); | |
| 549 params.bounds = gfx::Rect(0, 0, 50, 50); | |
| 550 first.Init(params); | |
| 551 first.Show(); | |
| 552 | |
| 553 Widget second; | |
| 554 params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 555 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 556 params.native_widget = new DesktopNativeWidgetAura(&second); | |
| 557 params.bounds = gfx::Rect(50, 50, 50, 50); | |
| 558 second.Init(params); | |
| 559 second.Show(); | |
| 560 | |
| 561 ui::X11EventSource::GetInstance()->DispatchXEvents(); | |
| 562 | |
| 563 MouseEventRecorder first_recorder, second_recorder; | |
| 564 first.GetNativeWindow()->AddPreTargetHandler(&first_recorder); | |
| 565 second.GetNativeWindow()->AddPreTargetHandler(&second_recorder); | |
| 566 | |
| 567 // Dispatch an event on |first|. Verify it gets the event. | |
| 568 ui::ScopedXI2Event event; | |
| 569 event.InitGenericButtonEvent(kPointerDeviceId, ui::ET_MOUSEWHEEL, | |
| 570 gfx::Point(50, 50), ui::EF_NONE); | |
| 571 DispatchSingleEventToWidget(event, &first); | |
| 572 ASSERT_EQ(1u, first_recorder.mouse_events().size()); | |
| 573 EXPECT_EQ(ui::ET_MOUSEWHEEL, first_recorder.mouse_events()[0].type()); | |
| 574 EXPECT_EQ(gfx::Point(25, 25).ToString(), | |
| 575 first_recorder.mouse_events()[0].location().ToString()); | |
| 576 ASSERT_EQ(0u, second_recorder.mouse_events().size()); | |
| 577 | |
| 578 first_recorder.Reset(); | |
| 579 second_recorder.Reset(); | |
| 580 | |
| 581 // Set a capture on |second|, and dispatch the same event to |first|. This | |
| 582 // event should reach |second| instead. | |
| 583 PretendCapture(&second); | |
| 584 event.InitGenericButtonEvent(kPointerDeviceId, ui::ET_MOUSEWHEEL, | |
| 585 gfx::Point(50, 50), ui::EF_NONE); | |
| 586 DispatchSingleEventToWidget(event, &first); | |
| 587 | |
| 588 ASSERT_EQ(0u, first_recorder.mouse_events().size()); | |
| 589 ASSERT_EQ(1u, second_recorder.mouse_events().size()); | |
| 590 EXPECT_EQ(ui::ET_MOUSEWHEEL, second_recorder.mouse_events()[0].type()); | |
| 591 EXPECT_EQ(gfx::Point(-25, -25).ToString(), | |
| 592 second_recorder.mouse_events()[0].location().ToString()); | |
| 593 | |
| 594 PretendCapture(nullptr); | |
| 595 first.GetNativeWindow()->RemovePreTargetHandler(&first_recorder); | |
| 596 second.GetNativeWindow()->RemovePreTargetHandler(&second_recorder); | |
| 597 } | |
| 598 | |
| 457 } // namespace views | 599 } // namespace views |
| OLD | NEW |