@@ -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,72 @@
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, QObject* parent): unityapi::MirSurfaceInterface(parent), m_id(id) {}
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+ QPoint position() const override { return QPoint(); }
50+ QSize size() const override { return QSize(); }
51+ void resize(const QSize &size) override { Q_UNUSED(size) }
52+ void resize(int width, int height) override { Q_UNUSED(width); Q_UNUSED(height) }
53+ Mir::State state() const override { return Mir::RestoredState; }
54+ bool live() const override { return true; }
55+ bool visible() const override { return true; }
56+ Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
57+ void setOrientationAngle(Mir::OrientationAngle angle) override { Q_UNUSED(angle); }
58+ int minimumWidth() const override { return 0; }
59+ int minimumHeight() const override { return 0; }
60+ int maximumWidth() const override { return 0; }
61+ int maximumHeight() const override { return 0; }
62+ int widthIncrement() const override { return 0; }
63+ int heightIncrement() const override { return 0; }
64+ void setKeymap(const QString &) override {}
65+ Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
66+ QString keymap() const override { return QStringLiteral("de_DE"); }
67+ bool focused() const override { return true; }
68+ QRect inputBounds() const override { return QRect(); }
69+ bool confinesMousePointer() const override { return false; }
70+ QPoint requestedPosition() const override { return QPoint(); }
71+ void setRequestedPosition(const QPoint &) override {}
72+ MirSurfaceInterface* parentSurface() const override { return nullptr; }
73+ MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
74+ void close() override {}
75+ void activate() override {}
76+ void requestState(Mir::State) override {}
77+
78+private:
79+ QString m_id;
80+};
81+
82+class MockSurfaceList: public unity::shell::application::MirSurfaceListInterface
83+{
84+ Q_OBJECT
85+public:
86+ MockSurfaceList(QObject *parent): unityapi::MirSurfaceListInterface(parent) {}
87+ int rowCount(const QModelIndex & = QModelIndex()) const override { return m_list.count(); }
88+ QVariant data(const QModelIndex &, int) const override { return QVariant(); }
89+ Q_INVOKABLE MirSurfaceInterface* get(int index) override { return m_list.at(index); }
90+ void append(MirSurfaceInterface* surface) {
91+ beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
92+ m_list.append(surface);
93+ endInsertRows();
94+ }
95+private:
96+ QList<MirSurfaceInterface*> m_list;
97+
98+};
99+
40100class MockApp: public unity::shell::application::ApplicationInfoInterface
41101{
42102 Q_OBJECT
43103public:
44− MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
104+ MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) {
105+ m_surfaces = new MockSurfaceList(this);
106+ }
45107
46108 RequestedState requestedState() const override { return RequestedRunning; }
47109 void setRequestedState(RequestedState) override {}
@@ -64,10 +126,10 @@ public:
64126 void setExemptFromLifecycle(bool) override {}
65127 QSize initialSurfaceSize() const override { return QSize(); }
66128 void setInitialSurfaceSize(const QSize &) override {}
67− MirSurfaceListInterface* surfaceList() const override { return nullptr; }
129+ MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
68130 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); }
131+ int surfaceCount() const override { return m_surfaces->count(); }
132+ void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
71133 void close() override {}
72134
73135 // Methods used for mocking (not in the interface)
@@ -75,7 +137,7 @@ public:
75137private:
76138 QString m_appId;
77139 bool m_focused;
78− int m_surfaceCount = 0;
140+ MockSurfaceList *m_surfaces;
79141};
80142
81143// This is a mock, specifically to test the LauncherModel
@@ -748,8 +810,20 @@ private Q_SLOTS:
748810
749811 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
750812 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
751− app->setSurfaceCount(1);
813+ MockSurfaceList* surfaces = new MockSurfaceList(appManager);
814+ surfaces->append(new MockSurface("foobar", surfaces));
815+ app->setSurfaces(surfaces);
752816 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
817+
818+ // Make sure the new surface appears in the quicklist
819+ QuickListModel *quickList = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
820+ bool found = false;
821+ for (int i = 0; i < quickList->rowCount(); ++i) {
822+ if (quickList->get(i).actionId() == "surface_foobar") {
823+ found = true;
824+ }
825+ }
826+ QCOMPARE(found, true);
753827 }
754828};
755829