~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/throwback/test_shell_control_of_surface_configuration.cpp

  • Committer: Package Import Robot
  • Author(s): Alexandros Frantzis
  • Date: 2015-10-08 16:12:19 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: package-import@ubuntu.com-20151008161219-emk4a1ys51yy0wjb
Tags: upstream-0.17.0+15.10.20151008.2
Import upstream version 0.17.0+15.10.20151008.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013-2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Robert Carr <robert.carr@canonical.com>
 
17
 */
 
18
 
 
19
#include "mir/scene/surface.h"
 
20
 
 
21
#include "mir_test_framework/connected_client_with_a_surface.h"
 
22
 
 
23
#include "mir/shell/canonical_window_manager.h"
 
24
 
 
25
#include "mir_toolkit/mir_client_library.h"
 
26
 
 
27
#include <gtest/gtest.h>
 
28
#include <gmock/gmock.h>
 
29
 
 
30
namespace ms = mir::scene;
 
31
namespace msh = mir::shell;
 
32
 
 
33
namespace mtf = mir_test_framework;
 
34
using namespace ::testing;
 
35
 
 
36
namespace
 
37
{
 
38
struct MockWindowManager : msh::CanonicalWindowManager
 
39
{
 
40
    using msh::CanonicalWindowManager::CanonicalWindowManager;
 
41
 
 
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,
 
46
            int value));
 
47
 
 
48
    int real_set_surface_attribute(std::shared_ptr<ms::Session> const& session,
 
49
                std::shared_ptr<ms::Surface> const& surface,
 
50
                MirSurfaceAttrib attrib,
 
51
                int value)
 
52
    {
 
53
        return msh::CanonicalWindowManager::set_surface_attribute(session, surface, attrib, value);
 
54
    }
 
55
};
 
56
 
 
57
struct ShellSurfaceConfiguration : mtf::ConnectedClientWithASurface
 
58
{
 
59
    void SetUp() override
 
60
    {
 
61
        server.override_the_window_manager_builder([this]
 
62
            (msh::FocusController* focus_controller) -> std::shared_ptr<msh::WindowManager>
 
63
            {
 
64
                mock_window_manager = std::make_shared<MockWindowManager>(
 
65
                    focus_controller,
 
66
                    server.the_shell_display_layout());
 
67
 
 
68
                ON_CALL(*mock_window_manager, set_surface_attribute(_, _, _, _))
 
69
                    .WillByDefault(Invoke(
 
70
                        mock_window_manager.get(), &MockWindowManager::real_set_surface_attribute));
 
71
 
 
72
                EXPECT_CALL(*mock_window_manager,
 
73
                    set_surface_attribute(_, _, Ne(mir_surface_attrib_state), _))
 
74
                    .Times(AnyNumber());
 
75
 
 
76
                return mock_window_manager;
 
77
            });
 
78
 
 
79
        mtf::ConnectedClientWithASurface::SetUp();
 
80
    }
 
81
 
 
82
    std::shared_ptr<MockWindowManager> mock_window_manager;
 
83
};
 
84
}
 
85
 
 
86
TEST_F(ShellSurfaceConfiguration, the_window_manager_is_notified_of_attribute_changes)
 
87
{
 
88
    EXPECT_CALL(*mock_window_manager,
 
89
        set_surface_attribute(_, _, mir_surface_attrib_state, Eq(mir_surface_state_maximized)));
 
90
 
 
91
    mir_wait_for(mir_surface_set_state(surface, mir_surface_state_maximized));
 
92
 
 
93
    EXPECT_THAT(mir_surface_get_state(surface), Eq(mir_surface_state_maximized));
 
94
}
 
95
 
 
96
TEST_F(ShellSurfaceConfiguration, the_window_manager_may_interfere_with_attribute_changes)
 
97
{
 
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,
 
102
        int /*value*/)
 
103
    {
 
104
        return mock_window_manager->real_set_surface_attribute(
 
105
            session, surface, attrib, mir_surface_state_vertmaximized);
 
106
    };
 
107
 
 
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));
 
111
 
 
112
    mir_wait_for(mir_surface_set_state(surface, mir_surface_state_maximized));
 
113
 
 
114
    EXPECT_THAT(mir_surface_get_state(surface), Eq(mir_surface_state_vertmaximized));
 
115
}