2
* Copyright © 2013-2015 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 "mir/scene/surface.h"
21
#include "mir_test_framework/connected_client_with_a_surface.h"
23
#include "mir/shell/canonical_window_manager.h"
25
#include "mir_toolkit/mir_client_library.h"
27
#include <gtest/gtest.h>
28
#include <gmock/gmock.h>
30
namespace ms = mir::scene;
31
namespace msh = mir::shell;
33
namespace mtf = mir_test_framework;
34
using namespace ::testing;
38
struct MockWindowManager : msh::CanonicalWindowManager
40
using msh::CanonicalWindowManager::CanonicalWindowManager;
42
MOCK_METHOD4(set_surface_attribute,
43
int(std::shared_ptr<ms::Session> const& session,
44
std::shared_ptr<ms::Surface> const& surface,
45
MirSurfaceAttrib attrib,
48
int real_set_surface_attribute(std::shared_ptr<ms::Session> const& session,
49
std::shared_ptr<ms::Surface> const& surface,
50
MirSurfaceAttrib attrib,
53
return msh::CanonicalWindowManager::set_surface_attribute(session, surface, attrib, value);
57
struct ShellSurfaceConfiguration : mtf::ConnectedClientWithASurface
61
server.override_the_window_manager_builder([this]
62
(msh::FocusController* focus_controller) -> std::shared_ptr<msh::WindowManager>
64
mock_window_manager = std::make_shared<MockWindowManager>(
66
server.the_shell_display_layout());
68
ON_CALL(*mock_window_manager, set_surface_attribute(_, _, _, _))
69
.WillByDefault(Invoke(
70
mock_window_manager.get(), &MockWindowManager::real_set_surface_attribute));
72
EXPECT_CALL(*mock_window_manager,
73
set_surface_attribute(_, _, Ne(mir_surface_attrib_state), _))
76
return mock_window_manager;
79
mtf::ConnectedClientWithASurface::SetUp();
82
std::shared_ptr<MockWindowManager> mock_window_manager;
86
TEST_F(ShellSurfaceConfiguration, the_window_manager_is_notified_of_attribute_changes)
88
EXPECT_CALL(*mock_window_manager,
89
set_surface_attribute(_, _, mir_surface_attrib_state, Eq(mir_surface_state_maximized)));
91
mir_wait_for(mir_surface_set_state(surface, mir_surface_state_maximized));
93
EXPECT_THAT(mir_surface_get_state(surface), Eq(mir_surface_state_maximized));
96
TEST_F(ShellSurfaceConfiguration, the_window_manager_may_interfere_with_attribute_changes)
98
auto const set_to_vertmax = [this](
99
std::shared_ptr<ms::Session> const& session,
100
std::shared_ptr<ms::Surface> const& surface,
101
MirSurfaceAttrib attrib,
104
return mock_window_manager->real_set_surface_attribute(
105
session, surface, attrib, mir_surface_state_vertmaximized);
108
EXPECT_CALL(*mock_window_manager,
109
set_surface_attribute(_, _, mir_surface_attrib_state, Eq(mir_surface_state_maximized)))
110
.WillOnce(Invoke(set_to_vertmax));
112
mir_wait_for(mir_surface_set_state(surface, mir_surface_state_maximized));
114
EXPECT_THAT(mir_surface_get_state(surface), Eq(mir_surface_state_vertmaximized));