2 * Copyright 2013-2016 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>
21#include "launcheritem.h"
22#include "launchermodel.h"
23#include "dbusinterface.h"
26#include "AccountsServiceDBusAdaptor.h"
29#include <QDBusInterface>
31#include <QDBusMetaType>
32#include <QDomDocument>
37// This is a mock, specifically to test the LauncherModel
38class MockApp: public unity::shell::application::ApplicationInfoInterface
42 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
44 RequestedState requestedState() const override { return RequestedRunning; }
45 void setRequestedState(RequestedState) override {}
46 QString appId() const override { return m_appId; }
47 QString name() const override { return "mock"; }
48 QString comment() const override { return "this is a mock"; }
49 QUrl icon() const override { return QUrl(); }
50 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
51 bool focused() const override { return m_focused; }
52 QString splashTitle() const override { return QString(); }
53 QUrl splashImage() const override { return QUrl(); }
54 bool splashShowHeader() const override { return true; }
55 QColor splashColor() const override { return QColor(0,0,0,0); }
56 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
57 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
58 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
59 bool rotatesWindowContents() const override { return false; }
60 bool isTouchApp() const override { return true; }
61 bool exemptFromLifecycle() const override { return false; }
62 void setExemptFromLifecycle(bool) override {}
63 QSize initialSurfaceSize() const override { return QSize(); }
64 void setInitialSurfaceSize(const QSize &) override {}
65 MirSurfaceListInterface* surfaceList() const override { return nullptr; }
66 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
67 int surfaceCount() const override { return m_surfaceCount; }
68 void setSurfaceCount(int count) { m_surfaceCount = count; Q_EMIT surfaceCountChanged(count); }
70 // Methods used for mocking (not in the interface)
71 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
75 int m_surfaceCount = 0;
78// This is a mock, specifically to test the LauncherModel
79class MockAppManager: public unity::shell::application::ApplicationManagerInterface
83 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
85 int rowCount(const QModelIndex &) const override { return m_list.count(); }
86 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
87 QString focusedApplicationId() const override {
88 Q_FOREACH(MockApp *app, m_list) {
89 if (app->focused()) return app->appId();
93 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
94 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
95 Q_FOREACH(MockApp* app, m_list) {
96 if (app->appId() == appId) {
102 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
103 bool stopApplication(const QString &appId) override {
104 Q_FOREACH(MockApp* app, m_list) {
105 if (app->appId() == appId) {
106 removeApplication(m_list.indexOf(app));
112 bool focusApplication(const QString &appId) {
113 Q_FOREACH(MockApp* app, m_list) {
114 app->setFocused(app->appId() == appId);
116 Q_EMIT focusedApplicationIdChanged();
120 void addApplication(MockApp *app) {
121 beginInsertRows(QModelIndex(), count(), count());
125 void removeApplication(int index) {
126 beginRemoveRows(QModelIndex(), index, index);
127 m_list.takeAt(index)->deleteLater();
130 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
133 QList<MockApp*> m_list;
136class LauncherModelTest : public QObject
141 LauncherModel *launcherModel;
142 MockAppManager *appManager;
143 QTemporaryDir tmpDir;
145 QList<QVariantMap> getASConfig() {
146 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
147 QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
148 "com.canonical.unity.AccountsService",
150 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
153 // Link our app data from a tempdir & tell glib/UAL to look there.
154 // We do this because we want to be able to delete the applications dir
155 // during testing, but that dir may be read-only (installed on system).
157 QFile appDir(qgetenv("APPDIR"));
158 appDir.link(tmpDir.path() + "/applications");
160 qputenv("XDG_DATA_HOME", tmpDir.path().toUtf8());
165 void initTestCase() {
166 qDBusRegisterMetaType<QList<QVariantMap>>();
170 launcherModel = new LauncherModel(this);
171 QCoreApplication::processEvents(); // to let the model register on DBus
172 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
174 appManager = new MockAppManager(this);
175 launcherModel->setApplicationManager(appManager);
178 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
180 // Switching to tmpDir makes manipulating our appdir symlink easier.
181 QDir::setCurrent(tmpDir.path());
183 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
184 QStringLiteral("/org/freedesktop/Accounts"),
185 QStringLiteral("org.freedesktop.Accounts"));
186 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
187 QString::fromUtf8(g_get_user_name()));
188 QVERIFY(addReply.isValid());
189 QCOMPARE(addReply.value(), true);
191 appManager->addApplication(new MockApp("abs-icon"));
192 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
194 appManager->addApplication(new MockApp("rel-icon"));
195 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
197 launcherModel->m_settings->setStoredApplications(QStringList());
200 // Removing apps from appmanager and launcher as pinned ones would stick
202 while (appManager->count() > 0) {
203 appManager->removeApplication(0);
205 while (launcherModel->rowCount(QModelIndex()) > 0) {
206 launcherModel->requestRemove(launcherModel->get(0)->appId());
209 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
210 QStringLiteral("/org/freedesktop/Accounts"),
211 QStringLiteral("org.freedesktop.Accounts"));
212 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
213 QString::fromUtf8(g_get_user_name()));
214 QVERIFY(removeReply.isValid());
215 QCOMPARE(removeReply.value(), true);
217 // Some tests move the directory, so lets move it back if so.
218 // But this will usually fail.
219 QFile::rename("applications.old", "applications");
223 QCOMPARE(launcherModel->get(0)->pinned(), false);
224 QCOMPARE(launcherModel->get(1)->pinned(), false);
226 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
227 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
228 launcherModel->move(1, 0);
230 QCOMPARE(item0BeforeMove, launcherModel->get(1));
231 QCOMPARE(item1BeforeMove, launcherModel->get(0));
233 // moved item must be pinned now
234 QCOMPARE(item0BeforeMove->pinned(), false);
235 QCOMPARE(item1BeforeMove->pinned(), true);
239 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
240 QCOMPARE(launcherModel->get(0)->pinned(), false);
241 QCOMPARE(launcherModel->get(1)->pinned(), false);
242 launcherModel->pin(launcherModel->get(0)->appId());
243 QCOMPARE(launcherModel->get(0)->pinned(), true);
244 QCOMPARE(launcherModel->get(1)->pinned(), false);
245 QCOMPARE(spy.count() > 0, true);
246 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
248 // App should be pinned now
250 launcherModel->requestRemove(launcherModel->get(0)->appId());
251 QCOMPARE(launcherModel->get(0)->pinned(), false);
252 QCOMPARE(launcherModel->get(1)->pinned(), false);
253 QCOMPARE(spy.count(), 1);
254 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
256 // Now that the app is unpinned, nothing should change and the signal should not be emitted
258 launcherModel->requestRemove(launcherModel->get(0)->appId());
259 QCOMPARE(launcherModel->get(0)->pinned(), false);
260 QCOMPARE(launcherModel->get(1)->pinned(), false);
261 QCOMPARE(spy.count(), 0);
264 void testRemove_data() {
266 QTest::addColumn<bool>("pinned");
267 QTest::addColumn<bool>("running");
269 QTest::newRow("non-pinned, running") << false << true;
270 QTest::newRow("pinned, running") << true << true;
271 QTest::newRow("pinned, non-running") << true << false;
275 QFETCH(bool, pinned);
276 QFETCH(bool, running);
278 // In the beginning we always have two items
279 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
281 // pin one if required
283 launcherModel->pin("abs-icon");
286 // stop it if required
288 appManager->stopApplication("abs-icon");
292 launcherModel->requestRemove("abs-icon");
295 // both apps are running, both apps must still be here
296 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
298 // Item must be unpinned now
299 int index = launcherModel->findApplication("abs-icon");
300 QCOMPARE(launcherModel->get(index)->pinned(), false);
303 // Item 1 must go away, item 0 is here to stay
304 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
307 // done our checks. now stop the app if was still running
309 appManager->stopApplication("abs-icon");
312 // It needs to go away in any case now
313 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
316 void testQuickListPinningRemoving() {
317 // we start with 2 unpinned items
318 QCOMPARE(launcherModel->get(0)->pinned(), false);
319 QCOMPARE(launcherModel->get(1)->pinned(), false);
320 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
322 // find the Pin item in the quicklist
323 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
324 int pinActionIndex = -1;
325 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
326 if (model->get(i).actionId() == "pin_item") {
331 QVERIFY(pinActionIndex >= 0);
333 // trigger pin item quicklist action => Item must be pinned now.
334 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
335 QCOMPARE(launcherModel->get(0)->pinned(), true);
336 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
338 // quicklist needs to transform to remove item. trigger it and check it item goes away
339 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
340 QCOMPARE(launcherModel->get(0)->pinned(), false);
342 // still needs to be here as the app is still here
343 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
345 appManager->removeApplication(0);
346 // Now it needs to go away
347 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
350 void testApplicationRunning() {
351 launcherModel->pin("abs-icon");
352 launcherModel->pin("rel-icon");
354 QCOMPARE(launcherModel->get(0)->running(), true);
355 QCOMPARE(launcherModel->get(1)->running(), true);
357 appManager->stopApplication("abs-icon");
358 QCOMPARE(launcherModel->get(0)->running(), false);
359 QCOMPARE(launcherModel->get(1)->running(), true);
361 appManager->stopApplication("rel-icon");
362 QCOMPARE(launcherModel->get(0)->running(), false);
363 QCOMPARE(launcherModel->get(1)->running(), false);
366 void testApplicationFocused() {
367 // all apps unfocused at beginning...
368 QCOMPARE(launcherModel->get(0)->focused(), false);
369 QCOMPARE(launcherModel->get(1)->focused(), false);
371 appManager->focusApplication("abs-icon");
372 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
373 QCOMPARE(launcherModel->get(0)->focused(), true);
374 QCOMPARE(launcherModel->get(1)->focused(), false);
376 appManager->focusApplication("rel-icon");
377 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
378 QCOMPARE(launcherModel->get(0)->focused(), false);
379 QCOMPARE(launcherModel->get(1)->focused(), true);
382 void testClosingApps() {
383 // At the start there are 2 items. Let's pin one.
384 launcherModel->pin("abs-icon");
385 while (appManager->count() > 0) {
386 appManager->removeApplication(0);
388 // The pinned one needs to stay, the other needs to disappear
389 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
390 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
393 void testQuitMenuItem() {
394 // we have 2 apps running, both should have the Quit action in its quick list
395 QCOMPARE(launcherModel->rowCount(), 2);
397 // stop the second one keeping it pinned so that it doesn't go away
398 launcherModel->pin("rel-icon");
399 appManager->stopApplication("rel-icon");
401 // find the first Quit item, should be there
402 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
403 int quitActionIndex = -1;
404 for (int i = 0; i < model->rowCount(); ++i) {
405 if (model->get(i).actionId() == "stop_item") {
410 QVERIFY(quitActionIndex >= 0);
412 // find the second Quit item, should NOT be there, the app is stopped
413 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
414 int quitActionIndex2 = -1;
415 for (int i = 0; i < model2->rowCount(); ++i) {
416 if (model2->get(i).actionId() == "stop_item") {
417 quitActionIndex2 = i;
421 QVERIFY(quitActionIndex2 == -1);
423 // trigger the first quit item quicklist action
424 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
425 // first app should be gone...
426 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
427 // ... the second app (now at index 0) should still be there, pinned and stopped
428 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("rel-icon"));
429 QCOMPARE(launcherModel->get(0)->pinned(), true);
430 QCOMPARE(launcherModel->get(0)->running(), false);
433 void testGetUrlForAppId() {
434 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
435 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
436 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
437 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
438 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
439 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
442 void testIntrospection() {
443 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
444 QDBusReply<QString> reply = interface.call("Introspect");
445 QStringList nodes = extractNodes(reply.value());
446 QCOMPARE(nodes.count(), launcherModel->rowCount());
448 appManager->addApplication(new MockApp("foobar"));
449 reply = interface.call("Introspect");
450 nodes = extractNodes(reply.value());
451 QCOMPARE(nodes.contains("foobar"), true);
453 appManager->removeApplication(2);
454 reply = interface.call("Introspect");
455 nodes = extractNodes(reply.value());
456 QCOMPARE(nodes.contains("foobar"), false);
459 QStringList extractNodes(const QString &introspectionXml) {
460 QXmlStreamReader introspectReply(introspectionXml);
463 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
464 QXmlStreamReader::TokenType token = introspectReply.readNext();
466 if (token == QXmlStreamReader::StartElement) {
467 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
468 ret << introspectReply.attributes().value("name").toString();
475 void testCountEmblems() {
476 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
478 // Call GetAll on abs-icon
479 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
480 QDBusReply<QVariantMap> reply = interface.call("GetAll");
481 QVariantMap map = reply.value();
483 // Check that the alerting-status is still false, and the item on the upper side of the API
484 int index = launcherModel->findApplication("abs-icon");
485 QCOMPARE(index >= 0, true);
486 QVERIFY(launcherModel->get(index)->alerting() == false);
488 // Make sure GetAll returns a map with count and countVisible props
489 QCOMPARE(map.contains("count"), true);
490 QCOMPARE(map.contains("countVisible"), true);
492 // Make sure count is intitilized to 0 and non-visible
493 QCOMPARE(map.value("count").toInt(), 0);
494 QCOMPARE(map.value("countVisible").toBool(), false);
496 // Now make it visible and set it to 55 through D-Bus
497 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
498 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
500 // Fetch it again using GetAll
501 reply = interface.call("GetAll");
504 // Make sure values have changed on the D-Bus interface
505 QCOMPARE(map.value("count").toInt(), 55);
506 QCOMPARE(map.value("countVisible").toBool(), true);
508 // Finally check, that the change to "count" implicitly also set the alerting-state to true
509 QVERIFY(launcherModel->get(index)->alerting() == true);
511 // Check if the launcher emitted the changed signals
512 QCOMPARE(spy.count(), 2);
514 QVariantList countEmissionArgs = spy.takeFirst();
515 QCOMPARE(countEmissionArgs.at(0).value<QModelIndex>().row(), index);
516 QCOMPARE(countEmissionArgs.at(1).value<QModelIndex>().row(), index);
517 QVector<int> roles = countEmissionArgs.at(2).value<QVector<int> >();
518 QCOMPARE(roles.first(), (int)LauncherModel::RoleCount);
520 QVariantList countVisibleEmissionArgs = spy.takeFirst();
521 QCOMPARE(countVisibleEmissionArgs.at(0).value<QModelIndex>().row(), index);
522 QCOMPARE(countVisibleEmissionArgs.at(1).value<QModelIndex>().row(), index);
523 roles = countVisibleEmissionArgs.at(2).value<QVector<int> >();
524 QVERIFY(roles.contains(LauncherModel::RoleCountVisible));
525 QVERIFY(roles.contains(LauncherModel::RoleAlerting));
527 // Check if the values match
528 QCOMPARE(launcherModel->get(index)->countVisible(), true);
529 QCOMPARE(launcherModel->get(index)->count(), 55);
530 QCOMPARE(launcherModel->get(index)->alerting(), true);
532 // Focus the app, make sure the alert gets cleared
533 appManager->focusApplication("abs-icon");
534 QVERIFY(launcherModel->get(index)->alerting() == false);
537 void testCountEmblemAddsRemovesItem_data() {
538 QTest::addColumn<bool>("isPinned");
539 QTest::addColumn<bool>("isRunning");
540 QTest::addColumn<bool>("startWhenVisible");
541 QTest::newRow("not pinned, not running") << false << false << false;
542 QTest::newRow("pinned, not running") << true << false << false;
543 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
544 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
545 QTest::newRow("not pinned, running") << false << true << false;
546 QTest::newRow("pinned, running") << true << true << false;
549 void testCountEmblemAddsRemovesItem() {
550 QFETCH(bool, isPinned);
551 QFETCH(bool, isRunning);
552 QFETCH(bool, startWhenVisible);
554 // Make sure item is here as expected after init() and that count is not visible
555 int index = launcherModel->findApplication("abs-icon");
556 QCOMPARE(index == -1, false);
557 QCOMPARE(launcherModel->get(index)->countVisible(), false);
561 launcherModel->pin("abs-icon");
563 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
565 // Stop it if we need to
567 appManager->stopApplication("abs-icon");
569 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
572 // set the count emblem to visible
573 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
574 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
575 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
577 // Make sure item is here and that count is visible
578 index = launcherModel->findApplication("abs-icon");
579 QCOMPARE(index == -1, false);
580 QCOMPARE(launcherModel->get(index)->countVisible(), true);
582 if (!isRunning && startWhenVisible) {
583 appManager->addApplication(new MockApp("abs-icon"));
586 // Hide count emblem again
587 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
589 // Make sure item is shown/hidden as expected
590 index = launcherModel->findApplication("abs-icon");
591 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
595 // Check that the alerting-status is still false
596 int index = launcherModel->findApplication("abs-icon");
597 QCOMPARE(index >= 0, true);
598 QVERIFY(launcherModel->get(index)->alerting() == false);
600 // Call Alert() on "abs-icon"
601 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
602 interface.call("Alert");
604 // Check that the alerting-status is now true
605 QVERIFY(launcherModel->get(index)->alerting() == true);
607 // Focus the app, make sure the alert gets cleared
608 appManager->focusApplication("abs-icon");
609 QVERIFY(launcherModel->get(index)->alerting() == false);
612 void testRefreshAfterDeletedDesktopFiles_data() {
613 QTest::addColumn<bool>("deleted");
614 QTest::newRow("have .desktop files") << false;
615 QTest::newRow("deleted .desktop files") << true;
618 void testRefreshAfterDeletedDesktopFiles() {
619 QFETCH(bool, deleted);
622 launcherModel->pin("abs-icon");
623 launcherModel->pin("rel-icon");
625 appManager->removeApplication(0);
626 appManager->removeApplication(0);
628 // "delete" the .desktop files
630 // In testing mode, the launcher searches the current dir for the sample .desktop file
631 // We can make that fail by moving the applications dir
632 QFile::rename("applications", "applications.old");
636 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
637 QDBusReply<void> reply = interface.call("Refresh");
639 // Make sure the call to Refresh returned without error.
640 QCOMPARE(reply.isValid(), true);
642 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
645 void testSettings() {
646 GSettings *settings = launcherModel->m_settings;
647 QSignalSpy spy(launcherModel, &LauncherModel::hint);
649 // Nothing pinned at startup
650 QCOMPARE(settings->storedApplications().count(), 0);
653 launcherModel->pin("abs-icon");
654 launcherModel->pin("rel-icon");
655 QCOMPARE(spy.count(), 0);
657 // Now settings should have 2 apps
658 QCOMPARE(settings->storedApplications().count(), 2);
661 appManager->removeApplication(0);
662 appManager->removeApplication(0);
664 // Now settings should have 2 apps
665 QCOMPARE(settings->storedApplications().count(), 2);
667 // Now remove 1 app through the backend, make sure one is still there
668 settings->simulateDConfChanged(QStringList() << "abs-icon");
669 QCOMPARE(settings->storedApplications().count(), 1);
670 QCOMPARE(spy.count(), 1);
672 // Check if it disappeared from the frontend too
673 QCOMPARE(launcherModel->rowCount(), 1);
675 // Add them back but in reverse order
676 settings->simulateDConfChanged(QStringList() << "rel-icon" << "abs-icon");
677 QCOMPARE(launcherModel->rowCount(), 2);
678 QCOMPARE(launcherModel->get(0)->appId(), QString("rel-icon"));
679 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
680 QCOMPARE(spy.count(), 2);
683 void testAddSyncsToAS() {
684 // Make sure launcher and AS are in sync when we start the test
685 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
687 int oldCount = launcherModel->rowCount();
688 appManager->addApplication(new MockApp("click-icon"));
689 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
690 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
693 void testRemoveSyncsToAS() {
694 // Make sure launcher and AS are in sync when we start the test
695 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
697 int oldCount = launcherModel->rowCount();
698 appManager->stopApplication("abs-icon");
699 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
700 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
703 void testMoveSyncsToAS() {
704 // Make sure launcher and AS are in sync when we start the test
705 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
707 for (int i = 0; i < launcherModel->rowCount(); i++) {
708 QString launcherAppId = launcherModel->get(i)->appId();
709 QString asAppId = getASConfig().at(i).value("id").toString();
710 QCOMPARE(launcherAppId, asAppId);
713 launcherModel->move(0, 1);
715 for (int i = 0; i < launcherModel->rowCount(); i++) {
716 QString launcherAppId = launcherModel->get(i)->appId();
717 QString asAppId = getASConfig().at(i).value("id").toString();
718 QCOMPARE(launcherAppId, asAppId);
722 void testCountChangeSyncsToAS() {
723 // Find the index of the abs-icon app
724 int index = launcherModel->findApplication("abs-icon");
726 // Make sure it's invisible and 0 at the beginning
727 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
728 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
730 // Change the count of the abs-icon app through D-Bus
731 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
732 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
733 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
735 // Make sure it changed to visible and 55
736 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
737 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
740 void testSurfaceCountUpdates() {
741 QString appId = launcherModel->get(0)->appId();
743 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
744 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
745 app->setSurfaceCount(1);
746 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
750QTEST_GUILESS_MAIN(LauncherModelTest)
751#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