on 3ecd374 help sign in
unity8/tests/mocks/Unity/Application/ApplicationTestInterface.cpp
134 lines 5.0 kB history raw
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 */
17#include "ApplicationInfo.h"
18#include "ApplicationTestInterface.h"
19#include "ApplicationManager.h"
20#include "SessionManager.h"
21#include "SurfaceManager.h"
22#include "Session.h"
23#include "MirSurfaceItem.h"
25#include <paths.h>
27quint32 nextId = 0;
29ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
30 : QDBusAbstractAdaptor(parent)
32 QDBusConnection connection = QDBusConnection::sessionBus();
33 connection.registerService("com.canonical.Unity8");
34 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
37quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
39 qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
41 ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
42 if (!application) {
43 qDebug() << "ApplicationTestInterface::addChildSession - No application found for " << appId;
44 return 0;
45 }
47 Session* parentSession = nullptr;
48 if (m_childSessions.contains(existingSessionId)) {
49 parentSession = m_childSessions[existingSessionId];
50 } else if (application->session()) {
51 parentSession = application->session();
52 } else {
53 qDebug() << "ApplicationTestInterface::addChildSession - No session for " << appId << ":" << existingSessionId;
54 return 0;
55 }
57 QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
58 .arg(qmlDirectory())
59 .arg(surfaceImage);
61 quint32 sessionId = ++nextId;
62 Session* session = SessionManager::singleton()->createSession(
63 QString("%1-Child%2").arg(parentSession->name())
64 .arg(sessionId),
65 screenshotUrl);
66 parentSession->addChildSession(session);
67 session->createSurface();
68 m_childSessions[sessionId] = session;
70 return sessionId;
73void ApplicationTestInterface::removeSession(quint32 sessionId)
75 qDebug() << "ApplicationTestInterface::removeSession - " << sessionId;
77 if (!m_childSessions.contains(sessionId)) {
78 qDebug() << "ApplicationTestInterface::removeSession - No added session for " << sessionId;
79 return;
80 }
81 Session* session = m_childSessions.take(sessionId);
82 Q_EMIT session->removed();
85quint32 ApplicationTestInterface::addChildSurface(const QString& appId, quint32 existingSessionId, quint32 existingSurfaceId, const QString& surfaceImage)
87 qDebug() << "ApplicationTestInterface::addChildSurface to " << appId;
89 ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
90 if (!application) {
91 qDebug() << "ApplicationTestInterface::addChildSurface - No application found for " << appId;
92 return 0;
93 }
95 MirSurfaceItem* parentSurface = nullptr;
96 if (m_childSessions.contains(existingSessionId) && m_childSessions[existingSessionId]->surface()) {
97 parentSurface = m_childSessions[existingSessionId]->surface();
98 } else if (m_childSurfaces.contains(existingSurfaceId)) {
99 parentSurface = m_childSurfaces[existingSurfaceId];
100 } else if (application->session() && application->session()->surface()) {
101 parentSurface = application->session()->surface();
102 } else {
103 qDebug() << "ApplicationTestInterface::addChildSurface - No surface for " << appId << ":" << existingSurfaceId;
104 return 0;
105 }
107 QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
108 .arg(qmlDirectory())
109 .arg(surfaceImage);
111 quint32 surfaceId = ++nextId;
112 MirSurfaceItem* surface = SurfaceManager::singleton()->createSurface(
113 QString("%1-Child%2").arg(parentSurface->name())
114 .arg(surfaceId),
115 MirSurfaceItem::Normal,
116 MirSurfaceItem::Maximized,
117 screenshotUrl);
118 parentSurface->addChildSurface(surface);
119 m_childSurfaces[surfaceId] = surface;
121 return surfaceId;
124void ApplicationTestInterface::removeSurface(quint32 surfaceId)
126 qDebug() << "ApplicationTestInterface::removeSurface - " << surfaceId;
128 if (!m_childSurfaces.contains(surfaceId)) {
129 qDebug() << "ApplicationTestInterface::removeSurface - No added surface for " << surfaceId;
130 return;
131 }
132 MirSurfaceItem* surface = m_childSurfaces.take(surfaceId);
133 Q_EMIT surface->removed();