on db503ee help sign in
unity8/tests/plugins/WindowManager/UnityApplicationMocks.h
211 lines 7.3 kB history raw
1/*
2 * Copyright (C) 2017 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#ifndef UNITYAPPLICATIONMOCKS_H
18#define UNITYAPPLICATIONMOCKS_H
20#include <unity/shell/application/ApplicationInfoInterface.h>
21#include <unity/shell/application/ApplicationManagerInterface.h>
22#include <unity/shell/application/MirSurfaceInterface.h>
23#include <unity/shell/application/SurfaceManagerInterface.h>
25// from tests/mocks
26#include <Unity/Application/MirSurfaceListModel.h>
28using namespace unity::shell::application;
30class MirSurface : public MirSurfaceInterface
32 Q_OBJECT
33public:
34 Mir::Type type() const override { return m_type; }
35 QString name() const override { return QString("foo"); }
36 QString persistentId() const override { return QString("a-b-c-my-id"); }
37 QString appId() const override { return QString(); }
38 QPoint position() const override { return QPoint(); }
39 QSize size() const override { return QSize(); }
40 void resize(int, int) override {}
41 void resize(const QSize &) override {}
42 Mir::State state() const override { return m_state; }
43 bool live() const override { return m_live; }
44 bool visible() const override { return true; }
45 Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
46 void setOrientationAngle(Mir::OrientationAngle) override {}
48 int minimumWidth() const override { return 0; }
49 int minimumHeight() const override { return 0; }
50 int maximumWidth() const override { return 0; }
51 int maximumHeight() const override { return 0; }
52 int widthIncrement() const override { return 0; }
53 int heightIncrement() const override { return 0; }
55 void setKeymap(const QString &) override {}
56 QString keymap() const override { return QString(); }
57 Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
58 bool focused() const override { return true; }
59 QRect inputBounds() const override { return QRect(); }
60 bool confinesMousePointer() const override { return false; }
61 bool allowClientResize() const override { return true; }
62 void setAllowClientResize(bool) override {}
63 QPoint requestedPosition() const override { return QPoint(); }
64 void setRequestedPosition(const QPoint &) override {}
65 MirSurfaceInterface* parentSurface() const override { return nullptr; }
66 unity::shell::application::MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
67 void close() override {}
68 void forceClose() override {}
69 void activate() override {}
71public Q_SLOTS:
72 void requestState(Mir::State value) override
73 {
74 if (m_state != value) {
75 m_state = value;
76 Q_EMIT stateChanged(m_state);
77 }
78 }
80public:
81 Mir::Type m_type { Mir::NormalType };
82 Mir::State m_state { Mir::RestoredState };
83 bool m_live { true };
84};
86class SurfaceManager : public SurfaceManagerInterface
88 Q_OBJECT
90public:
91 void raise(MirSurfaceInterface *) override {}
92 void activate(MirSurfaceInterface *) override {}
93};
95class Application : public ApplicationInfoInterface
97 Q_OBJECT
98public:
99 Application(QString appId)
100 : ApplicationInfoInterface(appId, nullptr)
101 , m_appId(std::move(appId))
102 , m_state(Starting)
103 , m_requestedState(RequestedRunning)
104 {
106 }
108 void close() override {}
109 QString appId() const override { return m_appId;}
110 QString name() const override { return "foo"; }
111 QString comment() const override { return "bar"; }
112 QUrl icon() const override { return QUrl(); }
113 State state() const override { return m_state; }
114 RequestedState requestedState() const override { return m_requestedState; }
115 void setRequestedState(RequestedState value) override
116 {
117 if (value != m_requestedState) {
118 m_requestedState = value;
119 Q_EMIT requestedStateChanged(value);
120 }
121 }
122 bool focused() const override { return false; }
123 QString splashTitle() const override { return QString(); }
124 QUrl splashImage() const override { return QUrl(); }
125 bool splashShowHeader() const override { return false; }
126 QColor splashColor() const override { return QColor(); }
127 QColor splashColorHeader() const override { return QColor(); }
128 QColor splashColorFooter() const override { return QColor(); }
129 Qt::ScreenOrientations supportedOrientations() const override { return Qt::LandscapeOrientation; }
130 bool rotatesWindowContents() const override { return false; }
131 bool isTouchApp() const override { return false; }
132 bool exemptFromLifecycle() const override { return false; }
133 void setExemptFromLifecycle(bool) override {}
134 QSize initialSurfaceSize() const override { return QSize(); }
135 void setInitialSurfaceSize(const QSize &) override {}
136 MirSurfaceListInterface* surfaceList() const override { return &m_surfaceList; }
137 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
138 int surfaceCount() const override { return 0; }
140 QString m_appId;
141 State m_state;
142 RequestedState m_requestedState;
143 mutable MirSurfaceListModel m_surfaceList;
144};
146class ApplicationManager : public ApplicationManagerInterface
148 Q_OBJECT
150public:
152 int rowCount(const QModelIndex &) const override
153 {
154 return m_applications.count();
155 }
157 QVariant data(const QModelIndex &/*index*/, int /*role*/) const override
158 {
159 return QVariant();
160 }
162 QString focusedApplicationId() const override {return QString();}
164 ApplicationInfoInterface *get(int index) const override
165 {
166 return m_applications[index];
167 }
169 ApplicationInfoInterface *findApplication(const QString &appId) const override
170 {
171 Q_UNUSED(appId);
172 return nullptr;
173 }
175 ApplicationInfoInterface *findApplicationWithSurface(MirSurfaceInterface* surface) const override
176 {
177 for (int i = 0; i < m_applications.count(); ++i) {
178 if (m_applications[i]->m_surfaceList.contains(surface)) {
179 return m_applications[i];
180 }
181 }
182 return nullptr;
183 }
185 bool requestFocusApplication(const QString &appId) override
186 {
187 Q_UNUSED(appId);
188 return false;
189 }
191 ApplicationInfoInterface *startApplication(const QString &appId, const QStringList &/*arguments*/) override
192 {
193 Application *application = new Application(appId);
194 prepend(application);
195 return application;
196 }
198 bool stopApplication(const QString &) override { return true; }
200private:
201 void prepend(Application *application)
202 {
203 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
204 m_applications.append(application);
205 endInsertRows();
206 }
208 QList<Application*> m_applications;
209};
211#endif // UNITYAPPLICATIONMOCKS_H