2 * Copyright 2013-2017 Canonical Ltd.
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
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include <unity/shell/launcher/LauncherModelInterface.h>
19#include <unity/shell/application/ApplicationInfoInterface.h>
20#include <unity/shell/application/MirSurfaceListInterface.h>
22#include "launcheritem.h"
23#include "launchermodel.h"
24#include "dbusinterface.h"
27#include "AccountsServiceDBusAdaptor.h"
30#include <QDBusInterface>
32#include <QDBusMetaType>
33#include <QDomDocument>
38namespace unityapi = unity::shell::application;
40// This is a mock, specifically to test the LauncherModel
41class 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 {}
86class 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;
104class MockApp: public unity::shell::application::ApplicationInfoInterface
108 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) {
109 m_surfaces = new MockSurfaceList(this);
112 RequestedState requestedState() const override { return RequestedRunning; }
113 void setRequestedState(RequestedState) override {}
114 QString appId() const override { return m_appId; }
115 QString name() const override { return "mock"; }
116 QString comment() const override { return "this is a mock"; }
117 QUrl icon() const override { return QUrl(); }
118 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
119 bool focused() const override { return m_focused; }
120 QString splashTitle() const override { return QString(); }
121 QUrl splashImage() const override { return QUrl(); }
122 bool splashShowHeader() const override { return true; }
123 QColor splashColor() const override { return QColor(0,0,0,0); }
124 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
125 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
126 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
127 bool rotatesWindowContents() const override { return false; }
128 bool isTouchApp() const override { return true; }
129 bool exemptFromLifecycle() const override { return false; }
130 void setExemptFromLifecycle(bool) override {}
131 QSize initialSurfaceSize() const override { return QSize(); }
132 void setInitialSurfaceSize(const QSize &) override {}
133 MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
134 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
135 int surfaceCount() const override { return m_surfaces->count(); }
136 void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
137 void close() override {}
139 // Methods used for mocking (not in the interface)
140 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
144 MockSurfaceList *m_surfaces;
147// This is a mock, specifically to test the LauncherModel
148class MockAppManager: public unity::shell::application::ApplicationManagerInterface
152 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
154 int rowCount(const QModelIndex &) const override { return m_list.count(); }
155 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
156 QString focusedApplicationId() const override {
157 Q_FOREACH(MockApp *app, m_list) {
158 if (app->focused()) return app->appId();
162 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
163 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
164 Q_FOREACH(MockApp* app, m_list) {
165 if (app->appId() == appId) {
171 unityapi::ApplicationInfoInterface *findApplicationWithSurface(unityapi::MirSurfaceInterface* /*surface*/) const override {
174 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
175 bool stopApplication(const QString &appId) override {
176 Q_FOREACH(MockApp* app, m_list) {
177 if (app->appId() == appId) {
178 removeApplication(m_list.indexOf(app));
184 bool focusApplication(const QString &appId) {
185 Q_FOREACH(MockApp* app, m_list) {
186 app->setFocused(app->appId() == appId);
188 Q_EMIT focusedApplicationIdChanged();
192 void addApplication(MockApp *app) {
193 beginInsertRows(QModelIndex(), count(), count());
197 void removeApplication(int index) {
198 beginRemoveRows(QModelIndex(), index, index);
199 m_list.takeAt(index)->deleteLater();
202 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
205 QList<MockApp*> m_list;
208class LauncherModelTest : public QObject
213 LauncherModel *launcherModel;
214 MockAppManager *appManager;
215 QTemporaryDir tmpDir;
217 QList<QVariantMap> getASConfig() {
218 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
219 QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
220 "com.canonical.unity.AccountsService",
222 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
225 // Link our app data from a tempdir & tell glib/UAL to look there.
226 // We do this because we want to be able to delete the applications dir
227 // during testing, but that dir may be read-only (installed on system).
229 QFile appDir(qgetenv("APPDIR"));
230 appDir.link(tmpDir.path() + "/applications");
232 qputenv("XDG_DATA_HOME", tmpDir.path().toUtf8());
237 void initTestCase() {
238 qDBusRegisterMetaType<QList<QVariantMap>>();
242 launcherModel = new LauncherModel(this);
243 QCoreApplication::processEvents(); // to let the model register on DBus
244 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
246 appManager = new MockAppManager(this);
247 launcherModel->setApplicationManager(appManager);
250 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
252 // Switching to tmpDir makes manipulating our appdir symlink easier.
253 QDir::setCurrent(tmpDir.path());
255 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
256 QStringLiteral("/org/freedesktop/Accounts"),
257 QStringLiteral("org.freedesktop.Accounts"));
258 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
259 QString::fromUtf8(g_get_user_name()));
260 QVERIFY(addReply.isValid());
261 QCOMPARE(addReply.value(), true);
263 appManager->addApplication(new MockApp("abs-icon"));
264 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
266 appManager->addApplication(new MockApp("rel-icon"));
267 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
269 launcherModel->m_settings->setStoredApplications(QStringList());
272 // Removing apps from appmanager and launcher as pinned ones would stick
274 while (appManager->count() > 0) {
275 appManager->removeApplication(0);
277 while (launcherModel->rowCount(QModelIndex()) > 0) {
278 launcherModel->requestRemove(launcherModel->get(0)->appId());
281 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
282 QStringLiteral("/org/freedesktop/Accounts"),
283 QStringLiteral("org.freedesktop.Accounts"));
284 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
285 QString::fromUtf8(g_get_user_name()));
286 QVERIFY(removeReply.isValid());
287 QCOMPARE(removeReply.value(), true);
289 // Some tests move the directory, so lets move it back if so.
290 // But this will usually fail.
291 QFile::rename("applications.old", "applications");
295 QCOMPARE(launcherModel->get(0)->pinned(), false);
296 QCOMPARE(launcherModel->get(1)->pinned(), false);
298 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
299 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
300 launcherModel->move(1, 0);
302 QCOMPARE(item0BeforeMove, launcherModel->get(1));
303 QCOMPARE(item1BeforeMove, launcherModel->get(0));
305 // moved item must be pinned now
306 QCOMPARE(item0BeforeMove->pinned(), false);
307 QCOMPARE(item1BeforeMove->pinned(), true);
311 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
312 QCOMPARE(launcherModel->get(0)->pinned(), false);
313 QCOMPARE(launcherModel->get(1)->pinned(), false);
314 launcherModel->pin(launcherModel->get(0)->appId());
315 QCOMPARE(launcherModel->get(0)->pinned(), true);
316 QCOMPARE(launcherModel->get(1)->pinned(), false);
317 QCOMPARE(spy.count() > 0, true);
318 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
320 // App should be pinned now
322 launcherModel->requestRemove(launcherModel->get(0)->appId());
323 QCOMPARE(launcherModel->get(0)->pinned(), false);
324 QCOMPARE(launcherModel->get(1)->pinned(), false);
325 QCOMPARE(spy.count(), 1);
326 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
328 // Now that the app is unpinned, nothing should change and the signal should not be emitted
330 launcherModel->requestRemove(launcherModel->get(0)->appId());
331 QCOMPARE(launcherModel->get(0)->pinned(), false);
332 QCOMPARE(launcherModel->get(1)->pinned(), false);
333 QCOMPARE(spy.count(), 0);
336 void testRemove_data() {
338 QTest::addColumn<bool>("pinned");
339 QTest::addColumn<bool>("running");
341 QTest::newRow("non-pinned, running") << false << true;
342 QTest::newRow("pinned, running") << true << true;
343 QTest::newRow("pinned, non-running") << true << false;
347 QFETCH(bool, pinned);
348 QFETCH(bool, running);
350 // In the beginning we always have two items
351 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
353 // pin one if required
355 launcherModel->pin("abs-icon");
358 // stop it if required
360 appManager->stopApplication("abs-icon");
364 launcherModel->requestRemove("abs-icon");
367 // both apps are running, both apps must still be here
368 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
370 // Item must be unpinned now
371 int index = launcherModel->findApplication("abs-icon");
372 QCOMPARE(launcherModel->get(index)->pinned(), false);
375 // Item 1 must go away, item 0 is here to stay
376 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
379 // done our checks. now stop the app if was still running
381 appManager->stopApplication("abs-icon");
384 // It needs to go away in any case now
385 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
388 void testQuickListPinningRemoving() {
389 // we start with 2 unpinned items
390 QCOMPARE(launcherModel->get(0)->pinned(), false);
391 QCOMPARE(launcherModel->get(1)->pinned(), false);
392 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
394 // find the Pin item in the quicklist
395 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
396 int pinActionIndex = -1;
397 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
398 if (model->get(i).actionId() == "pin_item") {
403 QVERIFY(pinActionIndex >= 0);
405 // trigger pin item quicklist action => Item must be pinned now.
406 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
407 QCOMPARE(launcherModel->get(0)->pinned(), true);
408 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
410 // quicklist needs to transform to remove item. trigger it and check it item goes away
411 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
412 QCOMPARE(launcherModel->get(0)->pinned(), false);
414 // still needs to be here as the app is still here
415 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
417 appManager->removeApplication(0);
418 // Now it needs to go away
419 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
422 void testApplicationRunning() {
423 launcherModel->pin("abs-icon");
424 launcherModel->pin("rel-icon");
426 QCOMPARE(launcherModel->get(0)->running(), true);
427 QCOMPARE(launcherModel->get(1)->running(), true);
429 appManager->stopApplication("abs-icon");
430 QCOMPARE(launcherModel->get(0)->running(), false);
431 QCOMPARE(launcherModel->get(1)->running(), true);
433 appManager->stopApplication("rel-icon");
434 QCOMPARE(launcherModel->get(0)->running(), false);
435 QCOMPARE(launcherModel->get(1)->running(), false);
438 void testApplicationFocused() {
439 // all apps unfocused at beginning...
440 QCOMPARE(launcherModel->get(0)->focused(), false);
441 QCOMPARE(launcherModel->get(1)->focused(), false);
443 appManager->focusApplication("abs-icon");
444 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
445 QCOMPARE(launcherModel->get(0)->focused(), true);
446 QCOMPARE(launcherModel->get(1)->focused(), false);
448 appManager->focusApplication("rel-icon");
449 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
450 QCOMPARE(launcherModel->get(0)->focused(), false);
451 QCOMPARE(launcherModel->get(1)->focused(), true);
454 void testClosingApps() {
455 // At the start there are 2 items. Let's pin one.
456 launcherModel->pin("abs-icon");
457 while (appManager->count() > 0) {
458 appManager->removeApplication(0);
460 // The pinned one needs to stay, the other needs to disappear
461 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
462 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
465 void testQuitMenuItem() {
466 // we have 2 apps running, both should have the Quit action in its quick list
467 QCOMPARE(launcherModel->rowCount(), 2);
469 // stop the second one keeping it pinned so that it doesn't go away
470 launcherModel->pin("rel-icon");
471 appManager->stopApplication("rel-icon");
473 // find the first Quit item, should be there
474 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
475 int quitActionIndex = -1;
476 for (int i = 0; i < model->rowCount(); ++i) {
477 if (model->get(i).actionId() == "stop_item") {
482 QVERIFY(quitActionIndex >= 0);
484 // find the second Quit item, should NOT be there, the app is stopped
485 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
486 int quitActionIndex2 = -1;
487 for (int i = 0; i < model2->rowCount(); ++i) {
488 if (model2->get(i).actionId() == "stop_item") {
489 quitActionIndex2 = i;
493 QVERIFY(quitActionIndex2 == -1);
495 // trigger the first quit item quicklist action
496 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
497 // first app should be gone...
498 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
499 // ... the second app (now at index 0) should still be there, pinned and stopped
500 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("rel-icon"));
501 QCOMPARE(launcherModel->get(0)->pinned(), true);
502 QCOMPARE(launcherModel->get(0)->running(), false);
505 void testGetUrlForAppId() {
506 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
507 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
508 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
509 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
510 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
511 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
514 void testIntrospection() {
515 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
516 QDBusReply<QString> reply = interface.call("Introspect");
517 QStringList nodes = extractNodes(reply.value());
518 QCOMPARE(nodes.count(), launcherModel->rowCount());
520 appManager->addApplication(new MockApp("foobar"));
521 reply = interface.call("Introspect");
522 nodes = extractNodes(reply.value());
523 QCOMPARE(nodes.contains("foobar"), true);
525 appManager->removeApplication(2);
526 reply = interface.call("Introspect");
527 nodes = extractNodes(reply.value());
528 QCOMPARE(nodes.contains("foobar"), false);
531 QStringList extractNodes(const QString &introspectionXml) {
532 QXmlStreamReader introspectReply(introspectionXml);
535 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
536 QXmlStreamReader::TokenType token = introspectReply.readNext();
538 if (token == QXmlStreamReader::StartElement) {
539 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
540 ret << introspectReply.attributes().value("name").toString();
547 void testCountEmblems() {
548 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
550 // Call GetAll on abs-icon
551 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
552 QDBusReply<QVariantMap> reply = interface.call("GetAll");
553 QVariantMap map = reply.value();
555 // Check that the alerting-status is still false, and the item on the upper side of the API
556 int index = launcherModel->findApplication("abs-icon");
557 QCOMPARE(index >= 0, true);
558 QVERIFY(launcherModel->get(index)->alerting() == false);
560 // Make sure GetAll returns a map with count and countVisible props
561 QCOMPARE(map.contains("count"), true);
562 QCOMPARE(map.contains("countVisible"), true);
564 // Make sure count is intitilized to 0 and non-visible
565 QCOMPARE(map.value("count").toInt(), 0);
566 QCOMPARE(map.value("countVisible").toBool(), false);
568 // Now make it visible and set it to 55 through D-Bus
569 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
570 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
572 // Fetch it again using GetAll
573 reply = interface.call("GetAll");
576 // Make sure values have changed on the D-Bus interface
577 QCOMPARE(map.value("count").toInt(), 55);
578 QCOMPARE(map.value("countVisible").toBool(), true);
580 // Finally check, that the change to "count" implicitly also set the alerting-state to true
581 QVERIFY(launcherModel->get(index)->alerting() == true);
583 // Check if the launcher emitted the changed signals
584 QCOMPARE(spy.count(), 2);
586 QVariantList countEmissionArgs = spy.takeFirst();
587 QCOMPARE(countEmissionArgs.at(0).toModelIndex().row(), index);
588 QCOMPARE(countEmissionArgs.at(1).toModelIndex().row(), index);
589 QVector<int> roles = countEmissionArgs.at(2).value<QVector<int> >();
590 QCOMPARE(roles.first(), (int)LauncherModel::RoleCount);
592 QVariantList countVisibleEmissionArgs = spy.takeFirst();
593 QCOMPARE(countVisibleEmissionArgs.at(0).toModelIndex().row(), index);
594 QCOMPARE(countVisibleEmissionArgs.at(1).toModelIndex().row(), index);
595 roles = countVisibleEmissionArgs.at(2).value<QVector<int> >();
596 QVERIFY(roles.contains(LauncherModel::RoleCountVisible));
597 QVERIFY(roles.contains(LauncherModel::RoleAlerting));
599 // Check if the values match
600 QCOMPARE(launcherModel->get(index)->countVisible(), true);
601 QCOMPARE(launcherModel->get(index)->count(), 55);
602 QCOMPARE(launcherModel->get(index)->alerting(), true);
604 // Focus the app, make sure the alert gets cleared
605 appManager->focusApplication("abs-icon");
606 QVERIFY(launcherModel->get(index)->alerting() == false);
609 void testCountEmblemAddsRemovesItem_data() {
610 QTest::addColumn<bool>("isPinned");
611 QTest::addColumn<bool>("isRunning");
612 QTest::addColumn<bool>("startWhenVisible");
613 QTest::newRow("not pinned, not running") << false << false << false;
614 QTest::newRow("pinned, not running") << true << false << false;
615 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
616 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
617 QTest::newRow("not pinned, running") << false << true << false;
618 QTest::newRow("pinned, running") << true << true << false;
621 void testCountEmblemAddsRemovesItem() {
622 QFETCH(bool, isPinned);
623 QFETCH(bool, isRunning);
624 QFETCH(bool, startWhenVisible);
626 // Make sure item is here as expected after init() and that count is not visible
627 int index = launcherModel->findApplication("abs-icon");
628 QCOMPARE(index == -1, false);
629 QCOMPARE(launcherModel->get(index)->countVisible(), false);
633 launcherModel->pin("abs-icon");
635 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
637 // Stop it if we need to
639 appManager->stopApplication("abs-icon");
641 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
644 // set the count emblem to visible
645 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
646 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
647 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
649 // Make sure item is here and that count is visible
650 index = launcherModel->findApplication("abs-icon");
651 QCOMPARE(index == -1, false);
652 QCOMPARE(launcherModel->get(index)->countVisible(), true);
654 if (!isRunning && startWhenVisible) {
655 appManager->addApplication(new MockApp("abs-icon"));
658 // Hide count emblem again
659 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
661 // Make sure item is shown/hidden as expected
662 index = launcherModel->findApplication("abs-icon");
663 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
667 // Check that the alerting-status is still false
668 int index = launcherModel->findApplication("abs-icon");
669 QCOMPARE(index >= 0, true);
670 QVERIFY(launcherModel->get(index)->alerting() == false);
672 // Call Alert() on "abs-icon"
673 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
674 interface.call("Alert");
676 // Check that the alerting-status is now true
677 QVERIFY(launcherModel->get(index)->alerting() == true);
679 // Focus the app, make sure the alert gets cleared
680 appManager->focusApplication("abs-icon");
681 QVERIFY(launcherModel->get(index)->alerting() == false);
684 void testRefreshAfterDeletedDesktopFiles_data() {
685 QTest::addColumn<bool>("deleted");
686 QTest::newRow("have .desktop files") << false;
687 QTest::newRow("deleted .desktop files") << true;
690 void testRefreshAfterDeletedDesktopFiles() {
691 QFETCH(bool, deleted);
694 launcherModel->pin("abs-icon");
695 launcherModel->pin("rel-icon");
697 appManager->removeApplication(0);
698 appManager->removeApplication(0);
700 // "delete" the .desktop files
702 // In testing mode, the launcher searches the current dir for the sample .desktop file
703 // We can make that fail by moving the applications dir
704 QFile::rename("applications", "applications.old");
708 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
709 QDBusReply<void> reply = interface.call("Refresh");
711 // Make sure the call to Refresh returned without error.
712 QCOMPARE(reply.isValid(), true);
714 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
717 void testSettings() {
718 GSettings *settings = launcherModel->m_settings;
719 QSignalSpy spy(launcherModel, &LauncherModel::hint);
721 // Nothing pinned at startup
722 QCOMPARE(settings->storedApplications().count(), 0);
725 launcherModel->pin("abs-icon");
726 launcherModel->pin("rel-icon");
727 QCOMPARE(spy.count(), 0);
729 // Now settings should have 2 apps
730 QCOMPARE(settings->storedApplications().count(), 2);
733 appManager->removeApplication(0);
734 appManager->removeApplication(0);
736 // Now settings should have 2 apps
737 QCOMPARE(settings->storedApplications().count(), 2);
739 // Now remove 1 app through the backend, make sure one is still there
740 settings->simulateDConfChanged(QStringList() << "abs-icon");
741 QCOMPARE(settings->storedApplications().count(), 1);
742 QCOMPARE(spy.count(), 1);
744 // Check if it disappeared from the frontend too
745 QCOMPARE(launcherModel->rowCount(), 1);
747 // Add them back but in reverse order
748 settings->simulateDConfChanged(QStringList() << "rel-icon" << "abs-icon");
749 QCOMPARE(launcherModel->rowCount(), 2);
750 QCOMPARE(launcherModel->get(0)->appId(), QString("rel-icon"));
751 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
752 QCOMPARE(spy.count(), 2);
755 void testAddSyncsToAS() {
756 // Make sure launcher and AS are in sync when we start the test
757 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
759 int oldCount = launcherModel->rowCount();
760 appManager->addApplication(new MockApp("click-icon"));
761 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
762 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
765 void testRemoveSyncsToAS() {
766 // Make sure launcher and AS are in sync when we start the test
767 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
769 int oldCount = launcherModel->rowCount();
770 appManager->stopApplication("abs-icon");
771 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
772 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
775 void testMoveSyncsToAS() {
776 // Make sure launcher and AS are in sync when we start the test
777 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
779 for (int i = 0; i < launcherModel->rowCount(); i++) {
780 QString launcherAppId = launcherModel->get(i)->appId();
781 QString asAppId = getASConfig().at(i).value("id").toString();
782 QCOMPARE(launcherAppId, asAppId);
785 launcherModel->move(0, 1);
787 for (int i = 0; i < launcherModel->rowCount(); i++) {
788 QString launcherAppId = launcherModel->get(i)->appId();
789 QString asAppId = getASConfig().at(i).value("id").toString();
790 QCOMPARE(launcherAppId, asAppId);
794 void testCountChangeSyncsToAS() {
795 // Find the index of the abs-icon app
796 int index = launcherModel->findApplication("abs-icon");
798 // Make sure it's invisible and 0 at the beginning
799 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
800 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
802 // Change the count of the abs-icon app through D-Bus
803 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
804 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
805 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
807 // Make sure it changed to visible and 55
808 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
809 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
812 void testSurfaceCountUpdates() {
813 QString appId = launcherModel->get(0)->appId();
815 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
816 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
817 MockSurfaceList* surfaces = new MockSurfaceList(appManager);
818 surfaces->append(new MockSurface("foobar", "foobar", surfaces));
819 app->setSurfaces(surfaces);
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);
834QTEST_GUILESS_MAIN(LauncherModelTest)
835#include "launchermodeltest.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list