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>
36// This is a mock, specifically to test the LauncherModel
37class MockApp: public unity::shell::application::ApplicationInfoInterface
41 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
43 RequestedState requestedState() const override { return RequestedRunning; }
44 void setRequestedState(RequestedState) override {}
45 QString appId() const override { return m_appId; }
46 QString name() const override { return "mock"; }
47 QString comment() const override { return "this is a mock"; }
48 QUrl icon() const override { return QUrl(); }
49 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
50 bool focused() const override { return m_focused; }
51 QString splashTitle() const override { return QString(); }
52 QUrl splashImage() const override { return QUrl(); }
53 bool splashShowHeader() const override { return true; }
54 QColor splashColor() const override { return QColor(0,0,0,0); }
55 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
56 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
57 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
58 bool rotatesWindowContents() const override { return false; }
59 bool isTouchApp() const override { return true; }
60 bool exemptFromLifecycle() const override { return false; }
61 void setExemptFromLifecycle(bool) override {}
62 QSize initialSurfaceSize() const override { return QSize(); }
63 void setInitialSurfaceSize(const QSize &) override {}
64 MirSurfaceListInterface* surfaceList() const override { return nullptr; }
65 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
66 int surfaceCount() const override { return m_surfaceCount; }
67 void setSurfaceCount(int count) { m_surfaceCount = count; Q_EMIT surfaceCountChanged(count); }
69 // Methods used for mocking (not in the interface)
70 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
74 int m_surfaceCount = 0;
77// This is a mock, specifically to test the LauncherModel
78class MockAppManager: public unity::shell::application::ApplicationManagerInterface
82 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
84 int rowCount(const QModelIndex &) const override { return m_list.count(); }
85 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
86 QString focusedApplicationId() const override {
87 Q_FOREACH(MockApp *app, m_list) {
88 if (app->focused()) return app->appId();
92 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
93 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
94 Q_FOREACH(MockApp* app, m_list) {
95 if (app->appId() == appId) {
101 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
102 bool stopApplication(const QString &appId) override {
103 Q_FOREACH(MockApp* app, m_list) {
104 if (app->appId() == appId) {
105 removeApplication(m_list.indexOf(app));
111 bool focusApplication(const QString &appId) {
112 Q_FOREACH(MockApp* app, m_list) {
113 app->setFocused(app->appId() == appId);
115 Q_EMIT focusedApplicationIdChanged();
119 void addApplication(MockApp *app) {
120 beginInsertRows(QModelIndex(), count(), count());
124 void removeApplication(int index) {
125 beginRemoveRows(QModelIndex(), index, index);
126 m_list.takeAt(index)->deleteLater();
129 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
132 QList<MockApp*> m_list;
135class LauncherModelTest : public QObject
140 LauncherModel *launcherModel;
141 MockAppManager *appManager;
143 QList<QVariantMap> getASConfig() {
144 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
145 QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString::fromUtf8(g_get_user_name()),
146 "com.canonical.unity.AccountsService",
148 return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
153 void initTestCase() {
154 qDBusRegisterMetaType<QList<QVariantMap>>();
156 launcherModel = new LauncherModel(this);
157 QCoreApplication::processEvents(); // to let the model register on DBus
158 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
160 appManager = new MockAppManager(this);
161 launcherModel->setApplicationManager(appManager);
164 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
166 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
167 QStringLiteral("/org/freedesktop/Accounts"),
168 QStringLiteral("org.freedesktop.Accounts"));
169 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
170 QString::fromUtf8(g_get_user_name()));
171 QVERIFY(addReply.isValid());
172 QCOMPARE(addReply.value(), true);
174 appManager->addApplication(new MockApp("abs-icon"));
175 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
177 appManager->addApplication(new MockApp("rel-icon"));
178 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
180 launcherModel->m_settings->setStoredApplications(QStringList());
183 // Removing apps from appmanager and launcher as pinned ones would stick
185 while (appManager->count() > 0) {
186 appManager->removeApplication(0);
188 while (launcherModel->rowCount(QModelIndex()) > 0) {
189 launcherModel->requestRemove(launcherModel->get(0)->appId());
192 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
193 QStringLiteral("/org/freedesktop/Accounts"),
194 QStringLiteral("org.freedesktop.Accounts"));
195 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
196 QString::fromUtf8(g_get_user_name()));
197 QVERIFY(removeReply.isValid());
198 QCOMPARE(removeReply.value(), true);
200 // Some tests move the directory, so lets move it back if so.
201 // But this will usually fail.
202 QFile::rename("applications.old", "applications");
206 QCOMPARE(launcherModel->get(0)->pinned(), false);
207 QCOMPARE(launcherModel->get(1)->pinned(), false);
209 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
210 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
211 launcherModel->move(1, 0);
213 QCOMPARE(item0BeforeMove, launcherModel->get(1));
214 QCOMPARE(item1BeforeMove, launcherModel->get(0));
216 // moved item must be pinned now
217 QCOMPARE(item0BeforeMove->pinned(), false);
218 QCOMPARE(item1BeforeMove->pinned(), true);
222 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
223 QCOMPARE(launcherModel->get(0)->pinned(), false);
224 QCOMPARE(launcherModel->get(1)->pinned(), false);
225 launcherModel->pin(launcherModel->get(0)->appId());
226 QCOMPARE(launcherModel->get(0)->pinned(), true);
227 QCOMPARE(launcherModel->get(1)->pinned(), false);
228 QCOMPARE(spy.count() > 0, true);
229 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
231 // App should be pinned now
233 launcherModel->requestRemove(launcherModel->get(0)->appId());
234 QCOMPARE(launcherModel->get(0)->pinned(), false);
235 QCOMPARE(launcherModel->get(1)->pinned(), false);
236 QCOMPARE(spy.count(), 1);
237 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
239 // Now that the app is unpinned, nothing should change and the signal should not be emitted
241 launcherModel->requestRemove(launcherModel->get(0)->appId());
242 QCOMPARE(launcherModel->get(0)->pinned(), false);
243 QCOMPARE(launcherModel->get(1)->pinned(), false);
244 QCOMPARE(spy.count(), 0);
247 void testRemove_data() {
249 QTest::addColumn<bool>("pinned");
250 QTest::addColumn<bool>("running");
252 QTest::newRow("non-pinned, running") << false << true;
253 QTest::newRow("pinned, running") << true << true;
254 QTest::newRow("pinned, non-running") << true << false;
258 QFETCH(bool, pinned);
259 QFETCH(bool, running);
261 // In the beginning we always have two items
262 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
264 // pin one if required
266 launcherModel->pin("abs-icon");
269 // stop it if required
271 appManager->stopApplication("abs-icon");
275 launcherModel->requestRemove("abs-icon");
278 // both apps are running, both apps must still be here
279 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
281 // Item must be unpinned now
282 int index = launcherModel->findApplication("abs-icon");
283 QCOMPARE(launcherModel->get(index)->pinned(), false);
286 // Item 1 must go away, item 0 is here to stay
287 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
290 // done our checks. now stop the app if was still running
292 appManager->stopApplication("abs-icon");
295 // It needs to go away in any case now
296 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
299 void testQuickListPinningRemoving() {
300 // we start with 2 unpinned items
301 QCOMPARE(launcherModel->get(0)->pinned(), false);
302 QCOMPARE(launcherModel->get(1)->pinned(), false);
303 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
305 // find the Pin item in the quicklist
306 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
307 int pinActionIndex = -1;
308 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
309 if (model->get(i).actionId() == "pin_item") {
314 QVERIFY(pinActionIndex >= 0);
316 // trigger pin item quicklist action => Item must be pinned now.
317 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
318 QCOMPARE(launcherModel->get(0)->pinned(), true);
319 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
321 // quicklist needs to transform to remove item. trigger it and check it item goes away
322 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
323 QCOMPARE(launcherModel->get(0)->pinned(), false);
325 // still needs to be here as the app is still here
326 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
328 appManager->removeApplication(0);
329 // Now it needs to go away
330 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
333 void testApplicationRunning() {
334 launcherModel->pin("abs-icon");
335 launcherModel->pin("rel-icon");
337 QCOMPARE(launcherModel->get(0)->running(), true);
338 QCOMPARE(launcherModel->get(1)->running(), true);
340 appManager->stopApplication("abs-icon");
341 QCOMPARE(launcherModel->get(0)->running(), false);
342 QCOMPARE(launcherModel->get(1)->running(), true);
344 appManager->stopApplication("rel-icon");
345 QCOMPARE(launcherModel->get(0)->running(), false);
346 QCOMPARE(launcherModel->get(1)->running(), false);
349 void testApplicationFocused() {
350 // all apps unfocused at beginning...
351 QCOMPARE(launcherModel->get(0)->focused(), false);
352 QCOMPARE(launcherModel->get(1)->focused(), false);
354 appManager->focusApplication("abs-icon");
355 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
356 QCOMPARE(launcherModel->get(0)->focused(), true);
357 QCOMPARE(launcherModel->get(1)->focused(), false);
359 appManager->focusApplication("rel-icon");
360 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
361 QCOMPARE(launcherModel->get(0)->focused(), false);
362 QCOMPARE(launcherModel->get(1)->focused(), true);
365 void testClosingApps() {
366 // At the start there are 2 items. Let's pin one.
367 launcherModel->pin("abs-icon");
368 while (appManager->count() > 0) {
369 appManager->removeApplication(0);
371 // The pinned one needs to stay, the other needs to disappear
372 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
373 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
376 void testQuitMenuItem() {
377 // we have 2 apps running, both should have the Quit action in its quick list
378 QCOMPARE(launcherModel->rowCount(), 2);
380 // stop the second one keeping it pinned so that it doesn't go away
381 launcherModel->pin("rel-icon");
382 appManager->stopApplication("rel-icon");
384 // find the first Quit item, should be there
385 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
386 int quitActionIndex = -1;
387 for (int i = 0; i < model->rowCount(); ++i) {
388 if (model->get(i).actionId() == "stop_item") {
393 QVERIFY(quitActionIndex >= 0);
395 // find the second Quit item, should NOT be there, the app is stopped
396 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
397 int quitActionIndex2 = -1;
398 for (int i = 0; i < model2->rowCount(); ++i) {
399 if (model2->get(i).actionId() == "stop_item") {
400 quitActionIndex2 = i;
404 QVERIFY(quitActionIndex2 == -1);
406 // trigger the first quit item quicklist action
407 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
408 // first app should be gone...
409 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
410 // ... the second app (now at index 0) should still be there, pinned and stopped
411 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("rel-icon"));
412 QCOMPARE(launcherModel->get(0)->pinned(), true);
413 QCOMPARE(launcherModel->get(0)->running(), false);
416 void testGetUrlForAppId() {
417 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
418 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
419 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
420 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
421 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
422 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
425 void testIntrospection() {
426 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
427 QDBusReply<QString> reply = interface.call("Introspect");
428 QStringList nodes = extractNodes(reply.value());
429 QCOMPARE(nodes.count(), launcherModel->rowCount());
431 appManager->addApplication(new MockApp("foobar"));
432 reply = interface.call("Introspect");
433 nodes = extractNodes(reply.value());
434 QCOMPARE(nodes.contains("foobar"), true);
436 appManager->removeApplication(2);
437 reply = interface.call("Introspect");
438 nodes = extractNodes(reply.value());
439 QCOMPARE(nodes.contains("foobar"), false);
442 QStringList extractNodes(const QString &introspectionXml) {
443 QXmlStreamReader introspectReply(introspectionXml);
446 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
447 QXmlStreamReader::TokenType token = introspectReply.readNext();
449 if (token == QXmlStreamReader::StartElement) {
450 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
451 ret << introspectReply.attributes().value("name").toString();
458 void testCountEmblems() {
459 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
461 // Call GetAll on abs-icon
462 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
463 QDBusReply<QVariantMap> reply = interface.call("GetAll");
464 QVariantMap map = reply.value();
466 // Check that the alerting-status is still false, and the item on the upper side of the API
467 int index = launcherModel->findApplication("abs-icon");
468 QCOMPARE(index >= 0, true);
469 QVERIFY(launcherModel->get(index)->alerting() == false);
471 // Make sure GetAll returns a map with count and countVisible props
472 QCOMPARE(map.contains("count"), true);
473 QCOMPARE(map.contains("countVisible"), true);
475 // Make sure count is intitilized to 0 and non-visible
476 QCOMPARE(map.value("count").toInt(), 0);
477 QCOMPARE(map.value("countVisible").toBool(), false);
479 // Now make it visible and set it to 55 through D-Bus
480 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
481 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
483 // Fetch it again using GetAll
484 reply = interface.call("GetAll");
487 // Make sure values have changed on the D-Bus interface
488 QCOMPARE(map.value("count").toInt(), 55);
489 QCOMPARE(map.value("countVisible").toBool(), true);
491 // Finally check, that the change to "count" implicitly also set the alerting-state to true
492 QVERIFY(launcherModel->get(index)->alerting() == true);
494 // Check if the launcher emitted the changed signals
495 QCOMPARE(spy.count(), 2);
497 QVariantList countEmissionArgs = spy.takeFirst();
498 QCOMPARE(countEmissionArgs.at(0).value<QModelIndex>().row(), index);
499 QCOMPARE(countEmissionArgs.at(1).value<QModelIndex>().row(), index);
500 QVector<int> roles = countEmissionArgs.at(2).value<QVector<int> >();
501 QCOMPARE(roles.first(), (int)LauncherModel::RoleCount);
503 QVariantList countVisibleEmissionArgs = spy.takeFirst();
504 QCOMPARE(countVisibleEmissionArgs.at(0).value<QModelIndex>().row(), index);
505 QCOMPARE(countVisibleEmissionArgs.at(1).value<QModelIndex>().row(), index);
506 roles = countVisibleEmissionArgs.at(2).value<QVector<int> >();
507 QVERIFY(roles.contains(LauncherModel::RoleCountVisible));
508 QVERIFY(roles.contains(LauncherModel::RoleAlerting));
510 // Check if the values match
511 QCOMPARE(launcherModel->get(index)->countVisible(), true);
512 QCOMPARE(launcherModel->get(index)->count(), 55);
513 QCOMPARE(launcherModel->get(index)->alerting(), true);
515 // Focus the app, make sure the alert gets cleared
516 appManager->focusApplication("abs-icon");
517 QVERIFY(launcherModel->get(index)->alerting() == false);
520 void testCountEmblemAddsRemovesItem_data() {
521 QTest::addColumn<bool>("isPinned");
522 QTest::addColumn<bool>("isRunning");
523 QTest::addColumn<bool>("startWhenVisible");
524 QTest::newRow("not pinned, not running") << false << false << false;
525 QTest::newRow("pinned, not running") << true << false << false;
526 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
527 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
528 QTest::newRow("not pinned, running") << false << true << false;
529 QTest::newRow("pinned, running") << true << true << false;
532 void testCountEmblemAddsRemovesItem() {
533 QFETCH(bool, isPinned);
534 QFETCH(bool, isRunning);
535 QFETCH(bool, startWhenVisible);
537 // Make sure item is here as expected after init() and that count is not visible
538 int index = launcherModel->findApplication("abs-icon");
539 QCOMPARE(index == -1, false);
540 QCOMPARE(launcherModel->get(index)->countVisible(), false);
544 launcherModel->pin("abs-icon");
546 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
548 // Stop it if we need to
550 appManager->stopApplication("abs-icon");
552 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
555 // set the count emblem to visible
556 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
557 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
558 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
560 // Make sure item is here and that count is visible
561 index = launcherModel->findApplication("abs-icon");
562 QCOMPARE(index == -1, false);
563 QCOMPARE(launcherModel->get(index)->countVisible(), true);
565 if (!isRunning && startWhenVisible) {
566 appManager->addApplication(new MockApp("abs-icon"));
569 // Hide count emblem again
570 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
572 // Make sure item is shown/hidden as expected
573 index = launcherModel->findApplication("abs-icon");
574 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
578 // Check that the alerting-status is still false
579 int index = launcherModel->findApplication("abs-icon");
580 QCOMPARE(index >= 0, true);
581 QVERIFY(launcherModel->get(index)->alerting() == false);
583 // Call Alert() on "abs-icon"
584 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
585 interface.call("Alert");
587 // Check that the alerting-status is now true
588 QVERIFY(launcherModel->get(index)->alerting() == true);
590 // Focus the app, make sure the alert gets cleared
591 appManager->focusApplication("abs-icon");
592 QVERIFY(launcherModel->get(index)->alerting() == false);
595 void testRefreshAfterDeletedDesktopFiles_data() {
596 QTest::addColumn<bool>("deleted");
597 QTest::newRow("have .desktop files") << false;
598 QTest::newRow("deleted .desktop files") << true;
601 void testRefreshAfterDeletedDesktopFiles() {
602 QFETCH(bool, deleted);
605 launcherModel->pin("abs-icon");
606 launcherModel->pin("rel-icon");
608 appManager->removeApplication(0);
609 appManager->removeApplication(0);
611 // "delete" the .desktop files
613 // In testing mode, the launcher searches the current dir for the sample .desktop file
614 // We can make that fail by moving the applications dir
615 QFile::rename("applications", "applications.old");
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);
628 void testSettings() {
629 GSettings *settings = launcherModel->m_settings;
630 QSignalSpy spy(launcherModel, &LauncherModel::hint);
632 // Nothing pinned at startup
633 QCOMPARE(settings->storedApplications().count(), 0);
636 launcherModel->pin("abs-icon");
637 launcherModel->pin("rel-icon");
638 QCOMPARE(spy.count(), 0);
640 // Now settings should have 2 apps
641 QCOMPARE(settings->storedApplications().count(), 2);
644 appManager->removeApplication(0);
645 appManager->removeApplication(0);
647 // Now settings should have 2 apps
648 QCOMPARE(settings->storedApplications().count(), 2);
650 // Now remove 1 app through the backend, make sure one is still there
651 settings->simulateDConfChanged(QStringList() << "abs-icon");
652 QCOMPARE(settings->storedApplications().count(), 1);
653 QCOMPARE(spy.count(), 1);
655 // Check if it disappeared from the frontend too
656 QCOMPARE(launcherModel->rowCount(), 1);
658 // Add them back but in reverse order
659 settings->simulateDConfChanged(QStringList() << "rel-icon" << "abs-icon");
660 QCOMPARE(launcherModel->rowCount(), 2);
661 QCOMPARE(launcherModel->get(0)->appId(), QString("rel-icon"));
662 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
663 QCOMPARE(spy.count(), 2);
666 void testAddSyncsToAS() {
667 // Make sure launcher and AS are in sync when we start the test
668 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
670 int oldCount = launcherModel->rowCount();
671 appManager->addApplication(new MockApp("click-icon"));
672 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
673 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
676 void testRemoveSyncsToAS() {
677 // Make sure launcher and AS are in sync when we start the test
678 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
680 int oldCount = launcherModel->rowCount();
681 appManager->stopApplication("abs-icon");
682 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
683 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
686 void testMoveSyncsToAS() {
687 // Make sure launcher and AS are in sync when we start the test
688 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
690 for (int i = 0; i < launcherModel->rowCount(); i++) {
691 QString launcherAppId = launcherModel->get(i)->appId();
692 QString asAppId = getASConfig().at(i).value("id").toString();
693 QCOMPARE(launcherAppId, asAppId);
696 launcherModel->move(0, 1);
698 for (int i = 0; i < launcherModel->rowCount(); i++) {
699 QString launcherAppId = launcherModel->get(i)->appId();
700 QString asAppId = getASConfig().at(i).value("id").toString();
701 QCOMPARE(launcherAppId, asAppId);
705 void testCountChangeSyncsToAS() {
706 // Find the index of the abs-icon app
707 int index = launcherModel->findApplication("abs-icon");
709 // Make sure it's invisible and 0 at the beginning
710 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
711 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
713 // Change the count of the abs-icon app through D-Bus
714 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
715 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
716 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
718 // Make sure it changed to visible and 55
719 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
720 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
723 void testSurfaceCountUpdates() {
724 QString appId = launcherModel->get(0)->appId();
726 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
727 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
728 app->setSurfaceCount(1);
729 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
733QTEST_GUILESS_MAIN(LauncherModelTest)
734#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