1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MIRAL_TEST_WINDOW_MANAGER_TOOLS_H
#define MIRAL_TEST_WINDOW_MANAGER_TOOLS_H
#include "basic_window_manager.h"
#include <mir/test/doubles/stub_session.h>
#include <miral/canonical_window_manager.h>
#include <miral/window.h>
#include <mir/shell/surface_specification.h>
#include <mir/scene/surface.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
namespace mir
{
namespace graphics
{
class DisplayConfiguration;
}
namespace test
{
struct MockWindowManagerPolicy
: miral::CanonicalWindowManagerPolicy
{
using miral::CanonicalWindowManagerPolicy::CanonicalWindowManagerPolicy;
bool handle_touch_event(MirTouchEvent const* /*event*/) { return false; }
bool handle_pointer_event(MirPointerEvent const* /*event*/) { return false; }
bool handle_keyboard_event(MirKeyboardEvent const* /*event*/) { return false; }
MOCK_METHOD(void, advise_new_window, (miral::WindowInfo const& window_info), (override));
MOCK_METHOD(void, advise_move_to, (miral::WindowInfo const& window_info, mir::geometry::Point top_left), (override));
MOCK_METHOD(void, advise_resize, (miral::WindowInfo const& window_info, mir::geometry::Size const& new_size), (override));
MOCK_METHOD(void, advise_raise, (std::vector<miral::Window> const&), (override));
MOCK_METHOD(void, advise_output_create, (miral::Output const&), (override));
MOCK_METHOD(void, advise_output_update, (miral::Output const&, miral::Output const&), (override));
MOCK_METHOD(void, advise_output_delete, (miral::Output const&), (override));
MOCK_METHOD(void, advise_application_zone_create, (miral::Zone const&), (override));
MOCK_METHOD(void, advise_application_zone_update, (miral::Zone const&, miral::Zone const&), (override));
MOCK_METHOD(void, advise_application_zone_delete, (miral::Zone const&), (override));
void handle_request_move(miral::WindowInfo& /*window_info*/, MirInputEvent const* /*input_event*/) {}
void handle_request_resize(miral::WindowInfo& /*window_info*/, MirInputEvent const* /*input_event*/, MirResizeEdge /*edge*/) {}
mir::geometry::Rectangle confirm_placement_on_display(const miral::WindowInfo&, MirWindowState, mir::geometry::Rectangle const& new_placement)
{
return new_placement;
}
};
class TestWindowManagerTools : public testing::Test
{
private:
struct Self;
std::unique_ptr<Self> self;
public:
TestWindowManagerTools();
~TestWindowManagerTools();
std::shared_ptr<mir::scene::Session> session;
MockWindowManagerPolicy* window_manager_policy;
miral::WindowManagerTools window_manager_tools;
miral::BasicWindowManager basic_window_manager;
static auto create_surface(
std::shared_ptr<mir::scene::Session> const& session,
mir::shell::SurfaceSpecification const& params) -> std::shared_ptr<mir::scene::Surface>;
auto static create_fake_display_configuration(std::vector<miral::Rectangle> const& outputs)
-> std::shared_ptr<graphics::DisplayConfiguration const>;
auto static create_fake_display_configuration(
std::vector<std::pair<graphics::DisplayConfigurationLogicalGroupId, miral::Rectangle>> const& outputs)
-> std::shared_ptr<graphics::DisplayConfiguration const>;
void notify_configuration_applied(
std::shared_ptr<graphics::DisplayConfiguration const> display_config);
/// Creates a new session, adds a surface to the session, and then sets the resulting window as
/// the active window.
/// \param creation_parameters
/// \returns The active window
auto create_and_select_window(mir::shell::SurfaceSpecification& creation_parameters) -> miral::Window;
/// Creates a new session, adds the provided surface to the session, and then sets the resulting window as
/// the active window.
auto create_and_select_window_for_session(mir::shell::SurfaceSpecification&, std::shared_ptr<scene::Session>) -> miral::Window;
};
struct StubStubSession : mir::test::doubles::StubSession
{
auto create_surface(
std::shared_ptr<mir::scene::Session> const & /*session*/,
mir::shell::SurfaceSpecification const ¶ms,
std::shared_ptr<mir::scene::SurfaceObserver> const & /*observer*/,
mir::Executor *) -> std::shared_ptr<mir::scene::Surface> override;
private:
std::atomic<int> next_surface_id;
std::map<mir::frontend::SurfaceId, std::shared_ptr<mir::scene::Surface>> surfaces;
};
}
}
#endif //MIRAL_TEST_WINDOW_MANAGER_TOOLS_H
|