on xenial help sign in
adjust tests and added some more
4cb1dd6Michael Zanetti
tests/plugins/Unity/Launcher/CMakeLists.txt+2
@@ -45,6 +45,8 @@ add_executable(launchermodeltestExec
45 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
45 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
46 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
46 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
47 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
47 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
48+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
49+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
48 )
50 )
49target_link_libraries(launchermodeltestExec ${GSETTINGS_QT_LDFLAGS} )
51target_link_libraries(launchermodeltestExec ${GSETTINGS_QT_LDFLAGS} )
50qt5_use_modules(launchermodeltestExec Test Core DBus)
52qt5_use_modules(launchermodeltestExec Test Core DBus)
tests/plugins/Unity/Launcher/launchermodeltest.cpp+87−21
@@ -19,39 +19,107 @@
19
19
20// unity-api
20// unity-api
21#include <unity/shell/launcher/LauncherModelInterface.h>
21#include <unity/shell/launcher/LauncherModelInterface.h>
22+#include <unity/shell/application/ApplicationInfoInterface.h>
22
23
23#include "launcheritem.h"
24#include "launcheritem.h"
24#include "launchermodel.h"
25#include "launchermodel.h"
25
26
26#include <QtTest>
27#include <QtTest>
27
28
29+class MockApp: public unity::shell::application::ApplicationInfoInterface
30+{
31+ Q_OBJECT
32+public:
33+ MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
34+ QString appId() const { return m_appId; }
35+ QString name() const { return "mock"; }
36+ QString comment() const { return "this is a mock"; }
37+ QUrl icon() const { return QUrl(); }
38+ ApplicationInfoInterface::Stage stage() const { return ApplicationInfoInterface::MainStage; }
39+ ApplicationInfoInterface::State state() const { return ApplicationInfoInterface::Running; }
40+ bool focused() const { return m_focused; }
41+
42+ // Methods used for mocking (not in the interface)
43+ void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
44+private:
45+ QString m_appId;
46+ bool m_focused;
47+};
48+
49+class MockAppManager: public unity::shell::application::ApplicationManagerInterface
50+{
51+ Q_OBJECT
52+public:
53+ MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
54+ int rowCount(const QModelIndex &) const { return m_list.count(); }
55+ QVariant data(const QModelIndex &, int ) const { return QVariant(); }
56+ QString focusedApplicationId() const {
57+ Q_FOREACH(MockApp *app, m_list) {
58+ if (app->focused()) return app->appId();
59+ }
60+ return QString();
61+ }
62+ unity::shell::application::ApplicationInfoInterface *get(int index) const { return m_list.at(index); }
63+ unity::shell::application::ApplicationInfoInterface *findApplication(const QString &) const { return nullptr; }
64+ unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) { return nullptr; }
65+ bool stopApplication(const QString &) { return false; }
66+ bool focusApplication(const QString &appId) {
67+ Q_FOREACH(MockApp* app, m_list) {
68+ app->setFocused(app->appId() == appId);
69+ }
70+ Q_EMIT focusedApplicationIdChanged();
71+ return true;
72+ }
73+
74+ void unfocusCurrentApplication() { }
75+
76+ void addApplication(MockApp *app) {
77+ beginInsertRows(QModelIndex(), count(), count());
78+ m_list.append(app);
79+ endInsertRows();
80+ }
81+ void removeApplication(int index) {
82+ beginRemoveRows(QModelIndex(), index, index);
83+ m_list.takeAt(index)->deleteLater();
84+ endRemoveRows();
85+ }
86+
87+private:
88+ QList<MockApp*> m_list;
89+};
90+
28class LauncherModelTest : public QObject
91class LauncherModelTest : public QObject
29{
92{
30 Q_OBJECT
93 Q_OBJECT
31
94
32private:
95private:
33 LauncherModel *launcherModel;
96 LauncherModel *launcherModel;
97+ MockAppManager *appManager;
34
98
35private Q_SLOTS:
99private Q_SLOTS:
36
100
37 void initTestCase() {
101 void initTestCase() {
38 launcherModel = new LauncherModel(this);
102 launcherModel = new LauncherModel(this);
39 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
103 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
104+
105+ appManager = new MockAppManager(this);
106+ launcherModel->setApplicationManager(appManager);
40 }
107 }
41
108
109+ // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
42 void init() {
110 void init() {
43−/* qDebug() << "init";
111+ appManager->addApplication(new MockApp("abs-icon"));
44− launcherModel->applicationFocused("abs-icon");
45 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
112 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
46
113
47− launcherModel->applicationFocused("no-icon.desktop");
114+ appManager->addApplication(new MockApp("no-icon"));
48 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
115 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
49−
50− launcherModel->applicationFocused(QString());
51− */
52 }
116 }
53
117
118+ // Removing apps from appmanager and launcher as pinned ones would stick
54 void cleanup() {
119 void cleanup() {
120+ while (appManager->count() > 0) {
121+ appManager->removeApplication(0);
122+ }
55 while (launcherModel->rowCount(QModelIndex()) > 0) {
123 while (launcherModel->rowCount(QModelIndex()) > 0) {
56 launcherModel->requestRemove(launcherModel->get(0)->appId());
124 launcherModel->requestRemove(launcherModel->get(0)->appId());
57 }
125 }
@@ -115,32 +183,30 @@ private Q_SLOTS:
115 }
183 }
116
184
117 void testApplicationFocused() {
185 void testApplicationFocused() {
118−/* // all apps unfocused at beginning...
186+ // all apps unfocused at beginning...
119 QCOMPARE(launcherModel->get(0)->focused(), false);
187 QCOMPARE(launcherModel->get(0)->focused(), false);
120 QCOMPARE(launcherModel->get(1)->focused(), false);
188 QCOMPARE(launcherModel->get(1)->focused(), false);
121
189
122− launcherModel->applicationFocused("abs-icon");
190+ appManager->focusApplication("abs-icon");
123 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
191 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
124 QCOMPARE(launcherModel->get(0)->focused(), true);
192 QCOMPARE(launcherModel->get(0)->focused(), true);
125 QCOMPARE(launcherModel->get(1)->focused(), false);
193 QCOMPARE(launcherModel->get(1)->focused(), false);
126
194
127− launcherModel->applicationFocused("no-icon");
195+ appManager->focusApplication("no-icon");
128 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
196 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
129 QCOMPARE(launcherModel->get(0)->focused(), false);
197 QCOMPARE(launcherModel->get(0)->focused(), false);
130 QCOMPARE(launcherModel->get(1)->focused(), true);
198 QCOMPARE(launcherModel->get(1)->focused(), true);
199+ }
131
200
201+ void testClosingApps() {
202+ // At the start there are 2 items. Let's pin one.
132− launcherModel->applicationFocused("rel-icon");
203+ launcherModel->pin("abs-icon");
133− QCOMPARE(launcherModel->rowCount(QModelIndex()), 3);
204+ while (appManager->count() > 0) {
134− QCOMPARE(launcherModel->get(0)->focused(), false);
205+ appManager->removeApplication(0);
135− QCOMPARE(launcherModel->get(1)->focused(), false);
206+ }
136− QCOMPARE(launcherModel->get(2)->focused(), true);
207+ // The pinned one needs to stay, the other needs to disappear
137−
138− launcherModel->applicationFocused(QString());
139− QCOMPARE(launcherModel->rowCount(QModelIndex()), 3);
208+ QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
140− QCOMPARE(launcherModel->get(0)->focused(), false);
209+ QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
141− QCOMPARE(launcherModel->get(1)->focused(), false);
142− QCOMPARE(launcherModel->get(2)->focused(), false);
143− */
144 }
210 }
145};
211};
146
212