Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/mus/platform_window_mus.h" | 5 #include "ui/views/mus/platform_window_mus.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/views/mus/native_widget_mus.h" | 16 #include "ui/views/mus/native_widget_mus.h" |
| 17 #include "ui/views/mus/window_tree_host_mus.h" | 17 #include "ui/views/mus/window_tree_host_mus.h" |
| 18 #include "ui/views/test/views_test_base.h" | 18 #include "ui/views/test/views_test_base.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 #include "ui/views/widget/widget_delegate.h" | 20 #include "ui/views/widget/widget_delegate.h" |
| 21 | 21 |
| 22 using mus::mojom::EventResult; | 22 using mus::mojom::EventResult; |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 namespace { | |
| 26 | |
| 27 // A view that reports any mouse press as handled. | |
| 28 class HandleMousePressView : public View { | |
| 29 public: | |
| 30 HandleMousePressView() {} | |
| 31 ~HandleMousePressView() override {} | |
| 32 | |
| 33 // View: | |
| 34 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } | |
| 35 | |
| 36 private: | |
| 37 DISALLOW_COPY_AND_ASSIGN(HandleMousePressView); | |
| 38 }; | |
| 39 | |
| 40 // A view that deletes a widget on mouse press. | |
| 41 class DeleteWidgetView : public View { | |
| 42 public: | |
| 43 explicit DeleteWidgetView(std::unique_ptr<Widget>* widget_ptr) | |
| 44 : widget_ptr_(widget_ptr) {} | |
| 45 ~DeleteWidgetView() override {} | |
| 46 | |
| 47 // View: | |
| 48 bool OnMousePressed(const ui::MouseEvent& event) override { | |
| 49 widget_ptr_->reset(); | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 std::unique_ptr<Widget>* widget_ptr_; | |
| 55 DISALLOW_COPY_AND_ASSIGN(DeleteWidgetView); | |
| 56 }; | |
| 57 | |
| 58 } // namespace | |
| 59 | 25 |
| 60 class PlatformWindowMusTest : public ViewsTestBase { | 26 class PlatformWindowMusTest : public ViewsTestBase { |
| 61 public: | 27 public: |
| 62 PlatformWindowMusTest() {} | 28 PlatformWindowMusTest() {} |
| 63 ~PlatformWindowMusTest() override {} | 29 ~PlatformWindowMusTest() override {} |
| 64 | 30 |
| 65 int ack_callback_count() { return ack_callback_count_; } | 31 int ack_callback_count() { return ack_callback_count_; } |
| 66 | 32 |
| 67 void AckCallback(mus::mojom::EventResult result) { | 33 void AckCallback(mus::mojom::EventResult result) { |
| 68 ack_callback_count_++; | 34 ack_callback_count_++; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 84 ASSERT_TRUE(platform_window_); | 50 ASSERT_TRUE(platform_window_); |
| 85 } | 51 } |
| 86 | 52 |
| 87 // Returns a mouse pressed event in the middle of the widget. | 53 // Returns a mouse pressed event in the middle of the widget. |
| 88 std::unique_ptr<ui::MouseEvent> CreateMouseEvent() { | 54 std::unique_ptr<ui::MouseEvent> CreateMouseEvent() { |
| 89 return base::WrapUnique(new ui::MouseEvent( | 55 return base::WrapUnique(new ui::MouseEvent( |
| 90 ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50), | 56 ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50), |
| 91 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 57 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 92 } | 58 } |
| 93 | 59 |
| 94 // Simulates an input event to the PlatformWindow. | |
| 95 void OnWindowInputEvent( | |
| 96 const ui::Event& event, | |
| 97 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* | |
| 98 ack_callback) { | |
| 99 platform_window_->OnWindowInputEvent(native_widget_->window(), event, | |
| 100 ack_callback); | |
| 101 } | |
| 102 | |
| 103 protected: | 60 protected: |
| 104 std::unique_ptr<Widget> widget_; | 61 std::unique_ptr<Widget> widget_; |
| 105 | 62 |
| 106 private: | 63 private: |
| 107 NativeWidgetMus* native_widget_ = nullptr; | 64 NativeWidgetMus* native_widget_ = nullptr; |
| 108 PlatformWindowMus* platform_window_ = nullptr; | 65 PlatformWindowMus* platform_window_ = nullptr; |
| 109 int ack_callback_count_ = 0; | 66 int ack_callback_count_ = 0; |
| 110 | 67 |
| 111 DISALLOW_COPY_AND_ASSIGN(PlatformWindowMusTest); | 68 DISALLOW_COPY_AND_ASSIGN(PlatformWindowMusTest); |
| 112 }; | 69 }; |
| 113 | 70 |
| 71 // TODO(markdittmer): Port these tests to native_widget_mus. | |
| 72 #if 0 | |
| 73 | |
|
sadrul
2016/05/13 17:02:44
This should be fixed?
Mark Dittmer
2016/05/16 15:58:43
I was going to move tests in another CL. Actually,
| |
| 114 // Tests that an incoming UI event is acked with the handled status. | 74 // Tests that an incoming UI event is acked with the handled status. |
| 115 TEST_F(PlatformWindowMusTest, EventAcked) { | 75 TEST_F(PlatformWindowMusTest, EventAcked) { |
| 116 View* content = new HandleMousePressView; | 76 View* content = new HandleMousePressView; |
| 117 content->SetBounds(0, 0, 100, 100); | 77 content->SetBounds(0, 0, 100, 100); |
| 118 widget_->GetContentsView()->AddChildView(content); | 78 widget_->GetContentsView()->AddChildView(content); |
| 119 | 79 |
| 120 // Dispatch an input event to the window and view. | 80 // Dispatch an input event to the window and view. |
| 121 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent(); | 81 std::unique_ptr<ui::MouseEvent> event = CreateMouseEvent(); |
| 122 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( | 82 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( |
| 123 new base::Callback<void(EventResult)>(base::Bind( | 83 new base::Callback<void(EventResult)>(base::Bind( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 144 OnWindowInputEvent(*event, &ack_callback); | 104 OnWindowInputEvent(*event, &ack_callback); |
| 145 | 105 |
| 146 // The widget was deleted. | 106 // The widget was deleted. |
| 147 EXPECT_FALSE(widget_); | 107 EXPECT_FALSE(widget_); |
| 148 | 108 |
| 149 // The platform window took ownership of the callback and called it. | 109 // The platform window took ownership of the callback and called it. |
| 150 EXPECT_FALSE(ack_callback); | 110 EXPECT_FALSE(ack_callback); |
| 151 EXPECT_EQ(1, ack_callback_count()); | 111 EXPECT_EQ(1, ack_callback_count()); |
| 152 } | 112 } |
| 153 | 113 |
| 114 #endif // #if 0 | |
| 115 | |
| 154 } // namespace views | 116 } // namespace views |
| OLD | NEW |