on de450aa help sign in
unity8/tests/plugins/WindowManager/UnityApplicationMocks.h
235 lines 8.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>
28#include "wmpolicyinterface.h"
30using namespace unity::shell::application;
32class MirSurface : public MirSurfaceInterface
34 Q_OBJECT
35public:
36 Mir::Type type() const override { return m_type; }
37 QString name() const override { return QString("foo"); }
38 QString persistentId() const override { return QString("a-b-c-my-id"); }
39 QString appId() const override { return QString(); }
40 QPoint position() const override { return QPoint(); }
41 QSize size() const override { return QSize(); }
42 void resize(int, int) override {}
43 void resize(const QSize &) override {}
44 Mir::State state() const override { return m_state; }
45 bool live() const override { return m_live; }
46 bool visible() const override { return true; }
47 Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
48 void setOrientationAngle(Mir::OrientationAngle) override {}
50 int minimumWidth() const override { return 0; }
51 int minimumHeight() const override { return 0; }
52 int maximumWidth() const override { return 0; }
53 int maximumHeight() const override { return 0; }
54 int widthIncrement() const override { return 0; }
55 int heightIncrement() const override { return 0; }
57 void setKeymap(const QString &) override {}
58 QString keymap() const override { return QString(); }
59 Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
60 bool focused() const override { return true; }
61 QRect inputBounds() const override { return QRect(); }
62 bool confinesMousePointer() const override { return false; }
63 bool allowClientResize() const override { return true; }
64 void setAllowClientResize(bool) override {}
65 QPoint requestedPosition() const override { return QPoint(); }
66 void setRequestedPosition(const QPoint &) override {}
67 MirSurfaceInterface* parentSurface() const override { return nullptr; }
68 unity::shell::application::MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
69 void close() override {}
70 void activate() override {}
72public Q_SLOTS:
73 void requestState(Mir::State value) override
74 {
75 if (m_state != value) {
76 m_state = value;
77 Q_EMIT stateChanged(m_state);
78 }
79 }
81public:
82 Mir::Type m_type { Mir::NormalType };
83 Mir::State m_state { Mir::RestoredState };
84 bool m_live { true };
85};
87class SurfaceManager : public SurfaceManagerInterface
89 Q_OBJECT
91public:
92 void forEachSurfaceInWorkspace(const std::shared_ptr<miral::Workspace>&,
93 const std::function<void(unity::shell::application::MirSurfaceInterface*)>&) override {}
94 void moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface*,
95 const std::shared_ptr<miral::Workspace>&) override {}
96 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>&,
97 const std::shared_ptr<miral::Workspace>&) override {}
99 void raise(MirSurfaceInterface *) override {}
100 void activate(MirSurfaceInterface *) override {}
101};
103class Application : public ApplicationInfoInterface
105 Q_OBJECT
106public:
107 Application(QString appId)
108 : ApplicationInfoInterface(appId, nullptr)
109 , m_appId(std::move(appId))
110 , m_state(Starting)
111 , m_requestedState(RequestedRunning)
112 {
114 }
116 void close() override {}
117 QString appId() const override { return m_appId;}
118 QString name() const override { return "foo"; }
119 QString comment() const override { return "bar"; }
120 QUrl icon() const override { return QUrl(); }
121 State state() const override { return m_state; }
122 RequestedState requestedState() const override { return m_requestedState; }
123 void setRequestedState(RequestedState value) override
124 {
125 if (value != m_requestedState) {
126 m_requestedState = value;
127 Q_EMIT requestedStateChanged(value);
128 }
129 }
130 bool focused() const override { return false; }
131 QString splashTitle() const override { return QString(); }
132 QUrl splashImage() const override { return QUrl(); }
133 bool splashShowHeader() const override { return false; }
134 QColor splashColor() const override { return QColor(); }
135 QColor splashColorHeader() const override { return QColor(); }
136 QColor splashColorFooter() const override { return QColor(); }
137 Qt::ScreenOrientations supportedOrientations() const override { return Qt::LandscapeOrientation; }
138 bool rotatesWindowContents() const override { return false; }
139 bool isTouchApp() const override { return false; }
140 bool exemptFromLifecycle() const override { return false; }
141 void setExemptFromLifecycle(bool) override {}
142 QSize initialSurfaceSize() const override { return QSize(); }
143 void setInitialSurfaceSize(const QSize &) override {}
144 MirSurfaceListInterface* surfaceList() const override { return &m_surfaceList; }
145 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
146 int surfaceCount() const override { return 0; }
148 QString m_appId;
149 State m_state;
150 RequestedState m_requestedState;
151 mutable MirSurfaceListModel m_surfaceList;
152};
154class ApplicationManager : public ApplicationManagerInterface
156 Q_OBJECT
158public:
160 int rowCount(const QModelIndex &) const override
161 {
162 return m_applications.count();
163 }
165 QVariant data(const QModelIndex &/*index*/, int /*role*/) const override
166 {
167 return QVariant();
168 }
170 QString focusedApplicationId() const override {return QString();}
172 ApplicationInfoInterface *get(int index) const override
173 {
174 return m_applications[index];
175 }
177 ApplicationInfoInterface *findApplication(const QString &appId) const override
178 {
179 Q_UNUSED(appId);
180 return nullptr;
181 }
183 ApplicationInfoInterface *findApplicationWithSurface(MirSurfaceInterface* surface) const override
184 {
185 for (int i = 0; i < m_applications.count(); ++i) {
186 if (m_applications[i]->m_surfaceList.contains(surface)) {
187 return m_applications[i];
188 }
189 }
190 return nullptr;
191 }
193 bool requestFocusApplication(const QString &appId) override
194 {
195 Q_UNUSED(appId);
196 return false;
197 }
199 ApplicationInfoInterface *startApplication(const QString &appId, const QStringList &/*arguments*/) override
200 {
201 Application *application = new Application(appId);
202 prepend(application);
203 return application;
204 }
206 bool stopApplication(const QString &) override { return true; }
208private:
209 void prepend(Application *application)
210 {
211 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
212 m_applications.append(application);
213 endInsertRows();
214 }
216 QList<Application*> m_applications;
217};
219namespace miral {
220class Workspace {};
223class WindowManagementPolicy : public WMPolicyInterface
225public:
226 WindowManagementPolicy() {}
228 std::shared_ptr<miral::Workspace> createWorkspace() override { return std::make_shared<miral::Workspace>(); }
230 void releaseWorkspace(const std::shared_ptr<miral::Workspace>&) override {}
232 void setActiveWorkspace(const std::shared_ptr<miral::Workspace>&) override {}
233};
235#endif // UNITYAPPLICATIONMOCKS_H