Merge lp:~alan-griffiths/miral/DragActiveWindow-tests into lp:miral

Proposed by Alan Griffiths
Status: Merged
Approved by: Gerry Boland
Approved revision: 342
Merged at revision: 340
Proposed branch: lp:~alan-griffiths/miral/DragActiveWindow-tests
Merge into: lp:miral
Diff against target: 167 lines (+152/-0)
2 files modified
test/CMakeLists.txt (+1/-0)
test/drag_active_window.cpp (+151/-0)
To merge this branch: bzr merge lp:~alan-griffiths/miral/DragActiveWindow-tests
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Review via email: mp+305910@code.launchpad.net

Commit message

Test that rules for user positioning of surfaces are applied by WindowManagerTools::drag_active_window()

To post a comment you must log in.
Revision history for this message
Gerry Boland (gerboland) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/CMakeLists.txt'
2--- test/CMakeLists.txt 2016-09-15 16:07:43 +0000
3+++ test/CMakeLists.txt 2016-09-16 08:39:38 +0000
4@@ -33,6 +33,7 @@
5 persistent_surface_store.cpp
6 runner.cpp
7 window_placement.cpp
8+ drag_active_window.cpp
9 test_server.cpp test_server.h
10 test_window_manager_tools.h
11 )
12
13=== added file 'test/drag_active_window.cpp'
14--- test/drag_active_window.cpp 1970-01-01 00:00:00 +0000
15+++ test/drag_active_window.cpp 2016-09-16 08:39:38 +0000
16@@ -0,0 +1,151 @@
17+/*
18+ * Copyright © 2016 Canonical Ltd.
19+ *
20+ * This program is free software: you can redistribute it and/or modify it
21+ * under the terms of the GNU General Public License version 3,
22+ * as published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
33+ */
34+
35+#include "test_window_manager_tools.h"
36+#include <mir/event_printer.h>
37+
38+using namespace miral;
39+using namespace testing;
40+namespace mt = mir::test;
41+using mir::operator<<;
42+
43+namespace
44+{
45+X const display_left{0};
46+Y const display_top{0};
47+Width const display_width{640};
48+Height const display_height{480};
49+
50+Rectangle const display_area{{display_left, display_top},
51+ {display_width, display_height}};
52+
53+auto const null_window = Window{};
54+
55+auto
56+create_surface(std::shared_ptr<mir::scene::Session> const& session, mir::scene::SurfaceCreationParameters const& params)
57+-> mir::frontend::SurfaceId
58+{
59+ // This type is Mir-internal, I hope we don't need to create it here
60+ std::shared_ptr<mir::frontend::EventSink> const sink;
61+
62+ return session->create_surface(params, sink);
63+}
64+
65+struct DragActiveWindow : TestWindowManagerTools, WithParamInterface<MirSurfaceType>
66+{
67+ Size const initial_parent_size{600, 400};
68+
69+ Window window;
70+
71+ void SetUp() override
72+ {
73+ basic_window_manager.add_display(display_area);
74+ basic_window_manager.add_session(session);
75+ }
76+
77+ void create_window_of_type(MirSurfaceType type)
78+ {
79+ mir::scene::SurfaceCreationParameters creation_parameters;
80+ creation_parameters.type = type;
81+ creation_parameters.size = initial_parent_size;
82+
83+ EXPECT_CALL(*window_manager_policy, advise_new_window(_))
84+ .WillOnce(
85+ Invoke(
86+ [this](WindowInfo const& window_info)
87+ { window = window_info.window(); }));
88+
89+ basic_window_manager.add_surface(session, creation_parameters, &create_surface);
90+ basic_window_manager.select_active_window(window);
91+
92+ // Clear the expectations used to capture parent & child
93+ Mock::VerifyAndClearExpectations(window_manager_policy);
94+ }
95+};
96+}
97+
98+using ForMoveableTypes = DragActiveWindow;
99+using ForUnmoveableTypes = DragActiveWindow;
100+
101+TEST_P(ForMoveableTypes, moves)
102+{
103+ create_window_of_type(GetParam());
104+
105+ Displacement const movement{10, 10};
106+ auto const initial_position = window.top_left();
107+ auto const expected_position = initial_position + movement;
108+
109+ EXPECT_CALL(*window_manager_policy, advise_move_to(_, expected_position));
110+
111+ window_manager_tools.drag_active_window(movement);
112+
113+ EXPECT_THAT(window.top_left(), Eq(expected_position))
114+ << "Type: " << GetParam();
115+}
116+
117+TEST_P(ForUnmoveableTypes, doesnt_move)
118+{
119+ create_window_of_type(GetParam());
120+
121+ Displacement const movement{10, 10};
122+ auto const expected_position = window.top_left();
123+
124+ EXPECT_CALL(*window_manager_policy, advise_move_to(_, _)).Times(0);
125+
126+ window_manager_tools.drag_active_window(movement);
127+
128+ EXPECT_THAT(window.top_left(), Eq(expected_position))
129+ << "Type: " << GetParam();
130+}
131+
132+// When a surface is moved interactively
133+// -------------------------------------
134+// Regular, floating regular, dialog, and satellite surfaces should be user-movable.
135+// Popups, glosses, and tips should not be.
136+// Freestyle surfaces may or may not be, as specified by the app.
137+// Mir and Unity: Surfaces, input, and displays (v0.3)
138+INSTANTIATE_TEST_CASE_P(DragActiveWindow, ForMoveableTypes, ::testing::Values(
139+ mir_surface_type_normal,
140+ mir_surface_type_utility,
141+ mir_surface_type_dialog,
142+// mir_surface_type_overlay,
143+// mir_surface_type_gloss,
144+ mir_surface_type_freestyle,
145+// mir_surface_type_popover,
146+// mir_surface_type_menu,
147+// mir_surface_type_inputmethod,
148+ mir_surface_type_satellite
149+// mir_surface_type_tip,
150+// mir_surface_types
151+));
152+
153+
154+INSTANTIATE_TEST_CASE_P(DragActiveWindow, ForUnmoveableTypes, ::testing::Values(
155+// mir_surface_type_normal,
156+// mir_surface_type_utility,
157+// mir_surface_type_dialog,
158+ mir_surface_type_overlay,
159+ mir_surface_type_gloss,
160+// mir_surface_type_freestyle,
161+ mir_surface_type_popover,
162+ mir_surface_type_menu,
163+ mir_surface_type_inputmethod,
164+// mir_surface_type_satellite,
165+ mir_surface_type_tip
166+// mir_surface_types
167+));

Subscribers

People subscribed via source and target branches