Merge lp:~dandrader/qtmir/frozenApps-lp1295623 into lp:qtmir

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Michael Zanetti
Approved revision: 253
Merged at revision: 249
Proposed branch: lp:~dandrader/qtmir/frozenApps-lp1295623
Merge into: lp:qtmir
Diff against target: 1687 lines (+667/-239)
27 files modified
src/modules/Unity/Application/Application.pro (+1/-0)
src/modules/Unity/Application/application.cpp (+3/-3)
src/modules/Unity/Application/mirsurfaceitem.cpp (+135/-30)
src/modules/Unity/Application/mirsurfaceitem.h (+38/-7)
src/modules/Unity/Application/mirsurfacemanager.cpp (+6/-6)
src/modules/Unity/Application/plugin.cpp (+1/-0)
src/modules/Unity/Application/session.cpp (+21/-19)
src/modules/Unity/Application/session.h (+35/-63)
src/modules/Unity/Application/session_interface.h (+106/-0)
src/modules/Unity/Application/sessionmanager.cpp (+8/-8)
src/modules/Unity/Application/sessionmanager.h (+4/-4)
src/modules/Unity/Application/sessionmodel.h (+2/-2)
tests/modules/ApplicationManager/application_manager_test.cpp (+3/-2)
tests/modules/MirSurfaceItem/MirSurfaceItem.pro (+13/-0)
tests/modules/MirSurfaceItem/mirsurfaceitem_test.cpp (+113/-0)
tests/modules/SessionManager/session_manager_test.cpp (+10/-9)
tests/modules/SessionManager/session_test.cpp (+5/-6)
tests/modules/common/common.pri (+1/-0)
tests/modules/common/mock_focus_controller.h (+9/-6)
tests/modules/common/mock_mir_session.h (+14/-13)
tests/modules/common/mock_prompt_session.h (+7/-4)
tests/modules/common/mock_prompt_session_manager.h (+21/-18)
tests/modules/common/mock_renderable.h (+9/-6)
tests/modules/common/mock_session.h (+65/-0)
tests/modules/common/mock_surface.h (+24/-23)
tests/modules/common/qtmir_test.h (+12/-9)
tests/modules/modules.pro (+1/-1)
To merge this branch: bzr merge lp:~dandrader/qtmir/frozenApps-lp1295623
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+234393@code.launchpad.net

Commit message

MirSurfaceItem: Ensure all touch sequences sent to Mir surface are properly ended.

In order to have a testable MirSurfaceItem I had to mock qtmir::Session.
To mock qtmir::Session I had to define a qtmir::SessionInterface. That caused many s/Session/SessionInterfaces throughout the code base.
When creating a testing::MockSession for qtmir::Session it clashed with the existing testing::MockSession for mir::scene::Surface. Thus I had to refactor the namespacing of all mocks.

So most of the diff is just about refactoring code to enable a MirSurfaceItem unit test.

Description of the change

* Are there any related MPs required for this MP to build/function as expected? Please list.
No

* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
Not applicable

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
Michael Zanetti (mzanetti) wrote :

Confirming this fixes the issue. Code looks ok despite the fact that we're drifting even further from unity-api. However, there's plans to restructure this. So ok with me.

 * Did you perform an exploratory manual test run of the code change and any related functionality?

yes

 * Did CI run pass? If not, please explain why.

yes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/modules/Unity/Application/Application.pro'
--- src/modules/Unity/Application/Application.pro 2014-09-07 19:42:33 +0000
+++ src/modules/Unity/Application/Application.pro 2014-09-11 21:25:08 +0000
@@ -63,6 +63,7 @@
63 processcontroller.h \63 processcontroller.h \
64 proc_info.h \64 proc_info.h \
65 session.h \65 session.h \
66 session_interface.h \
66 sessionmodel.h \67 sessionmodel.h \
67 upstart/applicationcontroller.h68 upstart/applicationcontroller.h
6869
6970
=== modified file 'src/modules/Unity/Application/application.cpp'
--- src/modules/Unity/Application/application.cpp 2014-09-07 19:42:14 +0000
+++ src/modules/Unity/Application/application.cpp 2014-09-11 21:25:08 +0000
@@ -183,9 +183,9 @@
183 m_session->setApplication(this);183 m_session->setApplication(this);
184 m_session->setState(state());184 m_session->setState(state());
185185
186 connect(m_session, &Session::suspended, this, &Application::onSessionSuspended);186 connect(m_session, &SessionInterface::suspended, this, &Application::onSessionSuspended);
187 connect(m_session, &Session::resumed, this, &Application::onSessionResumed);187 connect(m_session, &SessionInterface::resumed, this, &Application::onSessionResumed);
188 connect(m_session, &Session::fullscreenChanged, this, &Application::fullscreenChanged);188 connect(m_session, &SessionInterface::fullscreenChanged, this, &Application::fullscreenChanged);
189189
190 if (oldFullscreen != fullscreen())190 if (oldFullscreen != fullscreen())
191 Q_EMIT fullscreenChanged(fullscreen());191 Q_EMIT fullscreenChanged(fullscreen());
192192
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.cpp'
--- src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-07 19:42:14 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-11 21:25:08 +0000
@@ -87,7 +87,10 @@
87 return true;87 return true;
88}88}
8989
90bool fillInMirEvent(MirEvent &mirEvent, QTouchEvent *qtEvent)90bool fillInMirEvent(MirEvent &mirEvent,
91 const QList<QTouchEvent::TouchPoint> &qtTouchPoints,
92 Qt::TouchPointStates qtTouchPointStates,
93 ulong qtTimestamp)
91{94{
92 mirEvent.type = mir_event_type_motion;95 mirEvent.type = mir_event_type_motion;
9396
@@ -99,14 +102,14 @@
99 // NB: it's assumed that touch points are pressed and released102 // NB: it's assumed that touch points are pressed and released
100 // one at a time.103 // one at a time.
101104
102 if (qtEvent->touchPointStates().testFlag(Qt::TouchPointPressed)) {105 if (qtTouchPointStates.testFlag(Qt::TouchPointPressed)) {
103 if (qtEvent->touchPoints().count() > 1) {106 if (qtTouchPoints.count() > 1) {
104 mirEvent.motion.action = mir_motion_action_pointer_down;107 mirEvent.motion.action = mir_motion_action_pointer_down;
105 } else {108 } else {
106 mirEvent.motion.action = mir_motion_action_down;109 mirEvent.motion.action = mir_motion_action_down;
107 }110 }
108 } else if (qtEvent->touchPointStates().testFlag(Qt::TouchPointReleased)) {111 } else if (qtTouchPointStates.testFlag(Qt::TouchPointReleased)) {
109 if (qtEvent->touchPoints().count() > 1) {112 if (qtTouchPoints.count() > 1) {
110 mirEvent.motion.action = mir_motion_action_pointer_up;113 mirEvent.motion.action = mir_motion_action_pointer_up;
111 } else {114 } else {
112 mirEvent.motion.action = mir_motion_action_up;115 mirEvent.motion.action = mir_motion_action_up;
@@ -138,18 +141,17 @@
138141
139 // Note: QtEventFeeder scales the event time down, scale it back up - precision is142 // Note: QtEventFeeder scales the event time down, scale it back up - precision is
140 // lost but the time difference should still be accurate to milliseconds143 // lost but the time difference should still be accurate to milliseconds
141 mirEvent.motion.event_time = static_cast<nsecs_t>(qtEvent->timestamp()) * 1000000;144 mirEvent.motion.event_time = static_cast<nsecs_t>(qtTimestamp) * 1000000;
142145
143 mirEvent.motion.pointer_count = qtEvent->touchPoints().count();146 mirEvent.motion.pointer_count = qtTouchPoints.count();
144147
145 auto touchPoints = qtEvent->touchPoints();148 for (int i = 0; i < qtTouchPoints.count(); ++i) {
146 for (int i = 0; i < touchPoints.count(); ++i) {149 auto touchPoint = qtTouchPoints.at(i);
147 auto touchPoint = touchPoints.at(i);
148 auto &pointer = mirEvent.motion.pointer_coordinates[i];150 auto &pointer = mirEvent.motion.pointer_coordinates[i];
149151
150 // FIXME: https://bugs.launchpad.net/mir/+bug/1311699152 // FIXME: https://bugs.launchpad.net/mir/+bug/1311699
151 // When multiple touch points are transmitted with a MirEvent153 // When multiple touch points are transmitted with a MirEvent
152 // and one of them (only one is allowed) indicates a pressed154 // and one of them (only one is allowed) indicates a presse
153 // state change the index is encoded in the second byte of the155 // state change the index is encoded in the second byte of the
154 // action value.156 // action value.
155 const int mir_motion_event_pointer_index_shift = 8;157 const int mir_motion_event_pointer_index_shift = 8;
@@ -234,7 +236,7 @@
234UbuntuKeyboardInfo *MirSurfaceItem::m_ubuntuKeyboardInfo = nullptr;236UbuntuKeyboardInfo *MirSurfaceItem::m_ubuntuKeyboardInfo = nullptr;
235237
236MirSurfaceItem::MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,238MirSurfaceItem::MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,
237 QPointer<Session> session,239 SessionInterface* session,
238 QQuickItem *parent)240 QQuickItem *parent)
239 : QQuickItem(parent)241 : QQuickItem(parent)
240 , m_surface(surface)242 , m_surface(surface)
@@ -242,6 +244,7 @@
242 , m_firstFrameDrawn(false)244 , m_firstFrameDrawn(false)
243 , m_live(true)245 , m_live(true)
244 , m_textureProvider(nullptr)246 , m_textureProvider(nullptr)
247 , m_lastTouchEvent(nullptr)
245{248{
246 qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::MirSurfaceItem";249 qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::MirSurfaceItem";
247250
@@ -316,6 +319,8 @@
316 m_surface->remove_observer(m_surfaceObserver);319 m_surface->remove_observer(m_surfaceObserver);
317 if (m_textureProvider)320 if (m_textureProvider)
318 m_textureProvider->deleteLater();321 m_textureProvider->deleteLater();
322
323 delete m_lastTouchEvent;
319}324}
320325
321// For QML to destroy this surface326// For QML to destroy this surface
@@ -329,7 +334,7 @@
329 deleteLater();334 deleteLater();
330}335}
331336
332Session* MirSurfaceItem::session() const337SessionInterface* MirSurfaceItem::session() const
333{338{
334 return m_session.data();339 return m_session.data();
335}340}
@@ -478,31 +483,115 @@
478 }483 }
479}484}
480485
486QString MirSurfaceItem::appId() const
487{
488 QString appId;
489 if (session() && session()->application()) {
490 appId = session()->application()->appId();
491 } else {
492 appId.append("-");
493 }
494 return appId;
495}
496
497void MirSurfaceItem::endCurrentTouchSequence(ulong timestamp)
498{
499 MirEvent mirEvent;
500
501 Q_ASSERT(m_lastTouchEvent);
502 Q_ASSERT(m_lastTouchEvent->type != QEvent::TouchEnd);
503 Q_ASSERT(m_lastTouchEvent->touchPoints.count() > 0);
504
505 TouchEvent touchEvent = *m_lastTouchEvent;
506 touchEvent.timestamp = timestamp;
507
508 // Remove all already released touch points
509 int i = 0;
510 while (i < touchEvent.touchPoints.count()) {
511 if (touchEvent.touchPoints[i].state() == Qt::TouchPointReleased) {
512 touchEvent.touchPoints.removeAt(i);
513 } else {
514 ++i;
515 }
516 }
517
518 // And release the others one by one as Mir expects one press/release per event
519 while (touchEvent.touchPoints.count() > 0) {
520 touchEvent.touchPoints[0].setState(Qt::TouchPointReleased);
521
522 touchEvent.updateTouchPointStatesAndType();
523
524 if (fillInMirEvent(mirEvent, touchEvent.touchPoints,
525 touchEvent.touchPointStates, touchEvent.timestamp)) {
526 m_surface->consume(mirEvent);
527 }
528 *m_lastTouchEvent = touchEvent;
529
530 touchEvent.touchPoints.removeAt(0);
531 }
532}
533
534void MirSurfaceItem::validateAndDeliverTouchEvent(int eventType,
535 ulong timestamp,
536 const QList<QTouchEvent::TouchPoint> &touchPoints,
537 Qt::TouchPointStates touchPointStates)
538{
539 MirEvent mirEvent;
540
541 if (eventType == QEvent::TouchBegin && m_lastTouchEvent && m_lastTouchEvent->type != QEvent::TouchEnd) {
542 qCWarning(QTMIR_SURFACES) << qPrintable(QString("MirSurfaceItem(%1) - Got a QEvent::TouchBegin while "
543 "there's still an active/unfinished touch sequence.").arg(appId()));
544 // Qt forgot to end the last touch sequence. Let's do it ourselves.
545 endCurrentTouchSequence(timestamp);
546 }
547
548 if (fillInMirEvent(mirEvent, touchPoints, touchPointStates, timestamp)) {
549 m_surface->consume(mirEvent);
550 }
551
552 if (!m_lastTouchEvent) {
553 m_lastTouchEvent = new TouchEvent;
554 }
555 m_lastTouchEvent->type = eventType;
556 m_lastTouchEvent->timestamp = timestamp;
557 m_lastTouchEvent->touchPoints = touchPoints;
558 m_lastTouchEvent->touchPointStates = touchPointStates;
559}
560
481void MirSurfaceItem::touchEvent(QTouchEvent *event)561void MirSurfaceItem::touchEvent(QTouchEvent *event)
482{562{
483 MirEvent mirEvent;563 bool accepted = processTouchEvent(event->type(),
484 if (type() == InputMethod && event->type() == QEvent::TouchBegin) {564 event->timestamp(),
565 event->touchPoints(),
566 event->touchPointStates());
567 event->setAccepted(accepted);
568}
569
570bool MirSurfaceItem::processTouchEvent(
571 int eventType,
572 ulong timestamp,
573 const QList<QTouchEvent::TouchPoint> &touchPoints,
574 Qt::TouchPointStates touchPointStates)
575{
576 bool accepted = true;
577 if (type() == InputMethod && eventType == QEvent::TouchBegin) {
485 // FIXME: Hack to get the VKB use case working while we don't have the proper solution in place.578 // FIXME: Hack to get the VKB use case working while we don't have the proper solution in place.
486 if (hasTouchInsideUbuntuKeyboard(event)) {579 if (hasTouchInsideUbuntuKeyboard(touchPoints)) {
487 if (fillInMirEvent(mirEvent, event)) {580 validateAndDeliverTouchEvent(eventType, timestamp, touchPoints, touchPointStates);
488 m_surface->consume(mirEvent);
489 }
490 } else {581 } else {
491 event->ignore();582 accepted = false;
492 }583 }
493584
494 } else {585 } else {
495 // NB: If we are getting QEvent::TouchUpdate or QEvent::TouchEnd it's because we've586 // NB: If we are getting QEvent::TouchUpdate or QEvent::TouchEnd it's because we've
496 // previously accepted the corresponding QEvent::TouchBegin587 // previously accepted the corresponding QEvent::TouchBegin
497 if (fillInMirEvent(mirEvent, event)) {588 validateAndDeliverTouchEvent(eventType, timestamp, touchPoints, touchPointStates);
498 m_surface->consume(mirEvent);
499 }
500 }589 }
590 return accepted;
501}591}
502592
503bool MirSurfaceItem::hasTouchInsideUbuntuKeyboard(QTouchEvent *event)593bool MirSurfaceItem::hasTouchInsideUbuntuKeyboard(const QList<QTouchEvent::TouchPoint> &touchPoints)
504{594{
505 const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
506 for (int i = 0; i < touchPoints.count(); ++i) {595 for (int i = 0; i < touchPoints.count(); ++i) {
507 QPoint pos = touchPoints.at(i).pos().toPoint();596 QPoint pos = touchPoints.at(i).pos().toPoint();
508 if (pos.x() >= m_ubuntuKeyboardInfo->x()597 if (pos.x() >= m_ubuntuKeyboardInfo->x()
@@ -639,15 +728,15 @@
639 m_frameDropperTimer.start();728 m_frameDropperTimer.start();
640}729}
641730
642void MirSurfaceItem::setSession(Session *session)731void MirSurfaceItem::setSession(SessionInterface *session)
643{732{
644 m_session = session;733 m_session = session;
645}734}
646735
647void MirSurfaceItem::onSessionStateChanged(Session::State state)736void MirSurfaceItem::onSessionStateChanged(SessionInterface::State state)
648{737{
649 switch (state) {738 switch (state) {
650 case Session::State::Running:739 case SessionInterface::State::Running:
651 syncSurfaceSizeWithItemSize();740 syncSurfaceSizeWithItemSize();
652 break;741 break;
653 default:742 default:
@@ -676,6 +765,22 @@
676 || !m_session;765 || !m_session;
677}766}
678767
768void MirSurfaceItem::TouchEvent::updateTouchPointStatesAndType()
769{
770 touchPointStates = 0;
771 for (int i = 0; i < touchPoints.count(); ++i) {
772 touchPointStates |= touchPoints.at(i).state();
773 }
774
775 if (touchPointStates == Qt::TouchPointReleased) {
776 type = QEvent::TouchEnd;
777 } else if (touchPointStates == Qt::TouchPointPressed) {
778 type = QEvent::TouchBegin;
779 } else {
780 type = QEvent::TouchUpdate;
781 }
782}
783
679} // namespace qtmir784} // namespace qtmir
680785
681#include "mirsurfaceitem.moc"786#include "mirsurfaceitem.moc"
682787
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.h'
--- src/modules/Unity/Application/mirsurfaceitem.h 2014-08-29 14:58:07 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.h 2014-09-11 21:25:08 +0000
@@ -32,7 +32,7 @@
32#include <mir/scene/surface_observer.h>32#include <mir/scene/surface_observer.h>
33#include <mir_toolkit/common.h>33#include <mir_toolkit/common.h>
3434
35#include "session.h"35#include "session_interface.h"
36#include "ubuntukeyboardinfo.h"36#include "ubuntukeyboardinfo.h"
3737
38namespace qtmir {38namespace qtmir {
@@ -78,7 +78,7 @@
7878
79public:79public:
80 explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,80 explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,
81 QPointer<Session> session,81 SessionInterface* session,
82 QQuickItem *parent = 0);82 QQuickItem *parent = 0);
83 ~MirSurfaceItem();83 ~MirSurfaceItem();
8484
@@ -107,7 +107,7 @@
107 State state() const;107 State state() const;
108 QString name() const;108 QString name() const;
109 bool live() const;109 bool live() const;
110 Session *session() const;110 SessionInterface *session() const;
111111
112 Q_INVOKABLE void release();112 Q_INVOKABLE void release();
113113
@@ -120,7 +120,13 @@
120120
121 bool isFirstFrameDrawn() const { return m_firstFrameDrawn; }121 bool isFirstFrameDrawn() const { return m_firstFrameDrawn; }
122122
123 void setSession(Session *app);123 void setSession(SessionInterface *app);
124
125 // to allow easy touch event injection from tests
126 bool processTouchEvent(int eventType,
127 ulong timestamp,
128 const QList<QTouchEvent::TouchPoint> &touchPoints,
129 Qt::TouchPointStates touchPointStates);
124130
125Q_SIGNALS:131Q_SIGNALS:
126 void typeChanged();132 void typeChanged();
@@ -130,7 +136,7 @@
130 void firstFrameDrawn(MirSurfaceItem *item);136 void firstFrameDrawn(MirSurfaceItem *item);
131137
132protected Q_SLOTS:138protected Q_SLOTS:
133 void onSessionStateChanged(Session::State state);139 void onSessionStateChanged(SessionInterface::State state);
134140
135protected:141protected:
136 void mousePressEvent(QMouseEvent *event) override;142 void mousePressEvent(QMouseEvent *event) override;
@@ -167,15 +173,22 @@
167 void setAttribute(const MirSurfaceAttrib, const int);173 void setAttribute(const MirSurfaceAttrib, const int);
168 void setSurfaceValid(const bool);174 void setSurfaceValid(const bool);
169175
170 bool hasTouchInsideUbuntuKeyboard(QTouchEvent *event);176 bool hasTouchInsideUbuntuKeyboard(const QList<QTouchEvent::TouchPoint> &touchPoints);
171 void syncSurfaceSizeWithItemSize();177 void syncSurfaceSizeWithItemSize();
172178
173 bool clientIsRunning() const;179 bool clientIsRunning() const;
174180
181 QString appId() const;
182 void endCurrentTouchSequence(ulong timestamp);
183 void validateAndDeliverTouchEvent(int eventType,
184 ulong timestamp,
185 const QList<QTouchEvent::TouchPoint> &touchPoints,
186 Qt::TouchPointStates touchPointStates);
187
175 QMutex m_mutex;188 QMutex m_mutex;
176189
177 std::shared_ptr<mir::scene::Surface> m_surface;190 std::shared_ptr<mir::scene::Surface> m_surface;
178 QPointer<Session> m_session;191 QPointer<SessionInterface> m_session;
179 bool m_firstFrameDrawn;192 bool m_firstFrameDrawn;
180 bool m_live;193 bool m_live;
181194
@@ -189,6 +202,24 @@
189202
190 QTimer m_updateMirSurfaceSizeTimer;203 QTimer m_updateMirSurfaceSizeTimer;
191204
205 class TouchEvent {
206 public:
207 TouchEvent &operator= (const QTouchEvent &qtEvent) {
208 type = qtEvent.type();
209 timestamp = qtEvent.timestamp();
210 touchPoints = qtEvent.touchPoints();
211 touchPointStates = qtEvent.touchPointStates();
212 return *this;
213 }
214
215 void updateTouchPointStatesAndType();
216
217 int type;
218 ulong timestamp;
219 QList<QTouchEvent::TouchPoint> touchPoints;
220 Qt::TouchPointStates touchPointStates;
221 } *m_lastTouchEvent;
222
192 friend class MirSurfaceManager;223 friend class MirSurfaceManager;
193};224};
194225
195226
=== modified file 'src/modules/Unity/Application/mirsurfacemanager.cpp'
--- src/modules/Unity/Application/mirsurfacemanager.cpp 2014-09-07 19:42:33 +0000
+++ src/modules/Unity/Application/mirsurfacemanager.cpp 2014-09-11 21:25:08 +0000
@@ -99,21 +99,21 @@
99 m_mirSurfaceToItemHash.clear();99 m_mirSurfaceToItemHash.clear();
100}100}
101101
102void MirSurfaceManager::onSessionCreatedSurface(const mir::scene::Session *session,102void MirSurfaceManager::onSessionCreatedSurface(const mir::scene::Session *mirSession,
103 const std::shared_ptr<mir::scene::Surface> &surface)103 const std::shared_ptr<mir::scene::Surface> &surface)
104{104{
105 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionCreatedSurface - session=" << session105 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionCreatedSurface - mirSession=" << mirSession
106 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str();106 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str();
107107
108 Session* sessionItem = m_sessionManager->findSession(session);108 SessionInterface* session = m_sessionManager->findSession(mirSession);
109 auto qmlSurface = new MirSurfaceItem(surface, sessionItem);109 auto qmlSurface = new MirSurfaceItem(surface, session);
110 {110 {
111 QMutexLocker lock(&m_mutex);111 QMutexLocker lock(&m_mutex);
112 m_mirSurfaceToItemHash.insert(surface.get(), qmlSurface);112 m_mirSurfaceToItemHash.insert(surface.get(), qmlSurface);
113 }113 }
114114
115 if (sessionItem)115 if (session)
116 sessionItem->setSurface(qmlSurface);116 session->setSurface(qmlSurface);
117117
118 // Only notify QML of surface creation once it has drawn its first frame.118 // Only notify QML of surface creation once it has drawn its first frame.
119 connect(qmlSurface, &MirSurfaceItem::firstFrameDrawn, this, [&](MirSurfaceItem *item) {119 connect(qmlSurface, &MirSurfaceItem::firstFrameDrawn, this, [&](MirSurfaceItem *item) {
120120
=== modified file 'src/modules/Unity/Application/plugin.cpp'
--- src/modules/Unity/Application/plugin.cpp 2014-09-01 16:07:27 +0000
+++ src/modules/Unity/Application/plugin.cpp 2014-09-11 21:25:08 +0000
@@ -65,6 +65,7 @@
65 qRegisterMetaType<qtmir::MirSurfaceItem*>("MirSurfaceItem*");65 qRegisterMetaType<qtmir::MirSurfaceItem*>("MirSurfaceItem*");
66 qRegisterMetaType<qtmir::MirSurfaceItemModel*>("MirSurfaceItemModel*");66 qRegisterMetaType<qtmir::MirSurfaceItemModel*>("MirSurfaceItemModel*");
67 qRegisterMetaType<qtmir::Session*>("Session*");67 qRegisterMetaType<qtmir::Session*>("Session*");
68 qRegisterMetaType<qtmir::SessionInterface*>("SessionInterface*");
68 qRegisterMetaType<qtmir::SessionModel*>("SessionModel*");69 qRegisterMetaType<qtmir::SessionModel*>("SessionModel*");
6970
70 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(71 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(
7172
=== modified file 'src/modules/Unity/Application/session.cpp'
--- src/modules/Unity/Application/session.cpp 2014-09-01 16:07:27 +0000
+++ src/modules/Unity/Application/session.cpp 2014-09-11 21:25:08 +0000
@@ -34,13 +34,15 @@
3434
35namespace ms = mir::scene;35namespace ms = mir::scene;
3636
37using unity::shell::application::ApplicationInfoInterface;
38
37namespace qtmir39namespace qtmir
38{40{
3941
40Session::Session(const std::shared_ptr<ms::Session>& session,42Session::Session(const std::shared_ptr<ms::Session>& session,
41 const std::shared_ptr<ms::PromptSessionManager>& promptSessionManager,43 const std::shared_ptr<ms::PromptSessionManager>& promptSessionManager,
42 QObject *parent)44 QObject *parent)
43 : QObject(parent)45 : SessionInterface(parent)
44 , m_session(session)46 , m_session(session)
45 , m_application(nullptr)47 , m_application(nullptr)
46 , m_surface(nullptr)48 , m_surface(nullptr)
@@ -72,8 +74,8 @@
72 qCDebug(QTMIR_SESSIONS) << "Session::~Session() " << name();74 qCDebug(QTMIR_SESSIONS) << "Session::~Session() " << name();
73 stopPromptSessions();75 stopPromptSessions();
7476
75 QList<Session*> children(m_children->list());77 QList<SessionInterface*> children(m_children->list());
76 for (Session* child : children) {78 for (SessionInterface* child : children) {
77 delete child;79 delete child;
78 }80 }
79 if (m_parentSession) {81 if (m_parentSession) {
@@ -112,7 +114,7 @@
112 return m_session;114 return m_session;
113}115}
114116
115Application* Session::application() const117ApplicationInfoInterface* Session::application() const
116{118{
117 return m_application;119 return m_application;
118}120}
@@ -127,7 +129,7 @@
127 }129 }
128}130}
129131
130Session* Session::parentSession() const132SessionInterface* Session::parentSession() const
131{133{
132 return m_parentSession;134 return m_parentSession;
133}135}
@@ -147,12 +149,12 @@
147 return m_live;149 return m_live;
148}150}
149151
150void Session::setApplication(Application* application)152void Session::setApplication(ApplicationInfoInterface* application)
151{153{
152 if (m_application == application)154 if (m_application == application)
153 return;155 return;
154156
155 m_application = application;157 m_application = static_cast<Application*>(application);
156 Q_EMIT applicationChanged(application);158 Q_EMIT applicationChanged(application);
157}159}
158160
@@ -251,7 +253,7 @@
251 m_state = state;253 m_state = state;
252 Q_EMIT stateChanged(state);254 Q_EMIT stateChanged(state);
253255
254 foreachChildSession([state](Session* session) {256 foreachChildSession([state](SessionInterface* session) {
255 session->setState(state);257 session->setState(state);
256 });258 });
257 }259 }
@@ -275,35 +277,35 @@
275 Q_EMIT parentSessionChanged(session);277 Q_EMIT parentSessionChanged(session);
276}278}
277279
278void Session::addChildSession(Session* session)280void Session::addChildSession(SessionInterface* session)
279{281{
280 insertChildSession(m_children->rowCount(), session);282 insertChildSession(m_children->rowCount(), session);
281}283}
282284
283void Session::insertChildSession(uint index, Session* session)285void Session::insertChildSession(uint index, SessionInterface* session)
284{286{
285 qCDebug(QTMIR_SESSIONS) << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;287 qCDebug(QTMIR_SESSIONS) << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;
286288
287 session->setParentSession(this);289 static_cast<Session*>(session)->setParentSession(this);
288 m_children->insert(index, session);290 m_children->insert(index, session);
289291
290 session->setState(state());292 session->setState(state());
291}293}
292294
293void Session::removeChildSession(Session* session)295void Session::removeChildSession(SessionInterface* session)
294{296{
295 qCDebug(QTMIR_SESSIONS) << "Session::removeChildSession - " << session->name() << " from " << name();297 qCDebug(QTMIR_SESSIONS) << "Session::removeChildSession - " << session->name() << " from " << name();
296298
297 if (m_children->contains(session)) {299 if (m_children->contains(session)) {
298 m_children->remove(session);300 m_children->remove(session);
299 session->setParentSession(nullptr);301 static_cast<Session*>(session)->setParentSession(nullptr);
300 }302 }
301}303}
302304
303void Session::foreachChildSession(std::function<void(Session* session)> f) const305void Session::foreachChildSession(std::function<void(SessionInterface* session)> f) const
304{306{
305 QList<Session*> children(m_children->list());307 QList<SessionInterface*> children(m_children->list());
306 for (Session* child : children) {308 for (SessionInterface* child : children) {
307 f(child);309 f(child);
308 }310 }
309}311}
@@ -331,9 +333,9 @@
331333
332void Session::stopPromptSessions()334void Session::stopPromptSessions()
333{335{
334 QList<Session*> children(m_children->list());336 QList<SessionInterface*> children(m_children->list());
335 for (Session* child : children) {337 for (SessionInterface* child : children) {
336 child->stopPromptSessions();338 static_cast<Session*>(child)->stopPromptSessions();
337 }339 }
338340
339 QList<std::shared_ptr<ms::PromptSession>> copy(m_promptSessions);341 QList<std::shared_ptr<ms::PromptSession>> copy(m_promptSessions);
340342
=== modified file 'src/modules/Unity/Application/session.h'
--- src/modules/Unity/Application/session.h 2014-09-01 16:07:27 +0000
+++ src/modules/Unity/Application/session.h 2014-09-11 21:25:08 +0000
@@ -21,19 +21,15 @@
21#include <memory>21#include <memory>
2222
23// local23// local
24#include "sessionmodel.h"24#include "session_interface.h"
2525
26// Qt26// Qt
27#include <QObject>27#include <QObject>
28#include <QTimer>28#include <QTimer>
2929
30// Unity API
31#include <unity/shell/application/ApplicationInfoInterface.h>
3230
33namespace mir {31namespace mir {
34 namespace scene {32 namespace scene {
35 class Session;
36 class PromptSession;
37 class PromptSessionManager;33 class PromptSessionManager;
38 }34 }
39}35}
@@ -41,83 +37,61 @@
41namespace qtmir {37namespace qtmir {
4238
43class Application;39class Application;
44class MirSurfaceItem;
4540
46class Session : public QObject41class Session : public SessionInterface
47{42{
48 Q_OBJECT43 Q_OBJECT
49 Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
50 Q_PROPERTY(Application* application READ application NOTIFY applicationChanged DESIGNABLE false)
51 Q_PROPERTY(Session* parentSession READ parentSession NOTIFY parentSessionChanged DESIGNABLE false)
52 Q_PROPERTY(SessionModel* childSessions READ childSessions DESIGNABLE false CONSTANT)
53 Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged)
54 Q_PROPERTY(bool live READ live NOTIFY liveChanged)
55
56public:44public:
57 explicit Session(const std::shared_ptr<mir::scene::Session>& session,45 explicit Session(const std::shared_ptr<mir::scene::Session>& session,
58 const std::shared_ptr<mir::scene::PromptSessionManager>& promptSessionManager,46 const std::shared_ptr<mir::scene::PromptSessionManager>& promptSessionManager,
59 QObject *parent = 0);47 QObject *parent = 0);
60 ~Session();48 virtual ~Session();
6149
62 // Session State50 Q_INVOKABLE void release() override;
63 typedef unity::shell::application::ApplicationInfoInterface::State State;
64
65 Q_INVOKABLE void release();
6651
67 //getters52 //getters
68 QString name() const;53 QString name() const override;
69 Application* application() const;54 unity::shell::application::ApplicationInfoInterface* application() const override;
70 MirSurfaceItem* surface() const;55 MirSurfaceItem* surface() const override;
71 Session* parentSession() const;56 SessionInterface* parentSession() const override;
72 State state() const;57 State state() const override;
73 bool fullscreen() const;58 bool fullscreen() const override;
74 bool live() const;59 bool live() const override;
7560
76 void setSession();61 void setApplication(unity::shell::application::ApplicationInfoInterface* item) override;
77 void setApplication(Application* item);62 void setSurface(MirSurfaceItem* surface) override;
78 void setSurface(MirSurfaceItem* surface);63 void setState(State state) override;
79 void setState(State state);64
8065 void addChildSession(SessionInterface* session) override;
81 void addChildSession(Session* session);66 void insertChildSession(uint index, SessionInterface* session) override;
82 void insertChildSession(uint index, Session* session);67 void removeChildSession(SessionInterface* session) override;
83 void removeChildSession(Session* session);68 void foreachChildSession(std::function<void(SessionInterface* session)> f) const override;
84 void foreachChildSession(std::function<void(Session* session)> f) const;69
8570 std::shared_ptr<mir::scene::Session> session() const override;
86 std::shared_ptr<mir::scene::Session> session() const;71
8772 std::shared_ptr<mir::scene::PromptSession> activePromptSession() const override;
88 std::shared_ptr<mir::scene::PromptSession> activePromptSession() const;73 void foreachPromptSession(std::function<void(const std::shared_ptr<mir::scene::PromptSession>&)> f) const override;
89 void foreachPromptSession(std::function<void(const std::shared_ptr<mir::scene::PromptSession>&)> f) const;74
9075 SessionModel* childSessions() const override;
91Q_SIGNALS:76
92 void surfaceChanged(MirSurfaceItem*);77protected:
93 void parentSessionChanged(Session*);78 void setFullscreen(bool fullscreen) override;
94 void applicationChanged(Application* application);79 void setLive(const bool) override;
95 void aboutToBeDestroyed();80 void appendPromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) override;
96 void stateChanged(State state);81 void removePromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) override;
97 void fullscreenChanged(bool fullscreen);
98 void liveChanged(bool live);
99
100 void suspended();
101 void resumed();
10282
103private Q_SLOTS:83private Q_SLOTS:
104 void updateFullscreenProperty();84 void updateFullscreenProperty();
10585
106private:86private:
107 SessionModel* childSessions() const;
108 void setParentSession(Session* session);87 void setParentSession(Session* session);
10988
110 void appendPromptSession(const std::shared_ptr<mir::scene::PromptSession>& session);
111 void removePromptSession(const std::shared_ptr<mir::scene::PromptSession>& session);
112 void stopPromptSessions();89 void stopPromptSessions();
11390
114 void setFullscreen(bool fullscreen);
115 void setLive(const bool);
116
117 std::shared_ptr<mir::scene::Session> m_session;91 std::shared_ptr<mir::scene::Session> m_session;
118 Application* m_application;92 Application* m_application;
119 MirSurfaceItem* m_surface;93 MirSurfaceItem* m_surface;
120 Session* m_parentSession;94 SessionInterface* m_parentSession;
121 SessionModel* m_children;95 SessionModel* m_children;
122 bool m_fullscreen;96 bool m_fullscreen;
123 State m_state;97 State m_state;
@@ -125,8 +99,6 @@
125 QTimer* m_suspendTimer;99 QTimer* m_suspendTimer;
126 QList<std::shared_ptr<mir::scene::PromptSession>> m_promptSessions;100 QList<std::shared_ptr<mir::scene::PromptSession>> m_promptSessions;
127 std::shared_ptr<mir::scene::PromptSessionManager> const m_promptSessionManager;101 std::shared_ptr<mir::scene::PromptSessionManager> const m_promptSessionManager;
128
129 friend class SessionManager;
130};102};
131103
132} // namespace qtmir104} // namespace qtmir
133105
=== added file 'src/modules/Unity/Application/session_interface.h'
--- src/modules/Unity/Application/session_interface.h 1970-01-01 00:00:00 +0000
+++ src/modules/Unity/Application/session_interface.h 2014-09-11 21:25:08 +0000
@@ -0,0 +1,106 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef SESSION_INTERFACE_H
18#define SESSION_INTERFACE_H
19
20#include <functional>
21#include <memory>
22
23// Unity API
24#include <unity/shell/application/ApplicationInfoInterface.h>
25
26// local
27#include "sessionmodel.h"
28
29namespace mir {
30 namespace scene {
31 class Session;
32 class PromptSession;
33 }
34}
35
36namespace qtmir {
37
38class MirSurfaceItem;
39
40class SessionInterface : public QObject {
41 Q_OBJECT
42 Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
43 Q_PROPERTY(unity::shell::application::ApplicationInfoInterface* application READ application NOTIFY applicationChanged DESIGNABLE false)
44 Q_PROPERTY(SessionInterface* parentSession READ parentSession NOTIFY parentSessionChanged DESIGNABLE false)
45 Q_PROPERTY(SessionModel* childSessions READ childSessions DESIGNABLE false CONSTANT)
46 Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged)
47 Q_PROPERTY(bool live READ live NOTIFY liveChanged)
48public:
49 SessionInterface(QObject *parent = 0) : QObject(parent) {}
50 virtual ~SessionInterface() {}
51
52 // Session State
53 typedef unity::shell::application::ApplicationInfoInterface::State State;
54
55 Q_INVOKABLE virtual void release() = 0;
56
57 //getters
58 virtual QString name() const = 0;
59 virtual unity::shell::application::ApplicationInfoInterface* application() const = 0;
60 virtual MirSurfaceItem* surface() const = 0;
61 virtual SessionInterface* parentSession() const = 0;
62 virtual State state() const = 0;
63 virtual bool fullscreen() const = 0;
64 virtual bool live() const = 0;
65
66 virtual void setApplication(unity::shell::application::ApplicationInfoInterface* item) = 0;
67 virtual void setSurface(MirSurfaceItem* surface) = 0;
68 virtual void setState(State state) = 0;
69
70 virtual void addChildSession(SessionInterface* session) = 0;
71 virtual void insertChildSession(uint index, SessionInterface* session) = 0;
72 virtual void removeChildSession(SessionInterface* session) = 0;
73 virtual void foreachChildSession(std::function<void(SessionInterface* session)> f) const = 0;
74
75 virtual std::shared_ptr<mir::scene::Session> session() const = 0;
76
77 virtual std::shared_ptr<mir::scene::PromptSession> activePromptSession() const = 0;
78 virtual void foreachPromptSession(std::function<void(const std::shared_ptr<mir::scene::PromptSession>&)> f) const = 0;
79
80 virtual SessionModel* childSessions() const = 0;
81
82Q_SIGNALS:
83 void surfaceChanged(MirSurfaceItem*);
84 void parentSessionChanged(SessionInterface*);
85 void applicationChanged(unity::shell::application::ApplicationInfoInterface* application);
86 void aboutToBeDestroyed();
87 void stateChanged(State state);
88 void fullscreenChanged(bool fullscreen);
89 void liveChanged(bool live);
90
91 void suspended();
92 void resumed();
93
94protected:
95 virtual void setFullscreen(bool fullscreen) = 0;
96 virtual void setLive(const bool) = 0;
97 virtual void appendPromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) = 0;
98 virtual void removePromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) = 0;
99
100 friend class SessionManager;
101};
102
103} // namespace qtmir
104
105
106#endif // SESSION_INTERFACE_H
0107
=== modified file 'src/modules/Unity/Application/sessionmanager.cpp'
--- src/modules/Unity/Application/sessionmanager.cpp 2014-08-29 14:58:07 +0000
+++ src/modules/Unity/Application/sessionmanager.cpp 2014-09-11 21:25:08 +0000
@@ -103,11 +103,11 @@
103 qCDebug(QTMIR_SESSIONS) << "SessionManager::~SessionManager - this=" << this;103 qCDebug(QTMIR_SESSIONS) << "SessionManager::~SessionManager - this=" << this;
104}104}
105105
106Session *SessionManager::findSession(const mir::scene::Session* session) const106SessionInterface *SessionManager::findSession(const mir::scene::Session* session) const
107{107{
108 if (!session) return nullptr;108 if (!session) return nullptr;
109109
110 for (Session* child : list()) {110 for (SessionInterface* child : list()) {
111 if (child->session().get() == session)111 if (child->session().get() == session)
112 return child;112 return child;
113 }113 }
@@ -139,7 +139,7 @@
139{139{
140 qCDebug(QTMIR_SESSIONS) << "SessionManager::onSessionStopping - sessionName=" << session->name().c_str();140 qCDebug(QTMIR_SESSIONS) << "SessionManager::onSessionStopping - sessionName=" << session->name().c_str();
141141
142 Session* qmlSession = findSession(session.get());142 SessionInterface* qmlSession = findSession(session.get());
143 if (!qmlSession) return;143 if (!qmlSession) return;
144144
145 remove(qmlSession);145 remove(qmlSession);
@@ -153,7 +153,7 @@
153 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptSessionStarting - promptSession=" << promptSession.get();153 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptSessionStarting - promptSession=" << promptSession.get();
154154
155 std::shared_ptr<mir::scene::Session> appSession = m_mirConfig->the_prompt_session_manager()->application_for(promptSession);155 std::shared_ptr<mir::scene::Session> appSession = m_mirConfig->the_prompt_session_manager()->application_for(promptSession);
156 Session *qmlAppSession = findSession(appSession.get());156 SessionInterface *qmlAppSession = findSession(appSession.get());
157 if (qmlAppSession) {157 if (qmlAppSession) {
158 m_mirPromptToSessionHash[promptSession.get()] = qmlAppSession;158 m_mirPromptToSessionHash[promptSession.get()] = qmlAppSession;
159 qmlAppSession->appendPromptSession(promptSession);159 qmlAppSession->appendPromptSession(promptSession);
@@ -166,7 +166,7 @@
166{166{
167 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptSessionStopping - promptSession=" << promptSession.get();167 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptSessionStopping - promptSession=" << promptSession.get();
168168
169 for (Session *qmlSession : this->list()) {169 for (SessionInterface *qmlSession : this->list()) {
170 qmlSession->removePromptSession(promptSession);170 qmlSession->removePromptSession(promptSession);
171 }171 }
172 m_mirPromptToSessionHash.remove(promptSession.get());172 m_mirPromptToSessionHash.remove(promptSession.get());
@@ -177,13 +177,13 @@
177{177{
178 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - promptSession=" << promptSession << " promptProvider=" << promptProvider.get();178 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - promptSession=" << promptSession << " promptProvider=" << promptProvider.get();
179179
180 Session* qmlAppSession = m_mirPromptToSessionHash.value(promptSession, nullptr);180 SessionInterface* qmlAppSession = m_mirPromptToSessionHash.value(promptSession, nullptr);
181 if (!qmlAppSession) {181 if (!qmlAppSession) {
182 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for app session";182 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for app session";
183 return;183 return;
184 }184 }
185185
186 Session* qmlPromptProvider = findSession(promptProvider.get());186 SessionInterface* qmlPromptProvider = findSession(promptProvider.get());
187 if (!qmlPromptProvider) {187 if (!qmlPromptProvider) {
188 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for provider session";188 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for provider session";
189 return;189 return;
@@ -197,7 +197,7 @@
197{197{
198 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderRemoved - promptSession=" << promptSession << " promptProvider=" << promptProvider.get();198 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderRemoved - promptSession=" << promptSession << " promptProvider=" << promptProvider.get();
199199
200 Session* qmlPromptProvider = findSession(promptProvider.get());200 SessionInterface* qmlPromptProvider = findSession(promptProvider.get());
201 if (!qmlPromptProvider) {201 if (!qmlPromptProvider) {
202 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for provider session";202 qCDebug(QTMIR_SESSIONS) << "SessionManager::onPromptProviderAdded - could not find session item for provider session";
203 return;203 return;
204204
=== modified file 'src/modules/Unity/Application/sessionmanager.h'
--- src/modules/Unity/Application/sessionmanager.h 2014-08-28 23:36:42 +0000
+++ src/modules/Unity/Application/sessionmanager.h 2014-09-11 21:25:08 +0000
@@ -59,11 +59,11 @@
5959
60 static SessionManager* singleton();60 static SessionManager* singleton();
6161
62 Session *findSession(const mir::scene::Session* session) const;62 SessionInterface *findSession(const mir::scene::Session* session) const;
6363
64Q_SIGNALS:64Q_SIGNALS:
65 void sessionStarting(Session* session);65 void sessionStarting(SessionInterface* session);
66 void sessionStopping(Session* session);66 void sessionStopping(SessionInterface* session);
6767
68public Q_SLOTS:68public Q_SLOTS:
69 void onSessionStarting(std::shared_ptr<mir::scene::Session> const& session);69 void onSessionStarting(std::shared_ptr<mir::scene::Session> const& session);
@@ -82,7 +82,7 @@
82 static SessionManager *the_session_manager;82 static SessionManager *the_session_manager;
8383
84 QList<Session*> m_sessions;84 QList<Session*> m_sessions;
85 QHash<const mir::scene::PromptSession *, Session *> m_mirPromptToSessionHash;85 QHash<const mir::scene::PromptSession *, SessionInterface *> m_mirPromptToSessionHash;
86};86};
8787
88} // namespace qtmir88} // namespace qtmir
8989
=== modified file 'src/modules/Unity/Application/sessionmodel.h'
--- src/modules/Unity/Application/sessionmodel.h 2014-08-29 11:15:51 +0000
+++ src/modules/Unity/Application/sessionmodel.h 2014-09-11 21:25:08 +0000
@@ -22,8 +22,8 @@
2222
23namespace qtmir {23namespace qtmir {
2424
25class Session;25class SessionInterface;
26typedef ObjectListModel<Session> SessionModel;26typedef ObjectListModel<SessionInterface> SessionModel;
2727
28} // namespace qtmir28} // namespace qtmir
2929
3030
=== modified file 'tests/modules/ApplicationManager/application_manager_test.cpp'
--- tests/modules/ApplicationManager/application_manager_test.cpp 2014-08-29 10:18:57 +0000
+++ tests/modules/ApplicationManager/application_manager_test.cpp 2014-09-11 21:25:08 +0000
@@ -25,6 +25,7 @@
25 #include "qtmir_test.h"25 #include "qtmir_test.h"
2626
27using namespace qtmir;27using namespace qtmir;
28using mir::scene::MockSession;
2829
29namespace ms = mir::scene;30namespace ms = mir::scene;
3031
@@ -1774,7 +1775,7 @@
1774 }).detach();1775 }).detach();
1775 }));1776 }));
17761777
1777 auto mockSurface = std::make_shared<MockSurface>();1778 auto mockSurface = std::make_shared<ms::MockSurface>();
1778 EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));1779 EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));
17791780
1780 {1781 {
@@ -1826,7 +1827,7 @@
1826 }).detach();1827 }).detach();
1827 }));1828 }));
18281829
1829 auto mockSurface = std::make_shared<MockSurface>();1830 auto mockSurface = std::make_shared<ms::MockSurface>();
1830 EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));1831 EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));
18311832
1832 {1833 {
18331834
=== added directory 'tests/modules/MirSurfaceItem'
=== added file 'tests/modules/MirSurfaceItem/MirSurfaceItem.pro'
--- tests/modules/MirSurfaceItem/MirSurfaceItem.pro 1970-01-01 00:00:00 +0000
+++ tests/modules/MirSurfaceItem/MirSurfaceItem.pro 2014-09-11 21:25:08 +0000
@@ -0,0 +1,13 @@
1include(../../test-includes.pri)
2include(../common/common.pri)
3
4TARGET = mirsurfaceitem_test
5
6QT += testlib
7
8INCLUDEPATH += \
9 ../../../src/platforms/mirserver \
10 ../../../src/modules/Unity/Application
11
12SOURCES += \
13 mirsurfaceitem_test.cpp
014
=== added file 'tests/modules/MirSurfaceItem/mirsurfaceitem_test.cpp'
--- tests/modules/MirSurfaceItem/mirsurfaceitem_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/modules/MirSurfaceItem/mirsurfaceitem_test.cpp 2014-09-11 21:25:08 +0000
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 */
17
18#include <gtest/gtest.h>
19
20#include <QLoggingCategory>
21#include <QTest>
22
23// the test subject
24#include <mirsurfaceitem.h>
25
26// mocks
27#include <mock_surface.h>
28#include <mock_session.h>
29
30using namespace qtmir;
31
32using mir::scene::MockSurface;
33using qtmir::MockSession;
34
35// gtest stuff
36using ::testing::_;
37using ::testing::AnyNumber;
38using ::testing::Invoke;
39using ::testing::InSequence;
40using ::testing::Return;
41
42/*
43 Tests that even if Qt fails to finish a touch sequence, MirSurfaceItem will
44 properly finish it when forwarding it to its mir::input::surface. So
45 mir::input::surface will still consume a proper sequence of touch events
46 (comprised of a begin, zero or more updates and an end).
47 */
48TEST(MirSurfaceItemTest, MissingTouchEnd)
49{
50 // We don't want the logging spam cluttering the test results
51 QLoggingCategory::setFilterRules(QStringLiteral("qtmir*=false"));
52
53 std::shared_ptr<MockSurface> mockSurface = std::make_shared<MockSurface>();
54 MockSession *mockSession = new MockSession;
55
56 // Set some expectations and behavior for calls we are not interested in
57 EXPECT_CALL(*mockSurface, add_observer(_)).Times(AnyNumber());
58 EXPECT_CALL(*mockSurface, remove_observer(_)).Times(AnyNumber());
59 EXPECT_CALL(*mockSurface, size()).Times(AnyNumber()).WillRepeatedly(Return(mir::geometry::Size(100,100)));
60 EXPECT_CALL(*mockSurface, type()).Times(AnyNumber()).WillRepeatedly(Return(mir_surface_type_normal));
61 EXPECT_CALL(*mockSession, setSurface(_)).Times(AnyNumber());
62
63 // The touch event sequence we expect mir::input::surface to receive from MirSurfaceItem.
64 // It should properly finish the sequence for touch 0 ('down', 'move' and 'up') before starting
65 // the sequence for touch 1.
66 EXPECT_CALL(*mockSurface, consume(_))
67 .WillOnce(Invoke([] (MirEvent const& mirEvent) {
68 ASSERT_EQ(mir_motion_action_down, mirEvent.motion.action);
69 ASSERT_EQ(1, mirEvent.motion.pointer_count);
70 ASSERT_EQ(0, mirEvent.motion.pointer_coordinates[0].id);
71 }))
72 .WillOnce(Invoke([] (MirEvent const& mirEvent) {
73 ASSERT_EQ(mir_motion_action_move, mirEvent.motion.action);
74 ASSERT_EQ(1, mirEvent.motion.pointer_count);
75 ASSERT_EQ(0, mirEvent.motion.pointer_coordinates[0].id);
76 }))
77 .WillOnce(Invoke([] (MirEvent const& mirEvent) {
78 ASSERT_EQ(mir_motion_action_up, mirEvent.motion.action);
79 ASSERT_EQ(1, mirEvent.motion.pointer_count);
80 ASSERT_EQ(0, mirEvent.motion.pointer_coordinates[0].id);
81 }))
82 .WillOnce(Invoke([] (MirEvent const& mirEvent) {
83 ASSERT_EQ(mir_motion_action_down, mirEvent.motion.action);
84 ASSERT_EQ(1, mirEvent.motion.pointer_count);
85 ASSERT_EQ(1, mirEvent.motion.pointer_coordinates[0].id);
86 }));
87
88
89 MirSurfaceItem *surfaceItem = new MirSurfaceItem(mockSurface, mockSession);
90
91 ulong timestamp = 1234;
92 QList<QTouchEvent::TouchPoint> touchPoints;
93 touchPoints.append(QTouchEvent::TouchPoint());
94
95 touchPoints[0].setId(0);
96 touchPoints[0].setState(Qt::TouchPointPressed);
97 surfaceItem->processTouchEvent(QEvent::TouchBegin,
98 timestamp, touchPoints, touchPoints[0].state());
99
100 touchPoints[0].setState(Qt::TouchPointMoved);
101 surfaceItem->processTouchEvent(QEvent::TouchUpdate,
102 timestamp + 10, touchPoints, touchPoints[0].state());
103
104 // Starting a new touch sequence (with touch 1) without ending the current one
105 // (wich has touch 0).
106 touchPoints[0].setId(1);
107 touchPoints[0].setState(Qt::TouchPointPressed);
108 surfaceItem->processTouchEvent(QEvent::TouchBegin,
109 timestamp + 20, touchPoints, touchPoints[0].state());
110
111 delete surfaceItem;
112 delete mockSession;
113}
0114
=== modified file 'tests/modules/SessionManager/session_manager_test.cpp'
--- tests/modules/SessionManager/session_manager_test.cpp 2014-08-29 14:58:07 +0000
+++ tests/modules/SessionManager/session_manager_test.cpp 2014-09-11 21:25:08 +0000
@@ -24,6 +24,7 @@
24 #include "qtmir_test.h"24 #include "qtmir_test.h"
2525
26using namespace qtmir;26using namespace qtmir;
27using mir::scene::MockSession;
2728
28namespace ms = mir::scene;29namespace ms = mir::scene;
2930
@@ -33,7 +34,7 @@
33 SessionManagerTests()34 SessionManagerTests()
34 {}35 {}
3536
36 QList<std::shared_ptr<ms::PromptSession>> listPromptSessions(Session* session) {37 QList<std::shared_ptr<ms::PromptSession>> listPromptSessions(SessionInterface* session) {
37 QList<std::shared_ptr<ms::PromptSession>> promptSessions;38 QList<std::shared_ptr<ms::PromptSession>> promptSessions;
38 session->foreachPromptSession([&promptSessions](const std::shared_ptr<ms::PromptSession>& promptSession) {39 session->foreachPromptSession([&promptSessions](const std::shared_ptr<ms::PromptSession>& promptSession) {
39 promptSessions << promptSession;40 promptSessions << promptSession;
@@ -41,9 +42,9 @@
41 return promptSessions;42 return promptSessions;
42 }43 }
4344
44 QList<Session*> listChildSessions(Session* session) {45 QList<SessionInterface*> listChildSessions(SessionInterface* session) {
45 QList<Session*> sessions;46 QList<SessionInterface*> sessions;
46 session->foreachChildSession([&sessions](Session* session) {47 session->foreachChildSession([&sessions](SessionInterface* session) {
47 sessions << session;48 sessions << session;
48 });49 });
49 return sessions;50 return sessions;
@@ -56,10 +57,10 @@
5657
57 std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);58 std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);
58 sessionManager.onSessionStarting(mirAppSession);59 sessionManager.onSessionStarting(mirAppSession);
59 Session* qtmirAppSession = sessionManager.findSession(mirAppSession.get());60 SessionInterface* qtmirAppSession = sessionManager.findSession(mirAppSession.get());
60 EXPECT_TRUE(qtmirAppSession != nullptr);61 EXPECT_TRUE(qtmirAppSession != nullptr);
6162
62 auto promptSession = std::make_shared<MockPromptSession>();63 auto promptSession = std::make_shared<ms::MockPromptSession>();
63 ON_CALL(*mirConfig->the_mock_prompt_session_manager(), application_for(_)).WillByDefault(Return(mirAppSession));64 ON_CALL(*mirConfig->the_mock_prompt_session_manager(), application_for(_)).WillByDefault(Return(mirAppSession));
6465
65 sessionManager.onPromptSessionStarting(promptSession);66 sessionManager.onPromptSessionStarting(promptSession);
@@ -80,18 +81,18 @@
8081
81 std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);82 std::shared_ptr<ms::Session> mirAppSession = std::make_shared<MockSession>("mirAppSession", __LINE__);
82 sessionManager.onSessionStarting(mirAppSession);83 sessionManager.onSessionStarting(mirAppSession);
83 Session* qtmirAppSession = sessionManager.findSession(mirAppSession.get());84 SessionInterface* qtmirAppSession = sessionManager.findSession(mirAppSession.get());
84 EXPECT_TRUE(qtmirAppSession != nullptr);85 EXPECT_TRUE(qtmirAppSession != nullptr);
8586
86 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), application_for(_)).WillRepeatedly(Return(mirAppSession));87 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), application_for(_)).WillRepeatedly(Return(mirAppSession));
87 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), helper_for(_)).WillRepeatedly(Return(nullptr));88 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), helper_for(_)).WillRepeatedly(Return(nullptr));
8889
89 std::shared_ptr<ms::PromptSession> mirPromptSession = std::make_shared<MockPromptSession>();90 std::shared_ptr<ms::PromptSession> mirPromptSession = std::make_shared<ms::MockPromptSession>();
9091
91 // prompt provider session92 // prompt provider session
92 std::shared_ptr<ms::Session> mirProviderSession = std::make_shared<MockSession>("mirProviderSession", __LINE__);93 std::shared_ptr<ms::Session> mirProviderSession = std::make_shared<MockSession>("mirProviderSession", __LINE__);
93 sessionManager.onSessionStarting(mirProviderSession);94 sessionManager.onSessionStarting(mirProviderSession);
94 Session* qtmirProviderSession = sessionManager.findSession(mirProviderSession.get());95 SessionInterface* qtmirProviderSession = sessionManager.findSession(mirProviderSession.get());
9596
96 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), for_each_provider_in(mirPromptSession,_)).WillRepeatedly(WithArgs<1>(Invoke(97 EXPECT_CALL(*mirConfig->the_mock_prompt_session_manager(), for_each_provider_in(mirPromptSession,_)).WillRepeatedly(WithArgs<1>(Invoke(
97 [&](std::function<void(std::shared_ptr<ms::Session> const& prompt_provider)> const& f) {98 [&](std::function<void(std::shared_ptr<ms::Session> const& prompt_provider)> const& f) {
9899
=== modified file 'tests/modules/SessionManager/session_test.cpp'
--- tests/modules/SessionManager/session_test.cpp 2014-08-28 23:36:42 +0000
+++ tests/modules/SessionManager/session_test.cpp 2014-09-11 21:25:08 +0000
@@ -22,6 +22,8 @@
22#include "stub_scene_surface.h"22#include "stub_scene_surface.h"
2323
24using namespace qtmir;24using namespace qtmir;
25using mir::scene::MockSession;
26
2527
26namespace ms = mir::scene;28namespace ms = mir::scene;
27namespace mtd = mir::test::doubles;29namespace mtd = mir::test::doubles;
@@ -32,9 +34,9 @@
32 SessionTests()34 SessionTests()
33 {}35 {}
3436
35 QList<Session*> listChildSessions(Session* session) {37 QList<SessionInterface*> listChildSessions(Session* session) {
36 QList<Session*> sessions;38 QList<SessionInterface*> sessions;
37 session->foreachChildSession([&sessions](Session* session) {39 session->foreachChildSession([&sessions](SessionInterface* session) {
38 sessions << session;40 sessions << session;
39 });41 });
40 return sessions;42 return sessions;
@@ -151,17 +153,14 @@
151153
152 // delete surfaces154 // delete surfaces
153 delete session2;155 delete session2;
154 EXPECT_EQ(session2->parentSession(), nullptr);
155 EXPECT_THAT(listChildSessions(&session), ElementsAre(session1, session3));156 EXPECT_THAT(listChildSessions(&session), ElementsAre(session1, session3));
156157
157 // delete surfaces158 // delete surfaces
158 delete session3;159 delete session3;
159 EXPECT_EQ(session3->parentSession(), nullptr);
160 EXPECT_THAT(listChildSessions(&session), ElementsAre(session1));160 EXPECT_THAT(listChildSessions(&session), ElementsAre(session1));
161161
162 // delete surfaces162 // delete surfaces
163 delete session1;163 delete session1;
164 EXPECT_EQ(session1->parentSession(), nullptr);
165 EXPECT_THAT(listChildSessions(&session), IsEmpty());164 EXPECT_THAT(listChildSessions(&session), IsEmpty());
166}165}
167166
168167
=== modified file 'tests/modules/common/common.pri'
--- tests/modules/common/common.pri 2014-09-07 19:42:14 +0000
+++ tests/modules/common/common.pri 2014-09-11 21:25:08 +0000
@@ -6,6 +6,7 @@
6HEADERS += ../common/mock_application_controller.h \6HEADERS += ../common/mock_application_controller.h \
7 ../common/mock_desktop_file_reader.h \7 ../common/mock_desktop_file_reader.h \
8 ../common/mock_focus_controller.h \8 ../common/mock_focus_controller.h \
9 ../common/mock_mir_session.h \
9 ../common/mock_oom_controller.h \10 ../common/mock_oom_controller.h \
10 ../common/mock_process_controller.h \11 ../common/mock_process_controller.h \
11 ../common/mock_proc_info.h \12 ../common/mock_proc_info.h \
1213
=== modified file 'tests/modules/common/mock_focus_controller.h'
--- tests/modules/common/mock_focus_controller.h 2014-07-01 13:38:06 +0000
+++ tests/modules/common/mock_focus_controller.h 2014-09-11 21:25:08 +0000
@@ -23,15 +23,18 @@
2323
24#include <string>24#include <string>
2525
26namespace testing26namespace mir {
27{27namespace shell {
28class MockFocusController : public mir::shell::FocusController28
29class MockFocusController : public FocusController
29{30{
30public:31public:
31 MOCK_METHOD0(focus_next, void());32 MOCK_METHOD0(focus_next, void());
32 MOCK_CONST_METHOD0(focussed_application, std::weak_ptr<mir::scene::Session>());33 MOCK_CONST_METHOD0(focussed_application, std::weak_ptr<scene::Session>());
33 MOCK_METHOD1(set_focus_to, void(std::shared_ptr<mir::scene::Session>const&));34 MOCK_METHOD1(set_focus_to, void(std::shared_ptr<scene::Session>const&));
34};35};
35}36
37} // namespace shell
38} // namespace mir
3639
37#endif // MOCK_MIR_SHELL_FOCUS_CONTROLLER_H_40#endif // MOCK_MIR_SHELL_FOCUS_CONTROLLER_H_
3841
=== renamed file 'tests/modules/common/mock_session.h' => 'tests/modules/common/mock_mir_session.h'
--- tests/modules/common/mock_session.h 2014-07-01 13:38:06 +0000
+++ tests/modules/common/mock_mir_session.h 2014-09-11 21:25:08 +0000
@@ -25,9 +25,10 @@
2525
26#include <string>26#include <string>
2727
28namespace testing28namespace mir {
29{29namespace scene {
30struct MockSession : public mir::scene::Session30
31struct MockSession : public Session
31{32{
32 MockSession() {}33 MockSession() {}
33 MockSession(std::string const& sessionName, pid_t processId) 34 MockSession(std::string const& sessionName, pid_t processId)
@@ -44,22 +45,20 @@
44 return m_sessionId;45 return m_sessionId;
45 }46 }
4647
47 typedef mir::frontend::SurfaceId SurfaceId;
48
49 MOCK_METHOD0(force_requests_to_complete, void());48 MOCK_METHOD0(force_requests_to_complete, void());
5049
51 MOCK_CONST_METHOD0(default_surface, std::shared_ptr<mir::scene::Surface>());50 MOCK_CONST_METHOD0(default_surface, std::shared_ptr<Surface>());
52 MOCK_CONST_METHOD1(get_surface, std::shared_ptr<mir::frontend::Surface>(SurfaceId));51 MOCK_CONST_METHOD1(get_surface, std::shared_ptr<frontend::Surface>(frontend::SurfaceId));
5352
54 MOCK_METHOD1(take_snapshot, void(mir::scene::SnapshotCallback const&));53 MOCK_METHOD1(take_snapshot, void(SnapshotCallback const&));
55 MOCK_METHOD1(set_lifecycle_state, void(MirLifecycleState));54 MOCK_METHOD1(set_lifecycle_state, void(MirLifecycleState));
56 MOCK_METHOD1(create_surface, SurfaceId(mir::scene::SurfaceCreationParameters const&));55 MOCK_METHOD1(create_surface, frontend::SurfaceId(SurfaceCreationParameters const&));
57 MOCK_METHOD1(destroy_surface, void (SurfaceId));56 MOCK_METHOD1(destroy_surface, void (frontend::SurfaceId));
5857
59 MOCK_METHOD0(hide, void());58 MOCK_METHOD0(hide, void());
60 MOCK_METHOD0(show, void());59 MOCK_METHOD0(show, void());
61 MOCK_METHOD1(send_display_config, void(mir::graphics::DisplayConfiguration const&));60 MOCK_METHOD1(send_display_config, void(graphics::DisplayConfiguration const&));
62 MOCK_METHOD3(configure_surface, int(SurfaceId, MirSurfaceAttrib, int));61 MOCK_METHOD3(configure_surface, int(frontend::SurfaceId, MirSurfaceAttrib, int));
6362
64 void start_prompt_session() override {};63 void start_prompt_session() override {};
65 void stop_prompt_session() override {};64 void stop_prompt_session() override {};
@@ -68,6 +67,8 @@
68 std::string m_sessionName;67 std::string m_sessionName;
69 pid_t m_sessionId;68 pid_t m_sessionId;
70};69};
71}70
71} // namespace scene
72} // namespace mir
7273
73#endif // MOCK_MIR_SCENE_SESSION_H74#endif // MOCK_MIR_SCENE_SESSION_H
7475
=== modified file 'tests/modules/common/mock_prompt_session.h'
--- tests/modules/common/mock_prompt_session.h 2014-07-21 15:51:17 +0000
+++ tests/modules/common/mock_prompt_session.h 2014-09-11 21:25:08 +0000
@@ -21,11 +21,14 @@
21#include <mir/scene/prompt_session.h>21#include <mir/scene/prompt_session.h>
22#include <gmock/gmock.h>22#include <gmock/gmock.h>
2323
24namespace testing24namespace mir {
25{25namespace scene {
26struct MockPromptSession : public mir::scene::PromptSession26
27struct MockPromptSession : public PromptSession
27{28{
28};29};
29}30
31} // namespace scene
32} // namespace mir
3033
31#endif // MOCK_MIR_PROMPT_SESSION_H34#endif // MOCK_MIR_PROMPT_SESSION_H
3235
=== modified file 'tests/modules/common/mock_prompt_session_manager.h'
--- tests/modules/common/mock_prompt_session_manager.h 2014-07-21 15:51:17 +0000
+++ tests/modules/common/mock_prompt_session_manager.h 2014-09-11 21:25:08 +0000
@@ -23,33 +23,36 @@
2323
24#include <gmock/gmock.h>24#include <gmock/gmock.h>
2525
26namespace testing26namespace mir {
27{27namespace scene {
28class MockPromptSessionManager: public mir::scene::PromptSessionManager28
29class MockPromptSessionManager: public PromptSessionManager
29{30{
30public:31public:
31 MOCK_CONST_METHOD2(start_prompt_session_for, std::shared_ptr<mir::scene::PromptSession>(std::shared_ptr<mir::scene::Session> const&,32 MOCK_CONST_METHOD2(start_prompt_session_for, std::shared_ptr<PromptSession>(std::shared_ptr<mir::scene::Session> const&,
32 mir::scene::PromptSessionCreationParameters const&));33 mir::scene::PromptSessionCreationParameters const&));
3334
34 MOCK_CONST_METHOD1(stop_prompt_session, void(std::shared_ptr<mir::scene::PromptSession> const&));35 MOCK_CONST_METHOD1(stop_prompt_session, void(std::shared_ptr<PromptSession> const&));
3536
36 MOCK_CONST_METHOD2(add_prompt_provider, void(std::shared_ptr<mir::scene::PromptSession> const&,37 MOCK_CONST_METHOD2(add_prompt_provider, void(std::shared_ptr<PromptSession> const&,
37 std::shared_ptr<mir::scene::Session> const&));38 std::shared_ptr<mir::scene::Session> const&));
3839
39 MOCK_CONST_METHOD2(add_prompt_provider_by_pid, void(std::shared_ptr<mir::scene::PromptSession> const&,40 MOCK_CONST_METHOD2(add_prompt_provider_by_pid, void(std::shared_ptr<PromptSession> const&,
40 pid_t));41 pid_t));
4142
42 MOCK_CONST_METHOD1(add_expected_session, void(std::shared_ptr<mir::scene::Session> const&));43 MOCK_CONST_METHOD1(add_expected_session, void(std::shared_ptr<Session> const&));
4344
44 MOCK_CONST_METHOD1(remove_session, void(std::shared_ptr<mir::scene::Session> const&));45 MOCK_CONST_METHOD1(remove_session, void(std::shared_ptr<Session> const&));
4546
46 MOCK_CONST_METHOD1(application_for, std::shared_ptr<mir::scene::Session>(std::shared_ptr<mir::scene::PromptSession> const&));47 MOCK_CONST_METHOD1(application_for, std::shared_ptr<Session>(std::shared_ptr<PromptSession> const&));
4748
48 MOCK_CONST_METHOD1(helper_for, std::shared_ptr<mir::scene::Session>(std::shared_ptr<mir::scene::PromptSession> const&));49 MOCK_CONST_METHOD1(helper_for, std::shared_ptr<Session>(std::shared_ptr<PromptSession> const&));
4950
50 MOCK_CONST_METHOD2(for_each_provider_in, void(std::shared_ptr<mir::scene::PromptSession> const&,51 MOCK_CONST_METHOD2(for_each_provider_in, void(std::shared_ptr<PromptSession> const&,
51 std::function<void(std::shared_ptr<mir::scene::Session> const&)> const&));52 std::function<void(std::shared_ptr<Session> const&)> const&));
52};53};
53} // namespace testing54
55} // namespace scene
56} // namespace mir
5457
55#endif // MOCK_MIR_SCENE_PROMPT_SESSION_MANAGER_H_58#endif // MOCK_MIR_SCENE_PROMPT_SESSION_MANAGER_H_
5659
=== modified file 'tests/modules/common/mock_renderable.h'
--- tests/modules/common/mock_renderable.h 2014-08-14 15:38:15 +0000
+++ tests/modules/common/mock_renderable.h 2014-09-11 21:25:08 +0000
@@ -21,23 +21,26 @@
21#include <mir/graphics/renderable.h>21#include <mir/graphics/renderable.h>
22#include <gmock/gmock.h>22#include <gmock/gmock.h>
2323
24namespace testing24namespace mir {
25{25namespace graphics {
26struct MockRenderable : public mir::graphics::Renderable26
27struct MockRenderable : public Renderable
27{28{
28 MockRenderable() {};29 MockRenderable() {};
2930
30 MOCK_CONST_METHOD0(id, ID());31 MOCK_CONST_METHOD0(id, ID());
31 MOCK_CONST_METHOD0(buffer, std::shared_ptr<mir::graphics::Buffer>());32 MOCK_CONST_METHOD0(buffer, std::shared_ptr<Buffer>());
32 MOCK_CONST_METHOD0(alpha_enabled, bool());33 MOCK_CONST_METHOD0(alpha_enabled, bool());
33 MOCK_CONST_METHOD0(screen_position, mir::geometry::Rectangle());34 MOCK_CONST_METHOD0(screen_position, geometry::Rectangle());
34 MOCK_CONST_METHOD0(alpha, float() );35 MOCK_CONST_METHOD0(alpha, float() );
35 MOCK_CONST_METHOD0(transformation, glm::mat4());36 MOCK_CONST_METHOD0(transformation, glm::mat4());
36 MOCK_CONST_METHOD0(visible, bool());37 MOCK_CONST_METHOD0(visible, bool());
37 MOCK_CONST_METHOD0(shaped, bool());38 MOCK_CONST_METHOD0(shaped, bool());
38 MOCK_CONST_METHOD0(buffers_ready_for_compositor, int());39 MOCK_CONST_METHOD0(buffers_ready_for_compositor, int());
39};40};
40}41
42} // namespace graphics
43} // namespace mir
4144
42#endif // MOCK_MIR_GRAPHICS_RENDERABLE_H45#endif // MOCK_MIR_GRAPHICS_RENDERABLE_H
4346
4447
=== added file 'tests/modules/common/mock_session.h'
--- tests/modules/common/mock_session.h 1970-01-01 00:00:00 +0000
+++ tests/modules/common/mock_session.h 2014-09-11 21:25:08 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 */
17
18#ifndef MOCK_QTMIR_SESSION_H
19#define MOCK_QTMIR_SESSION_H
20
21#include <session_interface.h>
22#include <gmock/gmock.h>
23
24namespace qtmir {
25
26class MockSession : public SessionInterface {
27public:
28 MockSession() : SessionInterface(0) {}
29
30 MOCK_METHOD0(release, void());
31
32 MOCK_CONST_METHOD0(name, QString());
33 MOCK_CONST_METHOD0(application, unity::shell::application::ApplicationInfoInterface*());
34 MOCK_CONST_METHOD0(surface, MirSurfaceItem*());
35 MOCK_CONST_METHOD0(parentSession, SessionInterface*());
36 MOCK_CONST_METHOD0(state, State());
37 MOCK_CONST_METHOD0(fullscreen, bool());
38 MOCK_CONST_METHOD0(live, bool());
39
40 MOCK_METHOD1(setApplication, void(unity::shell::application::ApplicationInfoInterface* item));
41 MOCK_METHOD1(setSurface, void(MirSurfaceItem* surface));
42 MOCK_METHOD1(setState, void(State state));
43
44 MOCK_METHOD1(addChildSession, void(SessionInterface* session));
45 MOCK_METHOD2(insertChildSession, void(uint index, SessionInterface* session));
46 MOCK_METHOD1(removeChildSession, void(SessionInterface* session));
47 MOCK_CONST_METHOD1(foreachChildSession, void(std::function<void(SessionInterface* session)> f));
48
49 MOCK_CONST_METHOD0(session, std::shared_ptr<mir::scene::Session>());
50
51 MOCK_CONST_METHOD0(activePromptSession, std::shared_ptr<mir::scene::PromptSession>());
52 MOCK_CONST_METHOD1(foreachPromptSession, void(std::function<void(const std::shared_ptr<mir::scene::PromptSession>&)> f));
53
54 MOCK_CONST_METHOD0(childSessions, SessionModel*());
55
56protected:
57 MOCK_METHOD1(setFullscreen, void(bool fullscreen));
58 MOCK_METHOD1(setLive, void(const bool));
59 MOCK_METHOD1(appendPromptSession, void(const std::shared_ptr<mir::scene::PromptSession>& session));
60 MOCK_METHOD1(removePromptSession, void(const std::shared_ptr<mir::scene::PromptSession>& session));
61};
62
63} // namespace qtmir
64
65#endif // MOCK_QTMIR_SESSION_H
066
=== modified file 'tests/modules/common/mock_surface.h'
--- tests/modules/common/mock_surface.h 2014-08-18 19:40:31 +0000
+++ tests/modules/common/mock_surface.h 2014-09-11 21:25:08 +0000
@@ -24,22 +24,22 @@
24#include <string>24#include <string>
25#include "mock_renderable.h"25#include "mock_renderable.h"
2626
27namespace testing27namespace mir {
28{28namespace scene {
2929
30struct MockSurface : public mir::scene::Surface30struct MockSurface : public mir::scene::Surface
31{31{
32 MockSurface() {}32 MockSurface() {}
3333
34 MOCK_CONST_METHOD0(name, std::string());34 MOCK_CONST_METHOD0(name, std::string());
35 MOCK_CONST_METHOD0(client_size, mir::geometry::Size());35 MOCK_CONST_METHOD0(client_size, geometry::Size());
36 MOCK_CONST_METHOD0(input_bounds, mir::geometry::Rectangle());36 MOCK_CONST_METHOD0(input_bounds, geometry::Rectangle());
37 MOCK_CONST_METHOD0(top_left, mir::geometry::Point());37 MOCK_CONST_METHOD0(top_left, geometry::Point());
38 MOCK_CONST_METHOD0(size, mir::geometry::Size());38 MOCK_CONST_METHOD0(size, geometry::Size());
3939
40 std::unique_ptr<mir::graphics::Renderable> compositor_snapshot(void const* /*compositor_id*/) const40 std::unique_ptr<graphics::Renderable> compositor_snapshot(void const* /*compositor_id*/) const
41 {41 {
42 return std::unique_ptr<mir::graphics::Renderable>(new MockRenderable);42 return std::unique_ptr<graphics::Renderable>(new graphics::MockRenderable);
43 }43 }
4444
45 MOCK_CONST_METHOD0(alpha, float());45 MOCK_CONST_METHOD0(alpha, float());
@@ -47,39 +47,40 @@
47 MOCK_CONST_METHOD0(state, MirSurfaceState());47 MOCK_CONST_METHOD0(state, MirSurfaceState());
48 MOCK_METHOD0(hide, void());48 MOCK_METHOD0(hide, void());
49 MOCK_METHOD0(show, void());49 MOCK_METHOD0(show, void());
50 MOCK_METHOD1(move_to, void(mir::geometry::Point const& top_left));50 MOCK_METHOD1(move_to, void(geometry::Point const& top_left));
51 MOCK_METHOD1(take_input_focus, void(std::shared_ptr<mir::shell::InputTargeter> const& targeter));51 MOCK_METHOD1(take_input_focus, void(std::shared_ptr<shell::InputTargeter> const& targeter));
52 MOCK_METHOD1(set_input_region, void(std::vector<mir::geometry::Rectangle> const& region));52 MOCK_METHOD1(set_input_region, void(std::vector<geometry::Rectangle> const& region));
53 MOCK_METHOD1(allow_framedropping, void(bool));53 MOCK_METHOD1(allow_framedropping, void(bool));
54 MOCK_METHOD1(resize, void(mir::geometry::Size const& size));54 MOCK_METHOD1(resize, void(geometry::Size const& size));
55 MOCK_METHOD1(set_transformation, void(glm::mat4 const& t));55 MOCK_METHOD1(set_transformation, void(glm::mat4 const& t));
56 MOCK_METHOD1(set_alpha, void(float alpha));56 MOCK_METHOD1(set_alpha, void(float alpha));
57 MOCK_METHOD1(set_orientation, void(MirOrientation orientation));57 MOCK_METHOD1(set_orientation, void(MirOrientation orientation));
58 MOCK_METHOD0(force_requests_to_complete, void());58 MOCK_METHOD0(force_requests_to_complete, void());
59 MOCK_METHOD1(set_cursor_image, void(std::shared_ptr<mir::graphics::CursorImage> const& image));59 MOCK_METHOD1(set_cursor_image, void(std::shared_ptr<graphics::CursorImage> const& image));
60 MOCK_CONST_METHOD0(cursor_image, std::shared_ptr<mir::graphics::CursorImage>());60 MOCK_CONST_METHOD0(cursor_image, std::shared_ptr<graphics::CursorImage>());
61 MOCK_METHOD1(add_observer, void(std::shared_ptr<mir::scene::SurfaceObserver> const& observer));61 MOCK_METHOD1(add_observer, void(std::shared_ptr<SurfaceObserver> const& observer));
62 MOCK_METHOD1(remove_observer, void(std::weak_ptr<mir::scene::SurfaceObserver> const& observer));62 MOCK_METHOD1(remove_observer, void(std::weak_ptr<SurfaceObserver> const& observer));
63 MOCK_CONST_METHOD0(input_channel, std::shared_ptr<mir::input::InputChannel>());63 MOCK_CONST_METHOD0(input_channel, std::shared_ptr<input::InputChannel>());
64 MOCK_METHOD1(set_reception_mode, void(mir::input::InputReceptionMode mode));64 MOCK_METHOD1(set_reception_mode, void(input::InputReceptionMode mode));
6565
66 // from mir::input::surface66 // from mir::input::surface
67 MOCK_CONST_METHOD1(input_area_contains, bool(mir::geometry::Point const& point));67 MOCK_CONST_METHOD1(input_area_contains, bool(geometry::Point const& point));
68 MOCK_CONST_METHOD0(reception_mode, mir::input::InputReceptionMode());68 MOCK_CONST_METHOD0(reception_mode, input::InputReceptionMode());
69 MOCK_METHOD1(consume, void(MirEvent const& event));69 MOCK_METHOD1(consume, void(MirEvent const& event));
7070
71 // from mir::frontend::surface71 // from mir::frontend::surface
72 MOCK_CONST_METHOD0(pixel_format, MirPixelFormat());72 MOCK_CONST_METHOD0(pixel_format, MirPixelFormat());
73 MOCK_METHOD2(swap_buffers, void(mir::graphics::Buffer* old_buffer, std::function<void(mir::graphics::Buffer* new_buffer)> complete));73 MOCK_METHOD2(swap_buffers, void(graphics::Buffer* old_buffer, std::function<void(graphics::Buffer* new_buffer)> complete));
74 MOCK_CONST_METHOD0(supports_input, bool());74 MOCK_CONST_METHOD0(supports_input, bool());
75 MOCK_CONST_METHOD0(client_input_fd, int());75 MOCK_CONST_METHOD0(client_input_fd, int());
76 MOCK_METHOD2(configure, int(MirSurfaceAttrib attrib, int value));76 MOCK_METHOD2(configure, int(MirSurfaceAttrib attrib, int value));
77 MOCK_METHOD1(query, int(MirSurfaceAttrib attrib));77 MOCK_METHOD1(query, int(MirSurfaceAttrib attrib));
7878
79 // from mir::scene::SurfaceBufferAccess79 // from mir::scene::SurfaceBufferAccess
80 MOCK_METHOD1(with_most_recent_buffer_do, void(std::function<void(mir::graphics::Buffer&)> const& exec));80 MOCK_METHOD1(with_most_recent_buffer_do, void(std::function<void(graphics::Buffer&)> const& exec));
81};81};
8282
83}83} // namespace scene
84} // namespace mir
8485
85#endif // MOCK_MIR_SCENE_SURFACE_H86#endif // MOCK_MIR_SCENE_SURFACE_H
8687
=== modified file 'tests/modules/common/qtmir_test.h'
--- tests/modules/common/qtmir_test.h 2014-08-28 23:36:42 +0000
+++ tests/modules/common/qtmir_test.h 2014-09-11 21:25:08 +0000
@@ -35,7 +35,7 @@
35#include "mock_oom_controller.h"35#include "mock_oom_controller.h"
36#include "mock_process_controller.h"36#include "mock_process_controller.h"
37#include "mock_proc_info.h"37#include "mock_proc_info.h"
38#include "mock_session.h"38#include "mock_mir_session.h"
39#include "mock_focus_controller.h"39#include "mock_focus_controller.h"
40#include "mock_prompt_session_manager.h"40#include "mock_prompt_session_manager.h"
41#include "mock_prompt_session.h"41#include "mock_prompt_session.h"
@@ -43,14 +43,13 @@
43namespace ms = mir::scene;43namespace ms = mir::scene;
44using namespace qtmir;44using namespace qtmir;
4545
46namespace testing46namespace qtmir {
47{
4847
49class QtMirTestConfiguration: public MirServerConfiguration48class FakeMirServerConfiguration: public MirServerConfiguration
50{49{
51 typedef NiceMock<testing::MockPromptSessionManager> StubPromptSessionManager;50 typedef testing::NiceMock<mir::scene::MockPromptSessionManager> StubPromptSessionManager;
52public:51public:
53 QtMirTestConfiguration()52 FakeMirServerConfiguration()
54 : MirServerConfiguration(0, nullptr)53 : MirServerConfiguration(0, nullptr)
55 , mock_prompt_session_manager(std::make_shared<StubPromptSessionManager>())54 , mock_prompt_session_manager(std::make_shared<StubPromptSessionManager>())
56 {55 {
@@ -73,6 +72,10 @@
73 std::shared_ptr<StubPromptSessionManager> mock_prompt_session_manager;72 std::shared_ptr<StubPromptSessionManager> mock_prompt_session_manager;
74};73};
7574
75} // namespace qtmir
76
77namespace testing {
78
76class QtMirTest : public ::testing::Test79class QtMirTest : public ::testing::Test
77{80{
78public:81public:
@@ -83,7 +86,7 @@
83 [](ProcessController::OomController*){})86 [](ProcessController::OomController*){})
84 }87 }
85 , mirConfig{88 , mirConfig{
86 QSharedPointer<QtMirTestConfiguration> (new QtMirTestConfiguration)89 QSharedPointer<FakeMirServerConfiguration> (new FakeMirServerConfiguration)
87 }90 }
88 , taskController{91 , taskController{
89 QSharedPointer<TaskController> (92 QSharedPointer<TaskController> (
@@ -141,7 +144,7 @@
141 applicationManager.authorizeSession(procId, authed);144 applicationManager.authorizeSession(procId, authed);
142 EXPECT_EQ(authed, true);145 EXPECT_EQ(authed, true);
143146
144 auto appSession = std::make_shared<MockSession>(appId.toStdString(), procId);147 auto appSession = std::make_shared<mir::scene::MockSession>(appId.toStdString(), procId);
145 sessionManager.onSessionStarting(appSession);148 sessionManager.onSessionStarting(appSession);
146 return application;149 return application;
147 return nullptr;150 return nullptr;
@@ -152,7 +155,7 @@
152 testing::NiceMock<testing::MockApplicationController> appController;155 testing::NiceMock<testing::MockApplicationController> appController;
153 testing::NiceMock<testing::MockProcInfo> procInfo;156 testing::NiceMock<testing::MockProcInfo> procInfo;
154 testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;157 testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;
155 QSharedPointer<QtMirTestConfiguration> mirConfig;158 QSharedPointer<FakeMirServerConfiguration> mirConfig;
156 QSharedPointer<TaskController> taskController;159 QSharedPointer<TaskController> taskController;
157 ApplicationManager applicationManager;160 ApplicationManager applicationManager;
158 SessionManager sessionManager;161 SessionManager sessionManager;
159162
=== modified file 'tests/modules/modules.pro'
--- tests/modules/modules.pro 2014-08-28 23:36:42 +0000
+++ tests/modules/modules.pro 2014-09-11 21:25:08 +0000
@@ -1,2 +1,2 @@
1TEMPLATE = subdirs1TEMPLATE = subdirs
2SUBDIRS = ApplicationManager General SessionManager TaskController2SUBDIRS = ApplicationManager General MirSurfaceItem SessionManager TaskController

Subscribers

People subscribed via source and target branches