@@ -1,5 +1,5 @@
2− * Copyright 2013-2016 Canonical Ltd.
2+ * Copyright 2013-2017 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -17,6 +17,7 @@
17// unity-api
17// unity-api
18#include <unity/shell/launcher/LauncherModelInterface.h>
18#include <unity/shell/launcher/LauncherModelInterface.h>
19#include <unity/shell/application/ApplicationInfoInterface.h>
19#include <unity/shell/application/ApplicationInfoInterface.h>
20+#include <unity/shell/application/MirSurfaceListInterface.h>
21#include "launcheritem.h"
22#include "launcheritem.h"
22#include "launchermodel.h"
23#include "launchermodel.h"
@@ -37,11 +38,76 @@
37namespace unityapi = unity::shell::application;
38namespace unityapi = unity::shell::application;
39// This is a mock, specifically to test the LauncherModel
40// This is a mock, specifically to test the LauncherModel
41+class MockSurface: public unity::shell::application::MirSurfaceInterface
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 {}
86+class MockSurfaceList: public unity::shell::application::MirSurfaceListInterface
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);
100+ QList<MirSurfaceInterface*> m_list;
40class MockApp: public unity::shell::application::ApplicationInfoInterface
104class MockApp: public unity::shell::application::ApplicationInfoInterface
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);
46 RequestedState requestedState() const override { return RequestedRunning; }
112 RequestedState requestedState() const override { return RequestedRunning; }
47 void setRequestedState(RequestedState) override {}
113 void setRequestedState(RequestedState) override {}
@@ -64,10 +130,10 @@ public:
64 void setExemptFromLifecycle(bool) override {}
130 void setExemptFromLifecycle(bool) override {}
65 QSize initialSurfaceSize() const override { return QSize(); }
131 QSize initialSurfaceSize() const override { return QSize(); }
66 void setInitialSurfaceSize(const QSize &) override {}
132 void setInitialSurfaceSize(const QSize &) override {}
67− MirSurfaceListInterface* surfaceList() const override { return nullptr; }
133+ MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
68 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
134 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
69− int surfaceCount() const override { return m_surfaceCount; }
135+ int surfaceCount() const override { return m_surfaces->count(); }
70− void setSurfaceCount(int count) { m_surfaceCount = count; Q_EMIT surfaceCountChanged(count); }
136+ void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
71 void close() override {}
137 void close() override {}
73 // Methods used for mocking (not in the interface)
139 // Methods used for mocking (not in the interface)
@@ -75,7 +141,7 @@ public:
76 QString m_appId;
142 QString m_appId;
77 bool m_focused;
143 bool m_focused;
78− int m_surfaceCount = 0;
144+ MockSurfaceList *m_surfaces;
81// This is a mock, specifically to test the LauncherModel
147// This is a mock, specifically to test the LauncherModel
@@ -748,8 +814,20 @@ private Q_SLOTS:
749 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
815 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
750 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
816 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);
752 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
820 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
822+ // Make sure the new surface appears in the quicklist
823+ QuickListModel *quickList = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
825+ for (int i = 0; i < quickList->rowCount(); ++i) {
826+ if (quickList->get(i).actionId() == "surface_foobar") {
830+ QCOMPARE(found, true);