@@ -17,6 +17,7 @@
1717// unity-api
1818#include <unity/shell/launcher/LauncherModelInterface.h>
1919#include <unity/shell/application/ApplicationInfoInterface.h>
20+#include <unity/shell/application/MirSurfaceListInterface.h>
2021
2122#include "launcheritem.h"
2223#include "launchermodel.h"
@@ -37,11 +38,74 @@
3738namespace unityapi = unity::shell::application;
3839
3940// This is a mock, specifically to test the LauncherModel
41+class MockSurface: public unity::shell::application::MirSurfaceInterface
42+{
43+ Q_OBJECT
44+public:
45+ MockSurface(const QString &id, const QString &appId, QObject* parent): unityapi::MirSurfaceInterface(parent), m_id(id), m_appId(appId) {}
46+ Mir::Type type() const override { return Mir::NormalType;}
47+ QString name() const override { return QStringLiteral("mock surface"); }
48+ QString persistentId() const override { return m_id; }
49+ QString appId() const override { return m_appId; }
50+ QPoint position() const override { return QPoint(); }
51+ QSize size() const override { return QSize(); }
52+ void resize(const QSize &size) override { Q_UNUSED(size) }
53+ void resize(int width, int height) override { Q_UNUSED(width); Q_UNUSED(height) }
54+ Mir::State state() const override { return Mir::RestoredState; }
55+ bool live() const override { return true; }
56+ bool visible() const override { return true; }
57+ Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
58+ void setOrientationAngle(Mir::OrientationAngle angle) override { Q_UNUSED(angle); }
59+ int minimumWidth() const override { return 0; }
60+ int minimumHeight() const override { return 0; }
61+ int maximumWidth() const override { return 0; }
62+ int maximumHeight() const override { return 0; }
63+ int widthIncrement() const override { return 0; }
64+ int heightIncrement() const override { return 0; }
65+ void setKeymap(const QString &) override {}
66+ Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
67+ QString keymap() const override { return QStringLiteral("de_DE"); }
68+ bool focused() const override { return true; }
69+ QRect inputBounds() const override { return QRect(); }
70+ bool confinesMousePointer() const override { return false; }
71+ QPoint requestedPosition() const override { return QPoint(); }
72+ void setRequestedPosition(const QPoint &) override {}
73+ MirSurfaceInterface* parentSurface() const override { return nullptr; }
74+ MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
75+ void close() override {}
76+ void activate() override {}
77+ void requestState(Mir::State) override {}
78+
79+private:
80+ QString m_id;
81+ QString m_appId;
82+};
83+
84+class MockSurfaceList: public unity::shell::application::MirSurfaceListInterface
85+{
86+ Q_OBJECT
87+public:
88+ MockSurfaceList(QObject *parent): unityapi::MirSurfaceListInterface(parent) {}
89+ int rowCount(const QModelIndex & = QModelIndex()) const override { return m_list.count(); }
90+ QVariant data(const QModelIndex &, int) const override { return QVariant(); }
91+ Q_INVOKABLE MirSurfaceInterface* get(int index) override { return m_list.at(index); }
92+ void append(MirSurfaceInterface* surface) {
93+ beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
94+ m_list.append(surface);
95+ endInsertRows();
96+ }
97+private:
98+ QList<MirSurfaceInterface*> m_list;
99+
100+};
101+
40102class MockApp: public unity::shell::application::ApplicationInfoInterface
41103{
42104 Q_OBJECT
43105public:
44− MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
106+ MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) {
107+ m_surfaces = new MockSurfaceList(this);
108+ }
45109
46110 RequestedState requestedState() const override { return RequestedRunning; }
47111 void setRequestedState(RequestedState) override {}
@@ -64,10 +128,10 @@ public:
64128 void setExemptFromLifecycle(bool) override {}
65129 QSize initialSurfaceSize() const override { return QSize(); }
66130 void setInitialSurfaceSize(const QSize &) override {}
67− MirSurfaceListInterface* surfaceList() const override { return nullptr; }
131+ MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
68132 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
69− int surfaceCount() const override { return m_surfaceCount; }
70− void setSurfaceCount(int count) { m_surfaceCount = count; Q_EMIT surfaceCountChanged(count); }
133+ int surfaceCount() const override { return m_surfaces->count(); }
134+ void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
71135 void close() override {}
72136
73137 // Methods used for mocking (not in the interface)
@@ -75,7 +139,7 @@ public:
75139private:
76140 QString m_appId;
77141 bool m_focused;
78− int m_surfaceCount = 0;
142+ MockSurfaceList *m_surfaces;
79143};
80144
81145// This is a mock, specifically to test the LauncherModel
@@ -748,8 +812,20 @@ private Q_SLOTS:
748812
749813 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
750814 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
751− app->setSurfaceCount(1);
815+ MockSurfaceList* surfaces = new MockSurfaceList(appManager);
816+ surfaces->append(new MockSurface("foobar", "foobar", surfaces));
817+ app->setSurfaces(surfaces);
752818 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
819+
820+ // Make sure the new surface appears in the quicklist
821+ QuickListModel *quickList = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
822+ bool found = false;
823+ for (int i = 0; i < quickList->rowCount(); ++i) {
824+ if (quickList->get(i).actionId() == "surface_foobar") {
825+ found = true;
826+ }
827+ }
828+ QCOMPARE(found, true);
753829 }
754830};
755831