Skip to content

Commit

Permalink
Merge #2184
Browse files Browse the repository at this point in the history
2184: Tidy up ModifyWindowState tests r=wmww a=AlanGriffiths



Co-authored-by: Alan Griffiths <[email protected]>
  • Loading branch information
bors[bot] and AlanGriffiths authored Oct 1, 2021
2 parents f046e70 + 5d0b8e8 commit a8206f1
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions tests/miral/modify_window_state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2016 Canonical Ltd.
* Copyright © 2016-2021 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
Expand Down Expand Up @@ -34,7 +34,7 @@ Height const display_height{480};
Rectangle const display_area{{display_left, display_top},
{display_width, display_height}};

struct ModifyWindowState : mt::TestWindowManagerTools, WithParamInterface<MirWindowType>
struct ModifyWindowState : mt::TestWindowManagerTools, WithParamInterface<MirWindowState>
{
Size const initial_parent_size{600, 400};

Expand Down Expand Up @@ -64,31 +64,41 @@ struct ModifyWindowState : mt::TestWindowManagerTools, WithParamInterface<MirWin
// Clear the expectations used to capture parent & child
Mock::VerifyAndClearExpectations(window_manager_policy);
}

template<MirWindowType window_type>
void create_and_test_window_of_type(MirWindowState new_state)
{
auto const original_state = mir_window_state_restored;
auto const state_is_visible = (new_state != mir_window_state_minimized) && (new_state != mir_window_state_hidden);

create_window_of_type(window_type);
auto const& info = window_manager_tools.info_for(window);

WindowSpecification mods;
mods.state() = new_state;
window_manager_tools.modify_window(window, mods);
EXPECT_THAT(std::shared_ptr<mir::scene::Surface>(window)->state(), Eq(new_state));
EXPECT_THAT(info.state(), Eq(new_state));
EXPECT_THAT(info.is_visible(), Eq(state_is_visible)) << "State is " << new_state;

mods.state() = original_state;
window_manager_tools.modify_window(window, mods);
EXPECT_THAT(std::shared_ptr<mir::scene::Surface>(window)->state(), Eq(original_state));
EXPECT_THAT(info.state(), Eq(original_state));
EXPECT_TRUE(info.is_visible());
}
};

using ForNormalSurface = ModifyWindowState;

TEST_P(ForNormalSurface, state)
{
auto const original_state = mir_window_state_restored;
auto const new_state = MirWindowState(GetParam());
auto const state_is_visible = (new_state != mir_window_state_minimized) && (new_state != mir_window_state_hidden);

create_window_of_type(mir_window_type_normal);
auto const& info = window_manager_tools.info_for(window);

WindowSpecification mods;
mods.state() = new_state;
window_manager_tools.modify_window(window, mods);
EXPECT_THAT(std::shared_ptr<mir::scene::Surface>(window)->state(), Eq(new_state));
EXPECT_THAT(info.state(), Eq(new_state));
EXPECT_THAT(info.is_visible(), Eq(state_is_visible)) << "State is " << new_state;

mods.state() = original_state;
window_manager_tools.modify_window(window, mods);
EXPECT_THAT(std::shared_ptr<mir::scene::Surface>(window)->state(), Eq(original_state));
EXPECT_THAT(info.state(), Eq(original_state));
EXPECT_TRUE(info.is_visible());
create_and_test_window_of_type<mir_window_type_normal>(GetParam());
}

using ForFreestyleSurface = ModifyWindowState;
TEST_P(ForFreestyleSurface, state)
{
create_and_test_window_of_type<mir_window_type_freestyle>(GetParam());
}
}

Expand All @@ -103,3 +113,15 @@ INSTANTIATE_TEST_SUITE_P(ModifyWindowState, ForNormalSurface, ::testing::Values(
mir_window_state_hidden
// mir_window_states
));

INSTANTIATE_TEST_SUITE_P(ModifyWindowState, ForFreestyleSurface, ::testing::Values(
// mir_window_state_unknown,
mir_window_state_restored,
mir_window_state_minimized,
mir_window_state_maximized,
mir_window_state_vertmaximized,
mir_window_state_fullscreen,
mir_window_state_horizmaximized,
mir_window_state_hidden
// mir_window_states
));

0 comments on commit a8206f1

Please sign in to comment.