2 * Copyright 2013-2015 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/>.
17 * Michael Zanetti <michael.zanetti@canonical.com>
21#include <unity/shell/launcher/LauncherModelInterface.h>
22#include <unity/shell/application/ApplicationInfoInterface.h>
24#include "launcheritem.h"
25#include "launchermodel.h"
26#include "dbusinterface.h"
29#include "AccountsServiceDBusAdaptor.h"
32#include <QDBusInterface>
34#include <QDBusMetaType>
35#include <QDomDocument>
39// This is a mock, specifically to test the LauncherModel
40class MockApp: public unity::shell::application::ApplicationInfoInterface
44 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
46 RequestedState requestedState() const override { return RequestedRunning; }
47 void setRequestedState(RequestedState) override {}
48 QString appId() const override { return m_appId; }
49 QString name() const override { return "mock"; }
50 QString comment() const override { return "this is a mock"; }
51 QUrl icon() const override { return QUrl(); }
52 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
53 bool focused() const override { return m_focused; }
54 QString splashTitle() const override { return QString(); }
55 QUrl splashImage() const override { return QUrl(); }
56 bool splashShowHeader() const override { return true; }
57 QColor splashColor() const override { return QColor(0,0,0,0); }
58 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
59 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
60 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
61 bool rotatesWindowContents() const override { return false; }
62 bool isTouchApp() const override { return true; }
63 bool exemptFromLifecycle() const override { return false; }
64 void setExemptFromLifecycle(bool) override {}
65 QSize initialSurfaceSize() const override { return QSize(); }
66 void setInitialSurfaceSize(const QSize &) override {}
67 MirSurfaceListInterface* surfaceList() const override { return nullptr; }
68 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); }
72 // Methods used for mocking (not in the interface)
73 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
77 int m_surfaceCount = 0;
80// This is a mock, specifically to test the LauncherModel
81class MockAppManager: public unity::shell::application::ApplicationManagerInterface
85 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
87 int rowCount(const QModelIndex &) const override { return m_list.count(); }
88 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
89 QString focusedApplicationId() const override {
90 Q_FOREACH(MockApp *app, m_list) {
91 if (app->focused()) return app->appId();
95 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
96 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
97 Q_FOREACH(MockApp* app, m_list) {
98 if (app->appId() == appId) {
104 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
105 bool stopApplication(const QString &appId) override {
106 Q_FOREACH(MockApp* app, m_list) {
107 if (app->appId() == appId) {
108 removeApplication(m_list.indexOf(app));
114 bool focusApplication(const QString &appId) {
115 Q_FOREACH(MockApp* app, m_list) {
116 app->setFocused(app->appId() == appId);
118 Q_EMIT focusedApplicationIdChanged();
122 void addApplication(MockApp *app) {
123 beginInsertRows(QModelIndex(), count(), count());
127 void removeApplication(int index) {
128 beginRemoveRows(QModelIndex(), index, index);
129 m_list.takeAt(index)->deleteLater();
132 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
135 QList<MockApp*> m_list;
138class LauncherModelTest : public QObject
143 LauncherModel *launcherModel;
144 MockAppManager *appManager;
146 QList<QVariantMap> getASConfig() {
147 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
148 QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
149 "com.canonical.unity.AccountsService",
151 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
156 void initTestCase() {
157 qDBusRegisterMetaType<QList<QVariantMap>>();
159 launcherModel = new LauncherModel(this);
160 QCoreApplication::processEvents(); // to let the model register on DBus
161 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
163 appManager = new MockAppManager(this);
164 launcherModel->setApplicationManager(appManager);
167 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
169 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
170 QStringLiteral("/org/freedesktop/Accounts"),
171 QStringLiteral("org.freedesktop.Accounts"));
172 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
173 QString::fromUtf8(g_get_user_name()));
174 QVERIFY(addReply.isValid());
175 QCOMPARE(addReply.value(), true);
177 appManager->addApplication(new MockApp("abs-icon"));
178 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
180 appManager->addApplication(new MockApp("no-icon"));
181 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
183 launcherModel->m_settings->setStoredApplications(QStringList());
186 // Removing apps from appmanager and launcher as pinned ones would stick
188 while (appManager->count() > 0) {
189 appManager->removeApplication(0);
191 while (launcherModel->rowCount(QModelIndex()) > 0) {
192 launcherModel->requestRemove(launcherModel->get(0)->appId());
195 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
196 QStringLiteral("/org/freedesktop/Accounts"),
197 QStringLiteral("org.freedesktop.Accounts"));
198 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
199 QString::fromUtf8(g_get_user_name()));
200 QVERIFY(removeReply.isValid());
201 QCOMPARE(removeReply.value(), true);
205 QCOMPARE(launcherModel->get(0)->pinned(), false);
206 QCOMPARE(launcherModel->get(1)->pinned(), false);
208 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
209 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
210 launcherModel->move(1, 0);
212 QCOMPARE(item0BeforeMove, launcherModel->get(1));
213 QCOMPARE(item1BeforeMove, launcherModel->get(0));
215 // moved item must be pinned now
216 QCOMPARE(item0BeforeMove->pinned(), false);
217 QCOMPARE(item1BeforeMove->pinned(), true);
221 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
222 QCOMPARE(launcherModel->get(0)->pinned(), false);
223 QCOMPARE(launcherModel->get(1)->pinned(), false);
224 launcherModel->pin(launcherModel->get(0)->appId());
225 QCOMPARE(launcherModel->get(0)->pinned(), true);
226 QCOMPARE(launcherModel->get(1)->pinned(), false);
227 QCOMPARE(spy.count() > 0, true);
228 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
230 // App should be pinned now
232 launcherModel->requestRemove(launcherModel->get(0)->appId());
233 QCOMPARE(launcherModel->get(0)->pinned(), false);
234 QCOMPARE(launcherModel->get(1)->pinned(), false);
235 QCOMPARE(spy.count(), 1);
236 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
238 // Now that the app is unpinned, nothing should change and the signal should not be emitted
240 launcherModel->requestRemove(launcherModel->get(0)->appId());
241 QCOMPARE(launcherModel->get(0)->pinned(), false);
242 QCOMPARE(launcherModel->get(1)->pinned(), false);
243 QCOMPARE(spy.count(), 0);
246 void testRemove_data() {
248 QTest::addColumn<bool>("pinned");
249 QTest::addColumn<bool>("running");
251 QTest::newRow("non-pinned, running") << false << true;
252 QTest::newRow("pinned, running") << true << true;
253 QTest::newRow("pinned, non-running") << true << false;
257 QFETCH(bool, pinned);
258 QFETCH(bool, running);
260 // In the beginning we always have two items
261 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
263 // pin one if required
265 launcherModel->pin("abs-icon");
268 // stop it if required
270 appManager->stopApplication("abs-icon");
274 launcherModel->requestRemove("abs-icon");
277 // both apps are running, both apps must still be here
278 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
280 // Item must be unpinned now
281 int index = launcherModel->findApplication("abs-icon");
282 QCOMPARE(launcherModel->get(index)->pinned(), false);
285 // Item 1 must go away, item 0 is here to stay
286 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
289 // done our checks. now stop the app if was still running
291 appManager->stopApplication("abs-icon");
294 // It needs to go away in any case now
295 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
298 void testQuickListPinningRemoving() {
299 // we start with 2 unpinned items
300 QCOMPARE(launcherModel->get(0)->pinned(), false);
301 QCOMPARE(launcherModel->get(1)->pinned(), false);
302 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
304 // find the Pin item in the quicklist
305 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
306 int pinActionIndex = -1;
307 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
308 if (model->get(i).actionId() == "pin_item") {
313 QVERIFY(pinActionIndex >= 0);
315 // trigger pin item quicklist action => Item must be pinned now.
316 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
317 QCOMPARE(launcherModel->get(0)->pinned(), true);
318 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
320 // quicklist needs to transform to remove item. trigger it and check it item goes away
321 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
322 QCOMPARE(launcherModel->get(0)->pinned(), false);
324 // still needs to be here as the app is still here
325 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
327 appManager->removeApplication(0);
328 // Now it needs to go away
329 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
332 void testApplicationRunning() {
333 launcherModel->pin("abs-icon");
334 launcherModel->pin("no-icon");
336 QCOMPARE(launcherModel->get(0)->running(), true);
337 QCOMPARE(launcherModel->get(1)->running(), true);
339 appManager->stopApplication("abs-icon");
340 QCOMPARE(launcherModel->get(0)->running(), false);
341 QCOMPARE(launcherModel->get(1)->running(), true);
343 appManager->stopApplication("no-icon");
344 QCOMPARE(launcherModel->get(0)->running(), false);
345 QCOMPARE(launcherModel->get(1)->running(), false);
348 void testApplicationFocused() {
349 // all apps unfocused at beginning...
350 QCOMPARE(launcherModel->get(0)->focused(), false);
351 QCOMPARE(launcherModel->get(1)->focused(), false);
353 appManager->focusApplication("abs-icon");
354 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
355 QCOMPARE(launcherModel->get(0)->focused(), true);
356 QCOMPARE(launcherModel->get(1)->focused(), false);
358 appManager->focusApplication("no-icon");
359 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
360 QCOMPARE(launcherModel->get(0)->focused(), false);
361 QCOMPARE(launcherModel->get(1)->focused(), true);
364 void testClosingApps() {
365 // At the start there are 2 items. Let's pin one.
366 launcherModel->pin("abs-icon");
367 while (appManager->count() > 0) {
368 appManager->removeApplication(0);
370 // The pinned one needs to stay, the other needs to disappear
371 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
372 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
375 void testQuitMenuItem() {
376 // we have 2 apps running, both should have the Quit action in its quick list
377 QCOMPARE(launcherModel->rowCount(), 2);
379 // stop the second one keeping it pinned so that it doesn't go away
380 launcherModel->pin("no-icon");
381 appManager->stopApplication("no-icon");
383 // find the first Quit item, should be there
384 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
385 int quitActionIndex = -1;
386 for (int i = 0; i < model->rowCount(); ++i) {
387 if (model->get(i).actionId() == "stop_item") {
392 QVERIFY(quitActionIndex >= 0);
394 // find the second Quit item, should NOT be there, the app is stopped
395 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
396 int quitActionIndex2 = -1;
397 for (int i = 0; i < model2->rowCount(); ++i) {
398 if (model2->get(i).actionId() == "stop_item") {
399 quitActionIndex2 = i;
403 QVERIFY(quitActionIndex2 == -1);
405 // trigger the first quit item quicklist action
406 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
407 // first app should be gone...
408 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
409 // ... the second app (now at index 0) should still be there, pinned and stopped
410 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
411 QCOMPARE(launcherModel->get(0)->pinned(), true);
412 QCOMPARE(launcherModel->get(0)->running(), false);
415 void testGetUrlForAppId() {
416 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
417 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
418 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
419 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
420 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
421 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
424 void testIntrospection() {
425 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
426 QDBusReply<QString> reply = interface.call("Introspect");
427 QStringList nodes = extractNodes(reply.value());
428 QCOMPARE(nodes.count(), launcherModel->rowCount());
430 appManager->addApplication(new MockApp("foobar"));
431 reply = interface.call("Introspect");
432 nodes = extractNodes(reply.value());
433 QCOMPARE(nodes.contains("foobar"), true);
435 appManager->removeApplication(2);
436 reply = interface.call("Introspect");
437 nodes = extractNodes(reply.value());
438 QCOMPARE(nodes.contains("foobar"), false);
441 QStringList extractNodes(const QString &introspectionXml) {
442 QXmlStreamReader introspectReply(introspectionXml);
445 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
446 QXmlStreamReader::TokenType token = introspectReply.readNext();
448 if (token == QXmlStreamReader::StartElement) {
449 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
450 ret << introspectReply.attributes().value("name").toString();
457 void testCountEmblems() {
458 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
460 // Call GetAll on abs-icon
461 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
462 QDBusReply<QVariantMap> reply = interface.call("GetAll");
463 QVariantMap map = reply.value();
465 // Check that the alerting-status is still false, and the item on the upper side of the API
466 int index = launcherModel->findApplication("abs-icon");
467 QCOMPARE(index >= 0, true);
468 QVERIFY(launcherModel->get(index)->alerting() == false);
470 // Make sure GetAll returns a map with count and countVisible props
471 QCOMPARE(map.contains("count"), true);
472 QCOMPARE(map.contains("countVisible"), true);
474 // Make sure count is intitilized to 0 and non-visible
475 QCOMPARE(map.value("count").toInt(), 0);
476 QCOMPARE(map.value("countVisible").toBool(), false);
478 // Now make it visible and set it to 55 through D-Bus
479 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
480 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
482 // Fetch it again using GetAll
483 reply = interface.call("GetAll");
486 // Make sure values have changed on the D-Bus interface
487 QCOMPARE(map.value("count").toInt(), 55);
488 QCOMPARE(map.value("countVisible").toBool(), true);
490 // Finally check, that the change to "count" implicitly also set the alerting-state to true
491 QVERIFY(launcherModel->get(index)->alerting() == true);
493 // Check if the launcher emitted the changed signals
494 QCOMPARE(spy.count(), 2);
496 QVariantList countEmissionArgs = spy.takeFirst();
497 QCOMPARE(countEmissionArgs.at(0).value<QModelIndex>().row(), index);
498 QCOMPARE(countEmissionArgs.at(1).value<QModelIndex>().row(), index);
499 QVector<int> roles = countEmissionArgs.at(2).value<QVector<int> >();
500 QCOMPARE(roles.first(), (int)LauncherModel::RoleCount);
502 QVariantList countVisibleEmissionArgs = spy.takeFirst();
503 QCOMPARE(countVisibleEmissionArgs.at(0).value<QModelIndex>().row(), index);
504 QCOMPARE(countVisibleEmissionArgs.at(1).value<QModelIndex>().row(), index);
505 roles = countVisibleEmissionArgs.at(2).value<QVector<int> >();
506 QVERIFY(roles.contains(LauncherModel::RoleCountVisible));
507 QVERIFY(roles.contains(LauncherModel::RoleAlerting));
509 // Check if the values match
510 QCOMPARE(launcherModel->get(index)->countVisible(), true);
511 QCOMPARE(launcherModel->get(index)->count(), 55);
512 QCOMPARE(launcherModel->get(index)->alerting(), true);
514 // Focus the app, make sure the alert gets cleared
515 appManager->focusApplication("abs-icon");
516 QVERIFY(launcherModel->get(index)->alerting() == false);
519 void testCountEmblemAddsRemovesItem_data() {
520 QTest::addColumn<bool>("isPinned");
521 QTest::addColumn<bool>("isRunning");
522 QTest::addColumn<bool>("startWhenVisible");
523 QTest::newRow("not pinned, not running") << false << false << false;
524 QTest::newRow("pinned, not running") << true << false << false;
525 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
526 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
527 QTest::newRow("not pinned, running") << false << true << false;
528 QTest::newRow("pinned, running") << true << true << false;
531 void testCountEmblemAddsRemovesItem() {
532 QFETCH(bool, isPinned);
533 QFETCH(bool, isRunning);
534 QFETCH(bool, startWhenVisible);
536 // Make sure item is here as expected after init() and that count is not visible
537 int index = launcherModel->findApplication("abs-icon");
538 QCOMPARE(index == -1, false);
539 QCOMPARE(launcherModel->get(index)->countVisible(), false);
543 launcherModel->pin("abs-icon");
545 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
547 // Stop it if we need to
549 appManager->stopApplication("abs-icon");
551 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
554 // set the count emblem to visible
555 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
556 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
557 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
559 // Make sure item is here and that count is visible
560 index = launcherModel->findApplication("abs-icon");
561 QCOMPARE(index == -1, false);
562 QCOMPARE(launcherModel->get(index)->countVisible(), true);
564 if (!isRunning && startWhenVisible) {
565 appManager->addApplication(new MockApp("abs-icon"));
568 // Hide count emblem again
569 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
571 // Make sure item is shown/hidden as expected
572 index = launcherModel->findApplication("abs-icon");
573 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
577 // Check that the alerting-status is still false
578 int index = launcherModel->findApplication("abs-icon");
579 QCOMPARE(index >= 0, true);
580 QVERIFY(launcherModel->get(index)->alerting() == false);
582 // Call Alert() on "abs-icon"
583 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
584 interface.call("Alert");
586 // Check that the alerting-status is now true
587 QVERIFY(launcherModel->get(index)->alerting() == true);
589 // Focus the app, make sure the alert gets cleared
590 appManager->focusApplication("abs-icon");
591 QVERIFY(launcherModel->get(index)->alerting() == false);
594 void testRefreshAfterDeletedDesktopFiles_data() {
595 QTest::addColumn<bool>("deleted");
596 QTest::newRow("have .desktop files") << false;
597 QTest::newRow("deleted .desktop files") << true;
600 void testRefreshAfterDeletedDesktopFiles() {
601 QFETCH(bool, deleted);
604 launcherModel->pin("abs-icon");
605 launcherModel->pin("no-icon");
607 appManager->removeApplication(0);
608 appManager->removeApplication(0);
610 // "delete" the .desktop files
611 QString oldCurrent = QDir::currentPath();
613 // In testing mode, the launcher searches the current dir for the sample .desktop file
614 // We can make that fail by changing the current dir
615 QDir::setCurrent("..");
619 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
620 QDBusReply<void> reply = interface.call("Refresh");
622 // Make sure the call to Refresh returned without error.
623 QCOMPARE(reply.isValid(), true);
625 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
627 // Restoring current dir
628 QDir::setCurrent(oldCurrent);
631 void testSettings() {
632 GSettings *settings = launcherModel->m_settings;
633 QSignalSpy spy(launcherModel, &LauncherModel::hint);
635 // Nothing pinned at startup
636 QCOMPARE(settings->storedApplications().count(), 0);
639 launcherModel->pin("abs-icon");
640 launcherModel->pin("no-icon");
641 QCOMPARE(spy.count(), 0);
643 // Now settings should have 2 apps
644 QCOMPARE(settings->storedApplications().count(), 2);
647 appManager->removeApplication(0);
648 appManager->removeApplication(0);
650 // Now settings should have 2 apps
651 QCOMPARE(settings->storedApplications().count(), 2);
653 // Now remove 1 app through the backend, make sure one is still there
654 settings->simulateDConfChanged(QStringList() << "abs-icon");
655 QCOMPARE(settings->storedApplications().count(), 1);
656 QCOMPARE(spy.count(), 1);
658 // Check if it disappeared from the frontend too
659 QCOMPARE(launcherModel->rowCount(), 1);
661 // Add them back but in reverse order
662 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
663 QCOMPARE(launcherModel->rowCount(), 2);
664 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
665 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
666 QCOMPARE(spy.count(), 2);
669 void testAddSyncsToAS() {
670 // Make sure launcher and AS are in sync when we start the test
671 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
673 int oldCount = launcherModel->rowCount();
674 appManager->addApplication(new MockApp("rel-icon"));
675 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
676 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
679 void testRemoveSyncsToAS() {
680 // Make sure launcher and AS are in sync when we start the test
681 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
683 int oldCount = launcherModel->rowCount();
684 appManager->stopApplication("abs-icon");
685 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
686 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
689 void testMoveSyncsToAS() {
690 // Make sure launcher and AS are in sync when we start the test
691 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
693 for (int i = 0; i < launcherModel->rowCount(); i++) {
694 QString launcherAppId = launcherModel->get(i)->appId();
695 QString asAppId = getASConfig().at(i).value("id").toString();
696 QCOMPARE(launcherAppId, asAppId);
699 launcherModel->move(0, 1);
701 for (int i = 0; i < launcherModel->rowCount(); i++) {
702 QString launcherAppId = launcherModel->get(i)->appId();
703 QString asAppId = getASConfig().at(i).value("id").toString();
704 QCOMPARE(launcherAppId, asAppId);
708 void testCountChangeSyncsToAS() {
709 // Find the index of the abs-icon app
710 int index = launcherModel->findApplication("abs-icon");
712 // Make sure it's invisible and 0 at the beginning
713 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
714 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
716 // Change the count of the abs-icon app through D-Bus
717 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
718 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
719 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
721 // Make sure it changed to visible and 55
722 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
723 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
726 void testSurfaceCountUpdates() {
727 QString appId = launcherModel->get(0)->appId();
729 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
730 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
731 app->setSurfaceCount(1);
732 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
736QTEST_GUILESS_MAIN(LauncherModelTest)
737#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