Skip to content

Commit 2b3ae3b

Browse files
sadrulhcCommit bot
authored and
Commit bot
committed
views/mus: Add a test to verify that Widget receives events correctly.
BUG=none Review-Url: https://codereview.chromium.org/1994223003 Cr-Commit-Position: refs/heads/master@{#394939}
1 parent 0b38daa commit 2b3ae3b

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

components/mus/public/cpp/tests/window_tree_client_impl_private.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
#include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"
66

77
#include "components/mus/public/cpp/lib/window_tree_client_impl.h"
8+
#include "components/mus/public/cpp/window.h"
89
#include "mojo/converters/geometry/geometry_type_converters.h"
10+
#include "mojo/converters/input_events/input_events_type_converters.h"
911

1012
namespace mus {
1113

1214
WindowTreeClientImplPrivate::WindowTreeClientImplPrivate(
1315
WindowTreeClientImpl* tree_client_impl)
1416
: tree_client_impl_(tree_client_impl) {}
1517

18+
WindowTreeClientImplPrivate::WindowTreeClientImplPrivate(Window* window)
19+
: WindowTreeClientImplPrivate(window->tree_client()) {}
20+
1621
WindowTreeClientImplPrivate::~WindowTreeClientImplPrivate() {}
1722

1823
uint32_t WindowTreeClientImplPrivate::event_observer_id() {
@@ -33,4 +38,13 @@ void WindowTreeClientImplPrivate::OnEmbed(mojom::WindowTree* window_tree) {
3338
tree_client_impl_->OnEmbedImpl(window_tree, 1, std::move(root_data), 0, true);
3439
}
3540

41+
void WindowTreeClientImplPrivate::CallOnWindowInputEvent(
42+
Window* window,
43+
const ui::Event& event) {
44+
const uint32_t event_id = 0u;
45+
const uint32_t observer_id = 0u;
46+
tree_client_impl_->OnWindowInputEvent(event_id, window->server_id(),
47+
mojom::Event::From(event), observer_id);
48+
}
49+
3650
} // namespace mus

components/mus/public/cpp/tests/window_tree_client_impl_private.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,33 @@
99

1010
#include "base/macros.h"
1111

12+
namespace ui {
13+
class Event;
14+
}
15+
1216
namespace mus {
1317
namespace mojom {
1418
class WindowTree;
1519
}
1620

21+
class Window;
1722
class WindowTreeClientImpl;
1823

1924
// Use to access implementation details of WindowTreeClientImpl.
2025
class WindowTreeClientImplPrivate {
2126
public:
2227
explicit WindowTreeClientImplPrivate(WindowTreeClientImpl* tree_client_impl);
28+
explicit WindowTreeClientImplPrivate(Window* window);
2329
~WindowTreeClientImplPrivate();
2430

2531
uint32_t event_observer_id();
2632

2733
// Calls OnEmbed() on the WindowTreeClientImpl.
2834
void OnEmbed(mojom::WindowTree* window_tree);
2935

36+
// Pretends that |event| has been received from the window server.
37+
void CallOnWindowInputEvent(Window* window, const ui::Event& event);
38+
3039
private:
3140
WindowTreeClientImpl* tree_client_impl_;
3241

components/mus/public/cpp/window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class WindowObserver;
3232
class WindowSurface;
3333
class WindowSurfaceBinding;
3434
class WindowTreeClientImpl;
35+
class WindowTreeClientImplPrivate;
3536
class WindowTreeConnection;
3637

3738
namespace {
@@ -229,6 +230,7 @@ class Window {
229230
private:
230231
friend class WindowPrivate;
231232
friend class WindowTreeClientImpl;
233+
friend class WindowTreeClientImplPrivate;
232234

233235
Window(WindowTreeConnection* connection, Id id);
234236

ui/views/mus/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ test("views_mus_unittests") {
186186
"//base:i18n",
187187
"//cc",
188188
"//components/mus/public/cpp",
189+
"//components/mus/public/cpp/tests:unittest_support",
189190
"//components/mus/public/interfaces",
190191
"//services/shell/background:main", # Provides main().
191192
"//skia",

ui/views/mus/native_widget_mus_unittest.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "base/callback.h"
88
#include "base/macros.h"
99
#include "components/mus/public/cpp/property_type_converters.h"
10+
#include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"
1011
#include "components/mus/public/cpp/window.h"
1112
#include "components/mus/public/cpp/window_property.h"
1213
#include "components/mus/public/cpp/window_tree_connection.h"
@@ -17,6 +18,7 @@
1718
#include "third_party/skia/include/core/SkColor.h"
1819
#include "ui/aura/window.h"
1920
#include "ui/events/event.h"
21+
#include "ui/events/test/test_event_handler.h"
2022
#include "ui/gfx/geometry/rect.h"
2123
#include "ui/gfx/image/image_skia.h"
2224
#include "ui/gfx/skia_util.h"
@@ -363,6 +365,25 @@ TEST_F(NativeWidgetMusTest, FocusChildAuraWindow) {
363365
EXPECT_EQ(widget.GetNativeView(), active_window);
364366
}
365367

368+
TEST_F(NativeWidgetMusTest, WidgetReceivesEvent) {
369+
std::unique_ptr<Widget> widget(CreateWidget(nullptr));
370+
widget->Show();
371+
372+
View* content = new HandleMousePressView;
373+
content->SetBounds(10, 20, 90, 180);
374+
widget->GetContentsView()->AddChildView(content);
375+
376+
ui::test::TestEventHandler handler;
377+
content->AddPreTargetHandler(&handler);
378+
379+
std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent();
380+
NativeWidgetMus* native_widget =
381+
static_cast<NativeWidgetMus*>(widget->native_widget_private());
382+
mus::WindowTreeClientImplPrivate test_api(native_widget->window());
383+
test_api.CallOnWindowInputEvent(native_widget->window(), *mouse);
384+
EXPECT_EQ(1, handler.num_mouse_events());
385+
}
386+
366387
// Tests that an incoming UI event is acked with the handled status.
367388
TEST_F(NativeWidgetMusTest, EventAcked) {
368389
std::unique_ptr<Widget> widget(CreateWidget(nullptr));

0 commit comments

Comments
 (0)