Mir

Merge lp:~alan-griffiths/mir/fix-1302689 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1540
Proposed branch: lp:~alan-griffiths/mir/fix-1302689
Merge into: lp:mir
Diff against target: 182 lines (+155/-1)
3 files modified
src/server/shell/default_focus_mechanism.cpp (+1/-1)
tests/integration-tests/CMakeLists.txt (+1/-0)
tests/integration-tests/session_management.cpp (+153/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1302689
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Chris Halse Rogers Approve
Review via email: mp+214449@code.launchpad.net

Commit message

tests: Provide an integration test that focusing on a session raises its default surface.

Description of the change

tests: Provide an integration test that focusing on a session raises its default surface.

We didn't quite have a test that covers this, but adding the test seems to disprove the assertion in lp:1302689 that this doesn't work.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

LGTM

review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

Nit:

108 + the_surface_stack_model()

Missing "override". I have fallen into the trap of "overriding" non-existent methods a couple of times during test development, rendering my results meaningless.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Not sure there is any bug yet. But this change doesn't hurt.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/shell/default_focus_mechanism.cpp'
2--- src/server/shell/default_focus_mechanism.cpp 2014-04-03 13:17:52 +0000
3+++ src/server/shell/default_focus_mechanism.cpp 2014-04-07 10:44:44 +0000
4@@ -54,7 +54,7 @@
5 surface->configure(mir_surface_attrib_focus, mir_surface_focused);
6 currently_focused_surface = surface;
7
8- surface_coordinator->raise(std::static_pointer_cast<ms::Surface>(surface)); // TODO deal with cast
9+ surface_coordinator->raise(surface);
10 surface->take_input_focus(input_targeter);
11 }
12 else
13
14=== modified file 'tests/integration-tests/CMakeLists.txt'
15--- tests/integration-tests/CMakeLists.txt 2014-03-06 06:05:17 +0000
16+++ tests/integration-tests/CMakeLists.txt 2014-04-07 10:44:44 +0000
17@@ -13,6 +13,7 @@
18 test_server_client_types.cpp
19 test_session_manager.cpp
20 test_session.cpp
21+ session_management.cpp
22 )
23
24 add_subdirectory(client/)
25
26=== added file 'tests/integration-tests/session_management.cpp'
27--- tests/integration-tests/session_management.cpp 1970-01-01 00:00:00 +0000
28+++ tests/integration-tests/session_management.cpp 2014-04-07 10:44:44 +0000
29@@ -0,0 +1,153 @@
30+/*
31+ * Copyright © 2014 Canonical Ltd.
32+ *
33+ * This program is free software: you can redistribute it and/or modify it
34+ * under the terms of the GNU General Public License version 3,
35+ * as published by the Free Software Foundation.
36+ *
37+ * This program is distributed in the hope that it will be useful,
38+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+ * GNU General Public License for more details.
41+ *
42+ * You should have received a copy of the GNU General Public License
43+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
44+ *
45+ * Authored By: Alan Griffiths <alan@octopull.co.uk>
46+ */
47+
48+#include "mir/frontend/session.h"
49+#include "mir/frontend/shell.h"
50+#include "mir/input/input_configuration.h"
51+
52+#include "mir/shell/surface_creation_parameters.h"
53+#include "mir/shell/session.h"
54+#include "mir/shell/focus_controller.h"
55+
56+#include "mir/scene/surface.h"
57+#include "src/server/scene/surface_stack.h"
58+
59+#include "mir_test_doubles/null_event_sink.h"
60+#include "mir_test_framework/stubbed_server_configuration.h"
61+
62+#include <gmock/gmock.h>
63+#include <gtest/gtest.h>
64+
65+#include <vector>
66+
67+namespace mf = mir::frontend;
68+namespace mo = mir::options;
69+namespace ms = mir::scene;
70+namespace msh = mir::shell;
71+namespace mtd = mir::test::doubles;
72+
73+using namespace testing;
74+
75+namespace
76+{
77+struct TestSurfaceStack : public ms::SurfaceStack
78+{
79+ using ms::SurfaceStack::SurfaceStack;
80+
81+ MOCK_METHOD3(add_surface, void(
82+ std::shared_ptr<ms::Surface> const& surface,
83+ ms::DepthId depth,
84+ mir::input::InputReceptionMode input_mode));
85+
86+ MOCK_METHOD1(raise, void(
87+ std::weak_ptr<ms::Surface> const& surface));
88+
89+ void default_add_surface(
90+ std::shared_ptr<ms::Surface> const& surface,
91+ ms::DepthId depth,
92+ mir::input::InputReceptionMode input_mode)
93+ {
94+ ms::SurfaceStack::add_surface(surface, depth, input_mode);
95+ }
96+
97+ void default_raise(std::weak_ptr<ms::Surface> const& surface)
98+ {
99+ ms::SurfaceStack::raise(surface);
100+ }
101+
102+};
103+
104+struct TestConfiguration : public mir_test_framework::StubbedServerConfiguration
105+{
106+
107+ std::shared_ptr<ms::SurfaceStackModel>
108+ the_surface_stack_model() override
109+ {
110+ return surface_stack(
111+ [this]()
112+ {
113+ auto const scene_report = the_scene_report();
114+
115+ test_surface_stack = std::make_shared<TestSurfaceStack>(
116+ the_input_registrar(),
117+ scene_report);
118+
119+ the_input_configuration()->set_input_targets(test_surface_stack);
120+
121+ return test_surface_stack;
122+ });
123+ }
124+
125+ std::shared_ptr<TestSurfaceStack> test_surface_stack;
126+};
127+
128+struct SessionManagement : Test
129+{
130+ TestConfiguration builder;
131+ std::shared_ptr<mf::EventSink> const event_sink = std::make_shared<mtd::NullEventSink>();
132+ std::shared_ptr<mf::Shell> const session_manager = builder.the_frontend_shell();
133+ std::shared_ptr<TestSurfaceStack> const& test_surface_stack = builder.test_surface_stack;
134+
135+ void SetUp()
136+ {
137+ ASSERT_THAT(test_surface_stack, Ne(nullptr));
138+ ON_CALL(*test_surface_stack, add_surface(_,_,_))
139+ .WillByDefault(Invoke(test_surface_stack.get(), &TestSurfaceStack::default_add_surface));
140+ ON_CALL(*test_surface_stack, raise(_))
141+ .WillByDefault(Invoke(test_surface_stack.get(), &TestSurfaceStack::default_raise));
142+ }
143+};
144+
145+MATCHER_P(WeakPtrTo, p, "")
146+{
147+ return arg.lock() == p;
148+}
149+}
150+
151+TEST_F(SessionManagement, creating_a_surface_adds_it_to_scene)
152+{
153+ msh::SurfaceCreationParameters params;
154+
155+ auto const session = session_manager->open_session(0, __PRETTY_FUNCTION__, event_sink);
156+
157+ EXPECT_CALL(*test_surface_stack, add_surface(_,_,_)).Times(1);
158+ session->create_surface(params);
159+}
160+
161+TEST_F(SessionManagement, focus_on_a_session_raises_its_surface)
162+{
163+ EXPECT_CALL(*test_surface_stack, add_surface(_,_,_)).Times(AnyNumber());
164+
165+ msh::SurfaceCreationParameters params;
166+
167+ auto const session1 = session_manager->open_session(0, __PRETTY_FUNCTION__, event_sink);
168+ auto const surface1 = session1->create_surface(params);
169+
170+ auto const session2 = session_manager->open_session(0, __PRETTY_FUNCTION__, event_sink);
171+ auto surface2 = session2->create_surface(params);
172+
173+ auto const focus_controller = builder.the_focus_controller();
174+ auto const shell_session = std::dynamic_pointer_cast<msh::Session>(session1);
175+
176+ EXPECT_CALL(*test_surface_stack, raise(WeakPtrTo(session1->get_surface(surface1)))).Times(1);
177+
178+ focus_controller->set_focus_to(shell_session);
179+
180+ session1->destroy_surface(surface1);
181+ session2->destroy_surface(surface2);
182+}

Subscribers

People subscribed via source and target branches