File: window_placement_output.cpp

package info (click to toggle)
mir 2.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,636 kB
  • sloc: cpp: 174,574; xml: 13,422; ansic: 8,221; python: 1,337; sh: 874; makefile: 216; javascript: 37
file content (108 lines) | stat: -rw-r--r-- 3,599 bytes parent folder | download | duplicates (2)
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
/*
 * 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/>.
 */

#include "test_window_manager_tools.h"

using namespace miral;
using namespace mir::graphics;
using namespace testing;
namespace mt = mir::test;
namespace ms = mir::scene;
namespace msh = mir::shell;

namespace
{
std::vector<Rectangle> const display = {{{20,  30}, {600, 400}}, {{620, 0},  {800, 500}}};

struct WindowPlacementOutput : mt::TestWindowManagerTools
{
    void SetUp() override
    {
        notify_configuration_applied(create_fake_display_configuration(display));
        basic_window_manager.add_session(session);
    }

    auto create_window(msh::SurfaceSpecification creation_parameters) -> Window
    {
        Window result;

        EXPECT_CALL(*window_manager_policy, advise_new_window(_))
            .WillOnce(
                Invoke(
                    [&result](WindowInfo const& window_info)
                        { result = window_info.window(); }));

        basic_window_manager.add_surface(session, creation_parameters, &create_surface);
        basic_window_manager.select_active_window(result);

        // Clear the expectations used to capture the window
        Mock::VerifyAndClearExpectations(window_manager_policy);

        return result;
    }
};

struct WhenOutputIsSpecified : WindowPlacementOutput, WithParamInterface<MirWindowState> {};
}

TEST_P(WhenOutputIsSpecified, window_is_initially_placed_on_it)
{
    Window window;
    {
        msh::SurfaceSpecification params;
        params.state = GetParam();
        params.output_id = DisplayConfigurationOutputId{2};
        window = create_window(params);
    }
    auto const& info = basic_window_manager.info_for(window);

    EXPECT_THAT(info.state(), Eq(GetParam()));
    EXPECT_TRUE(display[1].contains(Rectangle{window.top_left(), window.size()}))
        << "display=" << display[1] <<", window=" << Rectangle{window.top_left(), window.size()};
}

TEST_P(WhenOutputIsSpecified, window_is_moved_to_it)
{
    Window window;
    {
        msh::SurfaceSpecification params;
        params.state = mir_window_state_minimized;
        window = create_window(params);
    }

    {
        WindowSpecification modifications;
        modifications.state() = GetParam();
        modifications.output_id() = 2;

        auto& info = basic_window_manager.info_for(window);
        basic_window_manager.place_and_size_for_state(modifications, info);
        basic_window_manager.modify_window(info, modifications);
    }

    auto const& info = basic_window_manager.info_for(window);
    EXPECT_THAT(info.state(), Eq(GetParam()));
    EXPECT_TRUE(display[1].contains(Rectangle{window.top_left(), window.size()}))
        << "display=" << display[1] <<", window=" << Rectangle{window.top_left(), window.size()};
}

INSTANTIATE_TEST_SUITE_P(WindowPlacementOutput, WhenOutputIsSpecified, ::testing::Values(
    mir_window_state_restored,
    mir_window_state_maximized,
    mir_window_state_vertmaximized,
    mir_window_state_fullscreen,
    mir_window_state_horizmaximized
));