Skip to content

Commit

Permalink
views/mus: Add a test to verify that Widget receives events correctly.
Browse files Browse the repository at this point in the history
BUG=none

Review-Url: https://codereview.chromium.org/1994223003
Cr-Commit-Position: refs/heads/master@{#394939}
  • Loading branch information
sadrulhc authored and Commit bot committed May 20, 2016
1 parent 0b38daa commit 2b3ae3b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/mus/public/cpp/tests/window_tree_client_impl_private.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
#include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"

#include "components/mus/public/cpp/lib/window_tree_client_impl.h"
#include "components/mus/public/cpp/window.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/converters/input_events/input_events_type_converters.h"

namespace mus {

WindowTreeClientImplPrivate::WindowTreeClientImplPrivate(
WindowTreeClientImpl* tree_client_impl)
: tree_client_impl_(tree_client_impl) {}

WindowTreeClientImplPrivate::WindowTreeClientImplPrivate(Window* window)
: WindowTreeClientImplPrivate(window->tree_client()) {}

WindowTreeClientImplPrivate::~WindowTreeClientImplPrivate() {}

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

void WindowTreeClientImplPrivate::CallOnWindowInputEvent(
Window* window,
const ui::Event& event) {
const uint32_t event_id = 0u;
const uint32_t observer_id = 0u;
tree_client_impl_->OnWindowInputEvent(event_id, window->server_id(),
mojom::Event::From(event), observer_id);
}

} // namespace mus
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@

#include "base/macros.h"

namespace ui {
class Event;
}

namespace mus {
namespace mojom {
class WindowTree;
}

class Window;
class WindowTreeClientImpl;

// Use to access implementation details of WindowTreeClientImpl.
class WindowTreeClientImplPrivate {
public:
explicit WindowTreeClientImplPrivate(WindowTreeClientImpl* tree_client_impl);
explicit WindowTreeClientImplPrivate(Window* window);
~WindowTreeClientImplPrivate();

uint32_t event_observer_id();

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

// Pretends that |event| has been received from the window server.
void CallOnWindowInputEvent(Window* window, const ui::Event& event);

private:
WindowTreeClientImpl* tree_client_impl_;

Expand Down
2 changes: 2 additions & 0 deletions components/mus/public/cpp/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class WindowObserver;
class WindowSurface;
class WindowSurfaceBinding;
class WindowTreeClientImpl;
class WindowTreeClientImplPrivate;
class WindowTreeConnection;

namespace {
Expand Down Expand Up @@ -229,6 +230,7 @@ class Window {
private:
friend class WindowPrivate;
friend class WindowTreeClientImpl;
friend class WindowTreeClientImplPrivate;

Window(WindowTreeConnection* connection, Id id);

Expand Down
1 change: 1 addition & 0 deletions ui/views/mus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ test("views_mus_unittests") {
"//base:i18n",
"//cc",
"//components/mus/public/cpp",
"//components/mus/public/cpp/tests:unittest_support",
"//components/mus/public/interfaces",
"//services/shell/background:main", # Provides main().
"//skia",
Expand Down
21 changes: 21 additions & 0 deletions ui/views/mus/native_widget_mus_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_property.h"
#include "components/mus/public/cpp/window_tree_connection.h"
Expand All @@ -17,6 +18,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skia_util.h"
Expand Down Expand Up @@ -363,6 +365,25 @@ TEST_F(NativeWidgetMusTest, FocusChildAuraWindow) {
EXPECT_EQ(widget.GetNativeView(), active_window);
}

TEST_F(NativeWidgetMusTest, WidgetReceivesEvent) {
std::unique_ptr<Widget> widget(CreateWidget(nullptr));
widget->Show();

View* content = new HandleMousePressView;
content->SetBounds(10, 20, 90, 180);
widget->GetContentsView()->AddChildView(content);

ui::test::TestEventHandler handler;
content->AddPreTargetHandler(&handler);

std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent();
NativeWidgetMus* native_widget =
static_cast<NativeWidgetMus*>(widget->native_widget_private());
mus::WindowTreeClientImplPrivate test_api(native_widget->window());
test_api.CallOnWindowInputEvent(native_widget->window(), *mouse);
EXPECT_EQ(1, handler.num_mouse_events());
}

// Tests that an incoming UI event is acked with the handled status.
TEST_F(NativeWidgetMusTest, EventAcked) {
std::unique_ptr<Widget> widget(CreateWidget(nullptr));
Expand Down

0 comments on commit 2b3ae3b

Please sign in to comment.