~unity-team/qtmir/no-upstart-notification

« back to all changes in this revision

Viewing changes to tests/modules/ApplicationManager/application_manager_test.cpp

  • Committer: CI bot
  • Author(s): Nick Dedekind, Nick Dedekind
  • Date: 2014-09-03 08:03:38 UTC
  • mfrom: (222.2.44 qtmir)
  • Revision ID: ps-jenkins@lists.canonical.com-20140903080338-hp7zj6ldudmpompg
Added support for nested prompt sessions. Fixes: 1358388
Approved by: Gerry Boland, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 */
17
17
 
18
 
#include <Unity/Application/application_manager.h>
19
 
 
20
 
#include <Unity/Application/applicationcontroller.h>
21
 
#include <Unity/Application/taskcontroller.h>
22
 
#include <Unity/Application/proc_info.h>
23
 
#include <mirserverconfiguration.h>
24
 
 
25
 
#include <core/posix/linux/proc/process/oom_score_adj.h>
26
 
 
27
 
#include <gmock/gmock.h>
28
 
#include <gtest/gtest.h>
29
18
#include <thread>
30
19
#include <condition_variable>
31
20
#include <QSignalSpy>
32
21
 
33
22
#include <applicationscreenshotprovider.h>
34
23
 
35
 
#include "mock_application_controller.h"
36
 
#include "mock_desktop_file_reader.h"
37
 
#include "mock_oom_controller.h"
38
 
#include "mock_process_controller.h"
39
 
#include "mock_proc_info.h"
40
 
#include "mock_session.h"
41
 
#include "mock_surface.h"
42
 
#include "mock_focus_controller.h"
43
 
#include "mock_prompt_session_manager.h"
44
 
#include "mock_prompt_session.h"
 
24
 #include "mock_surface.h"
 
25
 #include "qtmir_test.h"
45
26
 
46
27
using namespace qtmir;
47
28
 
48
29
namespace ms = mir::scene;
49
30
 
50
 
class TestMirConfiguration: public MirServerConfiguration
51
 
{
52
 
public:
53
 
    TestMirConfiguration()
54
 
    : MirServerConfiguration(0, nullptr)
55
 
    , mock_prompt_session_manager(std::make_shared<testing::MockPromptSessionManager>())
56
 
    {
57
 
    }
58
 
 
59
 
    std::shared_ptr<ms::PromptSessionManager> the_prompt_session_manager() override
60
 
    {
61
 
        return prompt_session_manager([this]()
62
 
           ->std::shared_ptr<ms::PromptSessionManager>
63
 
           {
64
 
               return the_mock_prompt_session_manager();
65
 
           });
66
 
    }
67
 
 
68
 
    std::shared_ptr<testing::MockPromptSessionManager> the_mock_prompt_session_manager()
69
 
    {
70
 
        return mock_prompt_session_manager;
71
 
    }
72
 
 
73
 
    std::shared_ptr<testing::MockPromptSessionManager> mock_prompt_session_manager;
74
 
};
75
 
 
76
 
class ApplicationManagerTests : public ::testing::Test
 
31
class ApplicationManagerTests : public ::testing::QtMirTest
77
32
{
78
33
public:
79
34
    ApplicationManagerTests()
80
 
        : processController{
81
 
            QSharedPointer<ProcessController::OomController> (
82
 
                &oomController,
83
 
                [](ProcessController::OomController*){})
84
 
        }
85
 
        , mirConfig{
86
 
            QSharedPointer<TestMirConfiguration> (new TestMirConfiguration)
87
 
        }
88
 
        , taskController{
89
 
              QSharedPointer<TaskController> (
90
 
                  new TaskController(
91
 
                      nullptr,
92
 
                      QSharedPointer<ApplicationController>(
93
 
                          &appController,
94
 
                          [](ApplicationController*){}),
95
 
                      QSharedPointer<ProcessController>(
96
 
                          &processController,
97
 
                          [](ProcessController*){})
98
 
                  )
99
 
              )
100
 
        }
101
 
        , applicationManager{
102
 
            mirConfig,
103
 
            taskController,
104
 
            QSharedPointer<DesktopFileReader::Factory>(
105
 
                &desktopFileReaderFactory,
106
 
                [](DesktopFileReader::Factory*){}),
107
 
            QSharedPointer<ProcInfo>(&procInfo,[](ProcInfo *){})
108
 
        }
109
 
    {
110
 
    }
111
 
 
112
 
    Application* startApplication(quint64 procId, QString const& appId)
113
 
    {
114
 
        using namespace testing;
115
 
 
116
 
        ON_CALL(appController,appIdHasProcessId(procId, appId)).WillByDefault(Return(true));
117
 
 
118
 
        // Set up Mocks & signal watcher
119
 
        auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId, QFileInfo());
120
 
        ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true));
121
 
        ON_CALL(*mockDesktopFileReader, appId()).WillByDefault(Return(appId));
122
 
 
123
 
        ON_CALL(desktopFileReaderFactory, createInstance(appId, _)).WillByDefault(Return(mockDesktopFileReader));
124
 
 
125
 
        EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(appId, _))
126
 
                .Times(1)
127
 
                .WillOnce(Return(true));
128
 
 
129
 
        auto application = applicationManager.startApplication(appId, ApplicationManager::NoFlag);
130
 
        applicationManager.onProcessStarting(appId);
131
 
 
132
 
        bool authed = false;
133
 
        applicationManager.authorizeSession(procId, authed);
134
 
        EXPECT_EQ(authed, true);
135
 
 
136
 
        auto appSession = std::make_shared<MockSession>(appId.toStdString(), procId);
137
 
 
138
 
        applicationManager.onSessionStarting(appSession);
139
 
        return application;
140
 
    }
141
 
 
142
 
    testing::NiceMock<testing::MockOomController> oomController;
143
 
    testing::NiceMock<testing::MockProcessController> processController;
144
 
    testing::NiceMock<testing::MockApplicationController> appController;
145
 
    testing::NiceMock<testing::MockProcInfo> procInfo;
146
 
    testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;
147
 
    QSharedPointer<TestMirConfiguration> mirConfig;
148
 
    QSharedPointer<TaskController> taskController;
149
 
    ApplicationManager applicationManager;
 
35
    {}
 
36
 
 
37
    inline void onSessionStarting(const std::shared_ptr<mir::scene::Session> &session) {
 
38
        applicationManager.onSessionStarting(session);
 
39
        sessionManager.onSessionStarting(session);
 
40
    }
 
41
    inline void onSessionStopping(const std::shared_ptr<mir::scene::Session> &session) {
 
42
        applicationManager.onSessionStopping(session);
 
43
        sessionManager.onSessionStopping(session);
 
44
    }
150
45
};
151
46
 
152
47
TEST_F(ApplicationManagerTests, SuspendingAndResumingARunningApplicationResultsInOomScoreAdjustment)
170
65
                ApplicationManager::NoFlag,
171
66
                QStringList());
172
67
 
173
 
    application->suspend();
174
 
    application->resume();
 
68
    // FIXME - this is doesn't really excerise the actualt behaviour since suspend/resume should be
 
69
    // controlled by state changes. Requires using suspend timer.
 
70
    QMetaObject::invokeMethod(application, "onSessionSuspended");
 
71
    QMetaObject::invokeMethod(application, "onSessionResumed");
175
72
}
176
73
 
177
74
// Currently disabled as we need to make sure that we have a corresponding mir session, too.
194
91
                    QStringList());
195
92
 
196
93
        std::shared_ptr<mir::scene::Session> mirSession = std::make_shared<MockSession>(appIdFormat.toStdString(), i);
197
 
        applicationManager.onSessionStarting( mirSession );
 
94
        onSessionStarting( mirSession );
198
95
 
199
96
        EXPECT_NE(nullptr, application);
200
97
 
233
130
    std::shared_ptr<mir::scene::Session> mirSession = std::make_shared<MockSession>(dialer_app_id, firstProcId);
234
131
    applicationManager.authorizeSession(firstProcId, authed);
235
132
    EXPECT_EQ(true, authed);
236
 
    applicationManager.onSessionStarting(mirSession);
 
133
    onSessionStarting(mirSession);
237
134
    applicationManager.onSessionCreatedSurface(mirSession.get(),aSurface);
238
135
    Application * app = applicationManager.findApplication(dialer_app_id);
239
136
    EXPECT_NE(nullptr,app);
261
158
 
262
159
    std::shared_ptr<mir::scene::Session> mirSession = std::make_shared<MockSession>(app_id, procId);
263
160
    applicationManager.authorizeSession(procId, authed);
264
 
    applicationManager.onSessionStarting(mirSession);
 
161
    onSessionStarting(mirSession);
265
162
    Application * beforeFailure = applicationManager.findApplication(app_id);
266
163
    applicationManager.onProcessStarting(app_id);
267
164
    applicationManager.onProcessFailed(app_id, true);
288
185
 
289
186
    std::shared_ptr<mir::scene::Session> mirSession = std::make_shared<MockSession>(app_id, procId);
290
187
    applicationManager.authorizeSession(procId, authed);
291
 
    applicationManager.onSessionStarting(mirSession);
 
188
    onSessionStarting(mirSession);
292
189
    Application * beforeFailure = applicationManager.findApplication(app_id);
293
190
    applicationManager.onSessionCreatedSurface(mirSession.get(), aSurface);
294
191
    applicationManager.onProcessStarting(app_id);
415
312
    applicationManager.authorizeSession(first_procId, authed);
416
313
    applicationManager.authorizeSession(second_procId, authed);
417
314
    applicationManager.authorizeSession(third_procId, authed);
418
 
    applicationManager.onSessionStarting(first_session);
419
 
    applicationManager.onSessionStarting(third_session);
420
 
    applicationManager.onSessionStarting(second_session);
 
315
    onSessionStarting(first_session);
 
316
    onSessionStarting(third_session);
 
317
    onSessionStarting(second_session);
421
318
 
422
319
    Application * firstApp = applicationManager.findApplication(first_app_id);
423
320
    Application * secondApp = applicationManager.findApplication(second_app_id);
424
321
    Application * thirdApp = applicationManager.findApplication(third_app_id);
425
322
 
426
 
    EXPECT_EQ(first_session, firstApp->session());
427
 
    EXPECT_EQ(second_session, secondApp->session());
428
 
    EXPECT_EQ(third_session, thirdApp->session());
 
323
    EXPECT_EQ(first_session, firstApp->session()->session());
 
324
    EXPECT_EQ(second_session, secondApp->session()->session());
 
325
    EXPECT_EQ(third_session, thirdApp->session()->session());
429
326
}
430
327
 
431
328
TEST_F(ApplicationManagerTests,two_session_on_one_application)
445
342
    std::shared_ptr<mir::scene::Session> second_session = std::make_shared<MockSession>("oO", a_procId);
446
343
    applicationManager.authorizeSession(a_procId, authed);
447
344
 
448
 
    applicationManager.onSessionStarting(first_session);
449
 
    applicationManager.onSessionStarting(second_session);
 
345
    onSessionStarting(first_session);
 
346
    onSessionStarting(second_session);
450
347
 
451
348
    Application * the_app = applicationManager.findApplication(an_app_id);
452
349
 
453
350
    EXPECT_EQ(true, authed);
454
 
    EXPECT_EQ(second_session, the_app->session());
 
351
    EXPECT_EQ(second_session, the_app->session()->session());
455
352
}
456
353
 
457
354
TEST_F(ApplicationManagerTests,DISABLED_upstart_launching_sidestage_app_on_phone_forced_into_mainstage)
494
391
    std::shared_ptr<mir::scene::Session> second_session = std::make_shared<MockSession>("oO", a_procId);
495
392
    applicationManager.authorizeSession(a_procId, authed);
496
393
 
497
 
    applicationManager.onSessionStarting(first_session);
 
394
    onSessionStarting(first_session);
498
395
    applicationManager.onSessionCreatedSurface(first_session.get(), aSurface);
499
 
    applicationManager.onSessionStarting(second_session);
 
396
    onSessionStarting(second_session);
500
397
 
501
398
    Application * the_app = applicationManager.findApplication(an_app_id);
502
399
 
503
400
    EXPECT_EQ(true, authed);
504
401
    EXPECT_EQ(Application::Running, the_app->state());
505
 
    EXPECT_EQ(first_session, the_app->session());
 
402
    EXPECT_EQ(first_session, the_app->session()->session());
506
403
}
507
404
 
508
405
TEST_F(ApplicationManagerTests,suspended_suspends_focused_app_and_marks_it_unfocused_in_the_model)
523
420
    std::shared_ptr<mir::scene::Session> second_session = std::make_shared<MockSession>("oO", a_procId);
524
421
    applicationManager.authorizeSession(a_procId, authed);
525
422
 
526
 
    applicationManager.onSessionStarting(first_session);
 
423
    onSessionStarting(first_session);
527
424
    applicationManager.onSessionCreatedSurface(first_session.get(), aSurface);
528
 
    applicationManager.onSessionStarting(second_session);
 
425
    onSessionStarting(second_session);
529
426
 
530
427
    Application * the_app = applicationManager.findApplication(an_app_id);
531
428
    applicationManager.focusApplication(an_app_id);
576
473
    applicationManager.authorizeSession(first_procId, authed);
577
474
    applicationManager.authorizeSession(second_procId, authed);
578
475
    applicationManager.authorizeSession(third_procId, authed);
579
 
    applicationManager.onSessionStarting(first_session);
580
 
    applicationManager.onSessionStarting(third_session);
581
 
    applicationManager.onSessionStarting(second_session);
 
476
    onSessionStarting(first_session);
 
477
    onSessionStarting(third_session);
 
478
    onSessionStarting(second_session);
582
479
 
583
480
    QSignalSpy spy(&applicationManager, SIGNAL(focusRequested(const QString &)));
584
481
 
895
792
    // Authorize session and emit Mir sessionStarting event
896
793
    bool authed = true;
897
794
    applicationManager.authorizeSession(procId, authed);
898
 
    applicationManager.onSessionStarting(session);
 
795
    onSessionStarting(session);
899
796
 
900
797
    EXPECT_EQ(countSpy.count(), 0);
901
798
    EXPECT_EQ(applicationManager.count(), 1);
903
800
 
904
801
    // Check application state and session are correctly set
905
802
    Application *theApp = applicationManager.findApplication(appId);
906
 
    EXPECT_EQ(theApp->session(), session);
 
803
    EXPECT_EQ(theApp->session()->session(), session);
907
804
    EXPECT_EQ(theApp->focused(), false);
908
805
}
909
806
 
935
832
 
936
833
    bool authed = true;
937
834
    applicationManager.authorizeSession(procId, authed);
938
 
    applicationManager.onSessionStarting(session);
 
835
    onSessionStarting(session);
939
836
 
940
837
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
941
838
 
971
868
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
972
869
    bool authed = true;
973
870
    applicationManager.authorizeSession(procId, authed);
974
 
    applicationManager.onSessionStarting(session);
 
871
    onSessionStarting(session);
975
872
 
976
873
    QSignalSpy countSpy(&applicationManager, SIGNAL(countChanged()));
977
874
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1010
907
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1011
908
    bool authed = true;
1012
909
    applicationManager.authorizeSession(procId, authed);
1013
 
    applicationManager.onSessionStarting(session);
 
910
    onSessionStarting(session);
1014
911
 
1015
912
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1016
913
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1054
951
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1055
952
    bool authed = true;
1056
953
    applicationManager.authorizeSession(procId, authed);
1057
 
    applicationManager.onSessionStarting(session);
 
954
    onSessionStarting(session);
1058
955
 
1059
956
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1060
957
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1099
996
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1100
997
    bool authed = true;
1101
998
    applicationManager.authorizeSession(procId, authed);
1102
 
    applicationManager.onSessionStarting(session);
 
999
    onSessionStarting(session);
1103
1000
 
1104
1001
    QSignalSpy countSpy(&applicationManager, SIGNAL(countChanged()));
1105
1002
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1138
1035
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1139
1036
    bool authed = true;
1140
1037
    applicationManager.authorizeSession(procId, authed);
1141
 
    applicationManager.onSessionStarting(session);
 
1038
    onSessionStarting(session);
1142
1039
 
1143
1040
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1144
1041
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1183
1080
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1184
1081
    bool authed = true;
1185
1082
    applicationManager.authorizeSession(procId, authed);
1186
 
    applicationManager.onSessionStarting(session);
 
1083
    onSessionStarting(session);
1187
1084
 
1188
1085
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1189
1086
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1231
1128
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1232
1129
    bool authed = true;
1233
1130
    applicationManager.authorizeSession(procId, authed);
1234
 
    applicationManager.onSessionStarting(session);
 
1131
    onSessionStarting(session);
1235
1132
 
1236
1133
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1237
1134
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1280
1177
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1281
1178
    bool authed = true;
1282
1179
    applicationManager.authorizeSession(procId, authed);
1283
 
    applicationManager.onSessionStarting(session);
 
1180
    onSessionStarting(session);
1284
1181
 
1285
1182
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1286
1183
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1293
1190
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1294
1191
 
1295
1192
    // Mir reports disconnection
1296
 
    applicationManager.onSessionStopping(session);
 
1193
    onSessionStopping(session);
1297
1194
 
1298
1195
    // Upstart notifies of crashing / OOM-killed app
1299
1196
    applicationManager.onProcessFailed(appId, false);
1338
1235
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1339
1236
    bool authed = true;
1340
1237
    applicationManager.authorizeSession(procId, authed);
1341
 
    applicationManager.onSessionStarting(session);
 
1238
    onSessionStarting(session);
1342
1239
 
1343
1240
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1344
1241
    applicationManager.onSessionCreatedSurface(session.get(), surface);
1351
1248
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1352
1249
 
1353
1250
    // Mir reports disconnection
1354
 
    applicationManager.onSessionStopping(session);
 
1251
    onSessionStopping(session);
1355
1252
 
1356
1253
    // Upstart notifies of crashing app
1357
1254
    applicationManager.onProcessFailed(appId, true);
1391
1288
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1392
1289
    bool authed = true;
1393
1290
    applicationManager.authorizeSession(procId, authed);
1394
 
    applicationManager.onSessionStarting(session);
 
1291
    onSessionStarting(session);
1395
1292
 
1396
1293
    QSignalSpy countSpy(&applicationManager, SIGNAL(countChanged()));
1397
1294
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1398
1295
 
1399
1296
    // Mir notifies of stopping app
1400
 
    applicationManager.onSessionStopping(session);
 
1297
    onSessionStopping(session);
1401
1298
 
1402
1299
    EXPECT_EQ(countSpy.count(), 2); //FIXME(greyback)
1403
1300
    EXPECT_EQ(applicationManager.count(), 0);
1430
1327
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1431
1328
    bool authed = true;
1432
1329
    applicationManager.authorizeSession(procId, authed);
1433
 
    applicationManager.onSessionStarting(session);
 
1330
    onSessionStarting(session);
1434
1331
 
1435
1332
    // Associate a surface so AppMan considers app Running, check focused
1436
1333
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1442
1339
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1443
1340
 
1444
1341
    // Mir notifies of stopping app
1445
 
    applicationManager.onSessionStopping(session);
 
1342
    onSessionStopping(session);
1446
1343
 
1447
1344
    EXPECT_EQ(countSpy.count(), 2); //FIXME(greyback)
1448
1345
    EXPECT_EQ(applicationManager.count(), 0);
1480
1377
    applicationManager.authorizeSession(procId, authed);
1481
1378
    EXPECT_EQ(authed, true);
1482
1379
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1483
 
    applicationManager.onSessionStarting(session);
 
1380
    onSessionStarting(session);
1484
1381
 
1485
1382
    // Associate a surface so AppMan considers app Running, check focused
1486
1383
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1492
1389
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1493
1390
 
1494
1391
    // Mir notifies of stopping app
1495
 
    applicationManager.onSessionStopping(session);
 
1392
    onSessionStopping(session);
1496
1393
 
1497
1394
    EXPECT_EQ(countSpy.count(), 2); //FIXME(greyback)
1498
1395
    EXPECT_EQ(applicationManager.count(), 0);
1528
1425
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1529
1426
    bool authed = true;
1530
1427
    applicationManager.authorizeSession(procId, authed);
1531
 
    applicationManager.onSessionStarting(session);
 
1428
    onSessionStarting(session);
1532
1429
 
1533
1430
    // Associate a surface so AppMan considers app Running, check in background
1534
1431
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1541
1438
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1542
1439
 
1543
1440
    // Mir notifies of stopping app
1544
 
    applicationManager.onSessionStopping(session);
 
1441
    onSessionStopping(session);
1545
1442
 
1546
1443
    EXPECT_EQ(countSpy.count(), 0);
1547
1444
    EXPECT_EQ(applicationManager.count(), 1);
1582
1479
    applicationManager.authorizeSession(procId, authed);
1583
1480
    EXPECT_EQ(authed, true);
1584
1481
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1585
 
    applicationManager.onSessionStarting(session);
 
1482
    onSessionStarting(session);
1586
1483
 
1587
1484
    // Associate a surface so AppMan considers app Running, check in background
1588
1485
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1595
1492
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1596
1493
 
1597
1494
    // Mir notifies of stopping app
1598
 
    applicationManager.onSessionStopping(session);
 
1495
    onSessionStopping(session);
1599
1496
 
1600
1497
    EXPECT_EQ(countSpy.count(), 2); //FIXME(greyback)
1601
1498
    EXPECT_EQ(applicationManager.count(), 0);
1630
1527
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1631
1528
    bool authed = true;
1632
1529
    applicationManager.authorizeSession(procId, authed);
1633
 
    applicationManager.onSessionStarting(session);
 
1530
    onSessionStarting(session);
1634
1531
 
1635
1532
    applicationManager.stopApplication(appId);
1636
1533
 
1669
1566
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1670
1567
    bool authed = true;
1671
1568
    applicationManager.authorizeSession(procId, authed);
1672
 
    applicationManager.onSessionStarting(session);
 
1569
    onSessionStarting(session);
1673
1570
 
1674
1571
    applicationManager.stopApplication(appId);
1675
1572
 
1677
1574
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1678
1575
 
1679
1576
    // Mir notifies of stopping app/Session
1680
 
    applicationManager.onSessionStopping(session);
 
1577
    onSessionStopping(session);
1681
1578
 
1682
1579
    EXPECT_EQ(countSpy.count(), 0);
1683
1580
    EXPECT_EQ(removedSpy.count(), 0);
1708
1605
    std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("", procId);
1709
1606
    bool authed = true;
1710
1607
    applicationManager.authorizeSession(procId, authed);
1711
 
    applicationManager.onSessionStarting(session);
 
1608
    onSessionStarting(session);
1712
1609
 
1713
1610
    applicationManager.onProcessStopped(appId);
1714
1611
 
1716
1613
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1717
1614
 
1718
1615
    // Mir notifies of stopping app
1719
 
    applicationManager.onSessionStopping(session);
 
1616
    onSessionStopping(session);
1720
1617
 
1721
1618
    EXPECT_EQ(countSpy.count(), 0);
1722
1619
    EXPECT_EQ(removedSpy.count(), 0);
1760
1657
 
1761
1658
    bool authed = false;
1762
1659
    applicationManager.authorizeSession(procId1, authed);
1763
 
    applicationManager.onSessionStarting(session1);
 
1660
    onSessionStarting(session1);
1764
1661
    EXPECT_EQ(authed, true);
1765
1662
    applicationManager.authorizeSession(procId2, authed);
1766
 
    applicationManager.onSessionStarting(session2);
 
1663
    onSessionStarting(session2);
1767
1664
    EXPECT_EQ(authed, true);
1768
1665
    std::shared_ptr<mir::scene::Surface> surface(nullptr);
1769
1666
    applicationManager.onSessionCreatedSurface(session2.get(), surface);
1772
1669
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1773
1670
 
1774
1671
    // Mir notifies of stopping app/Session
1775
 
    applicationManager.onSessionStopping(session2);
1776
 
    applicationManager.onSessionStopping(session1);
 
1672
    onSessionStopping(session2);
 
1673
    onSessionStopping(session1);
1777
1674
 
1778
1675
    EXPECT_EQ(countSpy.count(), 2); //FIXME(greyback)
1779
1676
    EXPECT_EQ(applicationManager.count(), 0);
1819
1716
 
1820
1717
    bool authed = false;
1821
1718
    applicationManager.authorizeSession(procId1, authed);
1822
 
    applicationManager.onSessionStarting(session1);
 
1719
    onSessionStarting(session1);
1823
1720
    EXPECT_EQ(authed, true);
1824
1721
    applicationManager.authorizeSession(procId2, authed);
1825
 
    applicationManager.onSessionStarting(session2);
 
1722
    onSessionStarting(session2);
1826
1723
    EXPECT_EQ(authed, true);
1827
1724
 
1828
1725
    // both sessions create surfaces, then unfocus everything.
1838
1735
    QSignalSpy removedSpy(&applicationManager, SIGNAL(applicationRemoved(const QString &)));
1839
1736
 
1840
1737
    // Mir notifies of stopping app/Session
1841
 
    applicationManager.onSessionStopping(session2);
1842
 
    applicationManager.onSessionStopping(session1);
 
1738
    onSessionStopping(session2);
 
1739
    onSessionStopping(session1);
1843
1740
 
1844
1741
    EXPECT_EQ(countSpy.count(), 0);
1845
1742
    EXPECT_EQ(removedSpy.count(), 0);
1858
1755
    bool done = false;
1859
1756
 
1860
1757
    auto application = startApplication(procId1, "webapp");
1861
 
    auto session = std::dynamic_pointer_cast<MockSession>(application->session());
 
1758
    auto session = std::dynamic_pointer_cast<MockSession>(application->session()->session());
1862
1759
    ON_CALL(*session, take_snapshot(_)).WillByDefault(Invoke(
1863
1760
        [&](mir::scene::SnapshotCallback const& callback)
1864
1761
        {
1910
1807
    bool done = false;
1911
1808
 
1912
1809
    auto application = startApplication(procId1, "webapp");
1913
 
    auto session = std::dynamic_pointer_cast<MockSession>(application->session());
 
1810
    auto session = std::dynamic_pointer_cast<MockSession>(application->session()->session());
1914
1811
    ON_CALL(*session, take_snapshot(_)).WillByDefault(Invoke(
1915
1812
        [&](mir::scene::SnapshotCallback const& callback)
1916
1813
        {
1945
1842
        cv.wait(lk, [&] { return done; } );
1946
1843
    }
1947
1844
}
1948
 
 
1949
 
TEST_F(ApplicationManagerTests, applicationTracksPromptSession)
1950
 
{
1951
 
    using namespace testing;
1952
 
    quint64 procId1 = 5551;
1953
 
 
1954
 
    auto application = startApplication(procId1, "webapp");
1955
 
    auto promptSession = std::make_shared<MockPromptSession>();
1956
 
 
1957
 
    ON_CALL(*mirConfig->the_mock_prompt_session_manager(), application_for(_)).WillByDefault(Return(application->session()));
1958
 
 
1959
 
    applicationManager.onPromptSessionStarting(promptSession);
1960
 
 
1961
 
    EXPECT_EQ(application->activePromptSession(), promptSession);
1962
 
 
1963
 
    applicationManager.onPromptSessionStopping(promptSession);
1964
 
 
1965
 
    EXPECT_EQ(application->activePromptSession(), nullptr);
1966
 
}