@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013-2016 Canonical Ltd.
2+ * Copyright 2013-2017 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -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,76 @@
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+ bool allowClientResize() const override { return true; }
72+ void setAllowClientResize(bool) override {}
73+ QPoint requestedPosition() const override { return QPoint(); }
74+ void setRequestedPosition(const QPoint &) override {}
75+ MirSurfaceInterface* parentSurface() const override { return nullptr; }
76+ MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
77+ void close() override {}
78+ void activate() override {}
79+ void requestState(Mir::State) override {}
80+
81+private:
82+ QString m_id;
83+ QString m_appId;
84+};
85+
86+class MockSurfaceList: public unity::shell::application::MirSurfaceListInterface
87+{
88+ Q_OBJECT
89+public:
90+ MockSurfaceList(QObject *parent): unityapi::MirSurfaceListInterface(parent) {}
91+ int rowCount(const QModelIndex & = QModelIndex()) const override { return m_list.count(); }
92+ QVariant data(const QModelIndex &, int) const override { return QVariant(); }
93+ Q_INVOKABLE MirSurfaceInterface* get(int index) override { return m_list.at(index); }
94+ void append(MirSurfaceInterface* surface) {
95+ beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
96+ m_list.append(surface);
97+ endInsertRows();
98+ }
99+private:
100+ QList<MirSurfaceInterface*> m_list;
101+
102+};
103+
40104class MockApp: public unity::shell::application::ApplicationInfoInterface
41105{
42106 Q_OBJECT
43107public:
44− MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
108+ MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) {
109+ m_surfaces = new MockSurfaceList(this);
110+ }
45111
46112 RequestedState requestedState() const override { return RequestedRunning; }
47113 void setRequestedState(RequestedState) override {}
@@ -64,10 +130,10 @@ public:
64130 void setExemptFromLifecycle(bool) override {}
65131 QSize initialSurfaceSize() const override { return QSize(); }
66132 void setInitialSurfaceSize(const QSize &) override {}
67− MirSurfaceListInterface* surfaceList() const override { return nullptr; }
133+ MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
68134 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); }
135+ int surfaceCount() const override { return m_surfaces->count(); }
136+ void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
71137 void close() override {}
72138
73139 // Methods used for mocking (not in the interface)
@@ -75,7 +141,7 @@ public:
75141private:
76142 QString m_appId;
77143 bool m_focused;
78− int m_surfaceCount = 0;
144+ MockSurfaceList *m_surfaces;
79145};
80146
81147// This is a mock, specifically to test the LauncherModel
@@ -748,8 +814,20 @@ private Q_SLOTS:
748814
749815 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
750816 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
751− app->setSurfaceCount(1);
817+ MockSurfaceList* surfaces = new MockSurfaceList(appManager);
818+ surfaces->append(new MockSurface("foobar", "foobar", surfaces));
819+ app->setSurfaces(surfaces);
752820 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
821+
822+ // Make sure the new surface appears in the quicklist
823+ QuickListModel *quickList = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
824+ bool found = false;
825+ for (int i = 0; i < quickList->rowCount(); ++i) {
826+ if (quickList->get(i).actionId() == "surface_foobar") {
827+ found = true;
828+ }
829+ }
830+ QCOMPARE(found, true);
753831 }
754832};
755833