2
* Copyright (C) 2013-2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License version 3, as published by
6
* the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <condition_variable>
21
#include "promptsession.h"
22
#include <Unity/Application/session.h>
24
#include "qtmir_test.h"
26
using namespace qtmir;
27
using mir::scene::MockSession;
29
namespace ms = mir::scene;
31
class SessionManagerTests : public ::testing::QtMirTest
37
QList<qtmir::PromptSession> listPromptSessions(SessionInterface* session) {
38
QList<qtmir::PromptSession> promptSessions;
39
session->foreachPromptSession([&promptSessions](const qtmir::PromptSession &promptSession) {
40
promptSessions << promptSession;
42
return promptSessions;
45
QList<SessionInterface*> listChildSessions(SessionInterface* session) {
46
QList<SessionInterface*> sessions;
47
session->foreachChildSession([&sessions](SessionInterface* session) {
54
TEST_F(SessionManagerTests, sessionTracksPromptSession)
56
using namespace testing;
58
std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);
59
miral::Application app(mirAppSession);
60
miral::ApplicationInfo appInfo(app);
61
sessionManager.onSessionStarting(appInfo);
62
SessionInterface* qtmirAppSession = sessionManager.findSession(mirAppSession.get());
63
EXPECT_TRUE(qtmirAppSession != nullptr);
65
qtmir::PromptSession promptSession{std::make_shared<ms::MockPromptSession>()};
66
ON_CALL(*stubPromptSessionManager, application_for(_)).WillByDefault(Return(mirAppSession));
68
sessionManager.onPromptSessionStarting(promptSession);
70
EXPECT_EQ(qtmirAppSession->activePromptSession(), promptSession);
72
sessionManager.onPromptSessionStopping(promptSession);
74
EXPECT_EQ(qtmirAppSession->activePromptSession(), nullptr);
76
delete qtmirAppSession;
80
TEST_F(SessionManagerTests, TestPromptSession)
82
using namespace testing;
84
std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);
85
miral::Application app(mirAppSession);
86
miral::ApplicationInfo appInfo(app);
87
sessionManager.onSessionStarting(appInfo);
88
SessionInterface* qtmirAppSession = sessionManager.findSession(mirAppSession.get());
89
EXPECT_TRUE(qtmirAppSession != nullptr);
91
EXPECT_CALL(*stubPromptSessionManager, application_for(_)).WillRepeatedly(Return(mirAppSession));
92
EXPECT_CALL(*stubPromptSessionManager, helper_for(_)).WillRepeatedly(Return(nullptr));
94
std::shared_ptr<ms::PromptSession> mirPromptSession = std::make_shared<ms::MockPromptSession>();
95
qtmir::PromptSession promptSession{mirPromptSession};
97
// prompt provider session
98
std::shared_ptr<ms::Session> mirProviderSession = std::make_shared<MockSession>("mirProviderSession", __LINE__);
99
miral::Application providerApp(mirProviderSession);
100
miral::ApplicationInfo providerAppInfo(providerApp);
101
sessionManager.onSessionStarting(providerAppInfo);
102
SessionInterface* qtmirProviderSession = sessionManager.findSession(mirProviderSession.get());
104
EXPECT_CALL(*stubPromptSessionManager, for_each_provider_in(mirPromptSession,_)).WillRepeatedly(WithArgs<1>(Invoke(
105
[&](std::function<void(std::shared_ptr<ms::Session> const& prompt_provider)> const& f) {
106
f(mirProviderSession);
109
EXPECT_THAT(listPromptSessions(qtmirAppSession), IsEmpty());
111
sessionManager.onPromptSessionStarting(promptSession);
113
EXPECT_THAT(listPromptSessions(qtmirAppSession), ElementsAre(mirPromptSession));
114
EXPECT_THAT(listChildSessions(qtmirAppSession), IsEmpty());
116
sessionManager.onPromptProviderAdded(promptSession, mirProviderSession);
118
EXPECT_THAT(listChildSessions(qtmirAppSession), ElementsAre(qtmirProviderSession));
120
EXPECT_CALL(*stubPromptSessionManager, for_each_provider_in(mirPromptSession,_)).WillRepeatedly(InvokeWithoutArgs([]{}));
122
EXPECT_EQ(qtmirProviderSession->live(), true);
123
sessionManager.onPromptProviderRemoved(promptSession, mirProviderSession);
124
EXPECT_EQ(qtmirProviderSession->live(), false);
126
sessionManager.onPromptSessionStopping(promptSession);
128
EXPECT_THAT(listPromptSessions(qtmirAppSession), IsEmpty());
130
delete qtmirProviderSession;
131
delete qtmirAppSession;