~andreas-pokorny/mir/use-input-channel-to-send-input

« back to all changes in this revision

Viewing changes to tests/unit-tests/scene/test_session_manager.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths
  • Date: 2014-04-09 09:59:17 UTC
  • mfrom: (1534.1.9 mir1)
  • Revision ID: tarmac-20140409095917-dptmdrdntzgc5sy2
scene, shell: sessions are part of the scene, so they should be in namespace scene.

Approved by Kevin DuBois, PS Jenkins bot, Alexandros Frantzis, Alberto Aguirre.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "mir/compositor/buffer_stream.h"
21
21
#include "src/server/scene/default_session_container.h"
22
22
#include "mir/scene/surface.h"
23
 
#include "mir/shell/session.h"
24
 
#include "mir/shell/session_listener.h"
25
 
#include "mir/shell/null_session_listener.h"
 
23
#include "mir/scene/session.h"
 
24
#include "mir/scene/session_listener.h"
 
25
#include "mir/scene/null_session_listener.h"
26
26
#include "mir/shell/surface_creation_parameters.h"
27
27
#include "src/server/scene/session_event_sink.h"
28
28
#include "src/server/scene/basic_surface.h"
54
54
{
55
55
struct MockSessionContainer : public ms::SessionContainer
56
56
{
57
 
    MOCK_METHOD1(insert_session, void(std::shared_ptr<msh::Session> const&));
58
 
    MOCK_METHOD1(remove_session, void(std::shared_ptr<msh::Session> const&));
59
 
    MOCK_CONST_METHOD1(successor_of, std::shared_ptr<msh::Session>(std::shared_ptr<msh::Session> const&));
60
 
    MOCK_CONST_METHOD1(for_each, void(std::function<void(std::shared_ptr<msh::Session> const&)>));
 
57
    MOCK_METHOD1(insert_session, void(std::shared_ptr<ms::Session> const&));
 
58
    MOCK_METHOD1(remove_session, void(std::shared_ptr<ms::Session> const&));
 
59
    MOCK_CONST_METHOD1(successor_of, std::shared_ptr<ms::Session>(std::shared_ptr<ms::Session> const&));
 
60
    MOCK_CONST_METHOD1(for_each, void(std::function<void(std::shared_ptr<ms::Session> const&)>));
61
61
    MOCK_METHOD0(lock, void());
62
62
    MOCK_METHOD0(unlock, void());
63
63
    ~MockSessionContainer() noexcept {}
65
65
 
66
66
struct MockSessionEventSink : public ms::SessionEventSink
67
67
{
68
 
    MOCK_METHOD1(handle_focus_change, void(std::shared_ptr<msh::Session> const& session));
 
68
    MOCK_METHOD1(handle_focus_change, void(std::shared_ptr<ms::Session> const& session));
69
69
    MOCK_METHOD0(handle_no_focus, void());
70
 
    MOCK_METHOD1(handle_session_stopping, void(std::shared_ptr<msh::Session> const& session));
 
70
    MOCK_METHOD1(handle_session_stopping, void(std::shared_ptr<ms::Session> const& session));
71
71
};
72
72
 
73
73
struct SessionManagerSetup : public testing::Test
81
81
                        mt::fake_shared(session_listener))
82
82
    {
83
83
        using namespace ::testing;
84
 
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<msh::Session>())));
 
84
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<ms::Session>())));
85
85
    }
86
86
 
87
87
    std::shared_ptr<ms::Surface> dummy_surface = std::make_shared<ms::BasicSurface>(
95
95
    mtd::MockSurfaceCoordinator surface_coordinator;
96
96
    testing::NiceMock<MockSessionContainer> container;    // Inelegant but some tests need a stub
97
97
    testing::NiceMock<mtd::MockFocusSetter> focus_setter; // Inelegant but some tests need a stub
98
 
    msh::NullSessionListener session_listener;
 
98
    ms::NullSessionListener session_listener;
99
99
 
100
100
    ms::SessionManager session_manager;
101
101
};
109
109
    EXPECT_CALL(container, insert_session(_)).Times(1);
110
110
    EXPECT_CALL(container, remove_session(_)).Times(1);
111
111
    EXPECT_CALL(focus_setter, set_focus_to(_));
112
 
    EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);
 
112
    EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<ms::Session>())).Times(1);
113
113
 
114
114
    auto session = session_manager.open_session(__LINE__, "Visual Basic Studio", std::shared_ptr<mf::EventSink>());
115
115
    session_manager.close_session(session);
128
128
    EXPECT_CALL(container, remove_session(_)).Times(1);
129
129
 
130
130
    EXPECT_CALL(focus_setter, set_focus_to(_)).Times(1);
131
 
    EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<msh::Session>())).Times(1);
 
131
    EXPECT_CALL(focus_setter, set_focus_to(std::shared_ptr<ms::Session>())).Times(1);
132
132
 
133
133
    auto session = session_manager.open_session(__LINE__, "Visual Basic Studio", std::shared_ptr<mf::EventSink>());
134
134
    session->create_surface(msh::a_surface().of_size(geom::Size{geom::Width{1024}, geom::Height{768}}));
139
139
TEST_F(SessionManagerSetup, new_applications_receive_focus)
140
140
{
141
141
    using namespace ::testing;
142
 
    std::shared_ptr<msh::Session> new_session;
 
142
    std::shared_ptr<ms::Session> new_session;
143
143
 
144
144
    EXPECT_CALL(container, insert_session(_)).Times(1);
145
145
    EXPECT_CALL(focus_setter, set_focus_to(_)).WillOnce(SaveArg<0>(&new_session));
181
181
                        mt::fake_shared(session_listener))
182
182
    {
183
183
        using namespace ::testing;
184
 
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<msh::Session>())));
 
184
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<ms::Session>())));
185
185
    }
186
186
 
187
187
    mtd::MockSurfaceCoordinator surface_coordinator;
217
217
                        mt::fake_shared(focus_setter),
218
218
                        std::make_shared<mtd::NullSnapshotStrategy>(),
219
219
                        mt::fake_shared(session_event_sink),
220
 
                        std::make_shared<msh::NullSessionListener>())
 
220
                        std::make_shared<ms::NullSessionListener>())
221
221
    {
222
222
        using namespace ::testing;
223
 
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<msh::Session>())));
 
223
        ON_CALL(container, successor_of(_)).WillByDefault(Return((std::shared_ptr<ms::Session>())));
224
224
    }
225
225
 
226
226
    mtd::MockSurfaceCoordinator surface_coordinator;
247
247
    InSequence s;
248
248
    EXPECT_CALL(session_event_sink, handle_session_stopping(_)).Times(1);
249
249
    EXPECT_CALL(container, successor_of(_)).
250
 
        WillOnce(Return(std::dynamic_pointer_cast<msh::Session>(session)));
 
250
        WillOnce(Return(std::dynamic_pointer_cast<ms::Session>(session)));
251
251
    EXPECT_CALL(session_event_sink, handle_focus_change(_)).Times(1);
252
252
    EXPECT_CALL(session_event_sink, handle_session_stopping(_)).Times(1);
253
253
    EXPECT_CALL(container, successor_of(_)).
254
 
        WillOnce(Return(std::shared_ptr<msh::Session>()));
 
254
        WillOnce(Return(std::shared_ptr<ms::Session>()));
255
255
    EXPECT_CALL(session_event_sink, handle_no_focus()).Times(1);
256
256
 
257
257
    session_manager.close_session(session1);