Commit 2e39d83d authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

ozone/wayland: Share ScopedWlArray and SendConfigureEvent between tests

Just moving ScopedWlArray into a shared place and making the
SendConfigureEvent available for other tests.

It also automatically sends configure event to the window so that
tests wouldn't need to activate the window by themselves.
Basically, this is going to be needed for the CL I'm going to submit
next.

Bug: 1022750, 1083949
Change-Id: I4ce6f7d8720266b8ee20c9d8cf6ce3c50490791e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207170Reviewed-by: default avatarNick Yamane <nickdiego@igalia.com>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#769991}
parent c24f6f28
......@@ -244,6 +244,8 @@ source_set("test_support") {
"test/mock_zwp_linux_dmabuf.h",
"test/mock_zwp_text_input.cc",
"test/mock_zwp_text_input.h",
"test/scoped_wl_array.cc",
"test/scoped_wl_array.h",
"test/server_object.cc",
"test/server_object.h",
"test/test_compositor.cc",
......
......@@ -21,6 +21,7 @@
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/scoped_wl_array.h"
#include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h"
#include "ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/test/scoped_wl_array.h"
#include <wayland-server-core.h>
namespace wl {
ScopedWlArray::ScopedWlArray(const std::vector<int32_t> states) {
wl_array_init(&array_);
for (const auto& state : states)
AddStateToWlArray(state);
}
ScopedWlArray::ScopedWlArray(ScopedWlArray&& rhs) {
array_ = rhs.array_;
// wl_array_init sets rhs.array_'s fields to nullptr, so that
// the free() in wl_array_release() is a no-op.
wl_array_init(&rhs.array_);
}
ScopedWlArray& ScopedWlArray::operator=(ScopedWlArray&& rhs) {
wl_array_release(&array_);
array_ = rhs.array_;
// wl_array_init sets rhs.array_'s fields to nullptr, so that
// the free() in wl_array_release() is a no-op.
wl_array_init(&rhs.array_);
return *this;
}
ScopedWlArray::~ScopedWlArray() {
wl_array_release(&array_);
}
void ScopedWlArray::AddStateToWlArray(uint32_t state) {
*static_cast<uint32_t*>(wl_array_add(&array_, sizeof array_)) = state;
}
} // namespace wl
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_
#include <wayland-server-core.h>
#include <vector>
namespace wl {
class ScopedWlArray {
public:
explicit ScopedWlArray(const std::vector<int32_t> states);
ScopedWlArray(ScopedWlArray&& rhs);
ScopedWlArray& operator=(ScopedWlArray&& rhs);
~ScopedWlArray();
wl_array* get() { return &array_; }
void AddStateToWlArray(uint32_t state);
private:
wl_array array_;
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_
......@@ -10,6 +10,7 @@
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_screen.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/scoped_wl_array.h"
#include "ui/platform_window/platform_window_init_properties.h"
#if BUILDFLAG(USE_XKBCOMMON)
......@@ -66,6 +67,11 @@ void WaylandTest::SetUp() {
surface_ = server_.GetObject<wl::MockSurface>(widget_);
ASSERT_TRUE(surface_);
// The surface must be activated before buffers are attached.
ActivateSurface(server_.GetObject<wl::MockSurface>(widget_)->xdg_surface());
Sync();
initialized_ = true;
}
......@@ -86,4 +92,28 @@ void WaylandTest::Sync() {
server_.Pause();
}
void WaylandTest::SendConfigureEvent(wl::MockXdgSurface* xdg_surface,
int width,
int height,
uint32_t serial,
struct wl_array* states) {
DCHECK(xdg_surface->xdg_toplevel());
// In xdg_shell_v6+, both surfaces send serial configure event and toplevel
// surfaces send other data like states, heights and widths.
if (GetParam() == kXdgShellV6) {
zxdg_surface_v6_send_configure(xdg_surface->resource(), serial);
zxdg_toplevel_v6_send_configure(xdg_surface->xdg_toplevel()->resource(),
width, height, states);
} else {
xdg_surface_send_configure(xdg_surface->resource(), serial);
xdg_toplevel_send_configure(xdg_surface->xdg_toplevel()->resource(), width,
height, states);
}
}
void WaylandTest::ActivateSurface(wl::MockXdgSurface* xdg_surface) {
wl::ScopedWlArray state({XDG_TOPLEVEL_STATE_ACTIVATED});
SendConfigureEvent(xdg_surface, 0, 0, 1, state.get());
}
} // namespace ui
......@@ -24,6 +24,7 @@
namespace wl {
class MockSurface;
class MockXdgSurface;
} // namespace wl
namespace ui {
......@@ -47,6 +48,18 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> {
void Sync();
protected:
// Sends configure event for the |xdg_surface|.
void SendConfigureEvent(wl::MockXdgSurface* xdg_surface,
int width,
int height,
uint32_t serial,
struct wl_array* states);
// Sends XDG_TOPLEVEL_STATE_ACTIVATED to the |xdg_surface| with width and
// height set to 0, which results in asking the client to set the width and
// height of the surface.
void ActivateSurface(wl::MockXdgSurface* xdg_surface);
base::test::TaskEnvironment task_environment_;
wl::TestWaylandServerThread server_;
......
......@@ -894,9 +894,20 @@ TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionMultipleBuffers) {
constexpr uint32_t kBufferId2 = 2;
auto temp_window = CreateWindow();
temp_window->Show(false);
Sync();
auto widget = temp_window->GetWidget();
auto bounds = temp_window->GetBounds();
auto* mock_surface = server_.GetObject<wl::MockSurface>(widget);
ASSERT_TRUE(mock_surface);
ActivateSurface(mock_surface->xdg_surface());
Sync();
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
CreateDmabufBasedBufferAndSetTerminateExpecation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
......@@ -915,7 +926,6 @@ TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionMultipleBuffers) {
Sync();
auto* mock_surface = server_.GetObject<wl::MockSurface>(widget);
mock_surface->SendFrameCallback();
Sync();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment