2
* Copyright © 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Robert Carr <robert.carr@canonical.com>
19
#include "src/server/shell/organising_surface_factory.h"
20
#include "mir/shell/placement_strategy.h"
21
#include "mir/shell/surface_creation_parameters.h"
22
#include "mir/shell/session.h"
23
#include "mir/scene/surface.h"
24
#include "mir/scene/surface_event_source.h"
25
#include "mir/scene/surface_coordinator.h"
27
#include "mir_test_doubles/stub_shell_session.h"
28
#include "mir_test_doubles/null_event_sink.h"
30
#include <gtest/gtest.h>
31
#include <gmock/gmock.h>
33
namespace mf = mir::frontend;
34
namespace ms = mir::scene;
35
namespace msh = mir::shell;
36
namespace geom = mir::geometry;
37
namespace mtd = mir::test::doubles;
41
struct MockSurfaceCoordinator : public ms::SurfaceCoordinator
43
MOCK_METHOD2(add_surface, std::shared_ptr<ms::Surface>(
44
msh::SurfaceCreationParameters const&,
45
std::shared_ptr<ms::SurfaceObserver> const&));
47
void remove_surface(std::weak_ptr<ms::Surface> const& /*surface*/) override {}
48
void raise(std::weak_ptr<ms::Surface> const& /*surface*/) override {}
51
struct MockPlacementStrategy : public msh::PlacementStrategy
53
MOCK_METHOD2(place, msh::SurfaceCreationParameters(msh::Session const&, msh::SurfaceCreationParameters const&));
56
struct OrganisingSurfaceFactorySetup : public testing::Test
60
using namespace ::testing;
61
ON_CALL(*surface_coordinator, add_surface(_, _)).WillByDefault(Return(null_surface));
63
std::shared_ptr<ms::Surface> null_surface;
64
std::shared_ptr<MockSurfaceCoordinator> surface_coordinator = std::make_shared<MockSurfaceCoordinator>();
65
std::shared_ptr<ms::SurfaceObserver> const observer = std::make_shared<ms::SurfaceEventSource>(mf::SurfaceId(), std::make_shared<mtd::NullEventSink>());
66
std::shared_ptr<MockPlacementStrategy> placement_strategy = std::make_shared<MockPlacementStrategy>();
71
TEST_F(OrganisingSurfaceFactorySetup, offers_create_surface_parameters_to_placement_strategy)
73
using namespace ::testing;
75
msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
77
mtd::StubShellSession session;
78
EXPECT_CALL(*surface_coordinator, add_surface(_, _)).Times(1);
80
auto params = msh::a_surface();
81
EXPECT_CALL(*placement_strategy, place(Ref(session), Ref(params))).Times(1)
82
.WillOnce(Return(msh::a_surface()));
84
factory.create_surface(&session, params, observer);
87
TEST_F(OrganisingSurfaceFactorySetup, forwards_create_surface_parameters_from_placement_strategy_to_underlying_factory)
89
using namespace ::testing;
91
msh::OrganisingSurfaceFactory factory(surface_coordinator, placement_strategy);
93
auto params = msh::a_surface();
94
auto placed_params = params;
95
placed_params.size.width = geom::Width{100};
97
EXPECT_CALL(*placement_strategy, place(_, Ref(params))).Times(1)
98
.WillOnce(Return(placed_params));
99
EXPECT_CALL(*surface_coordinator, add_surface(placed_params, _));
101
factory.create_surface(nullptr, params, observer);