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>
40// This is a mock, specifically to test the LauncherModel
41class MockApp: public unity::shell::application::ApplicationInfoInterface
45 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
47 RequestedState requestedState() const override { return RequestedRunning; }
48 void setRequestedState(RequestedState) override {}
49 QString appId() const override { return m_appId; }
50 QString name() const override { return "mock"; }
51 QString comment() const override { return "this is a mock"; }
52 QUrl icon() const override { return QUrl(); }
53 ApplicationInfoInterface::Stage stage() const override { return ApplicationInfoInterface::MainStage; }
54 void setStage(ApplicationInfoInterface::Stage) override {}
55 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
56 bool focused() const override { return m_focused; }
57 QString splashTitle() const override { return QString(); }
58 QUrl splashImage() const override { return QUrl(); }
59 bool splashShowHeader() const override { return true; }
60 QColor splashColor() const override { return QColor(0,0,0,0); }
61 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
62 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
63 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
64 bool rotatesWindowContents() const override { return false; }
65 bool isTouchApp() const override { return true; }
66 bool exemptFromLifecycle() const override { return false; }
67 void setExemptFromLifecycle(bool) override {}
68 QSize initialSurfaceSize() const override { return QSize(); }
69 void setInitialSurfaceSize(const QSize &) override {}
71 // Methods used for mocking (not in the interface)
72 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
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) override {
113 Q_FOREACH(MockApp* app, m_list) {
114 app->setFocused(app->appId() == appId);
116 Q_EMIT focusedApplicationIdChanged();
120 void unfocusCurrentApplication() override { }
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 // Launcher will look in current dir in testing mode for data
170 QDir::setCurrent(testDataDir() + "/" TEST_DIR);
172 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
173 QStringLiteral("/org/freedesktop/Accounts"),
174 QStringLiteral("org.freedesktop.Accounts"));
175 QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
176 QString::fromUtf8(g_get_user_name()));
177 QVERIFY(addReply.isValid());
178 QCOMPARE(addReply.value(), true);
180 appManager->addApplication(new MockApp("abs-icon"));
181 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
183 appManager->addApplication(new MockApp("no-icon"));
184 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
186 launcherModel->m_settings->setStoredApplications(QStringList());
189 // Removing apps from appmanager and launcher as pinned ones would stick
191 while (appManager->count() > 0) {
192 appManager->removeApplication(0);
194 while (launcherModel->rowCount(QModelIndex()) > 0) {
195 launcherModel->requestRemove(launcherModel->get(0)->appId());
198 QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
199 QStringLiteral("/org/freedesktop/Accounts"),
200 QStringLiteral("org.freedesktop.Accounts"));
201 QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
202 QString::fromUtf8(g_get_user_name()));
203 QVERIFY(removeReply.isValid());
204 QCOMPARE(removeReply.value(), true);
208 QCOMPARE(launcherModel->get(0)->pinned(), false);
209 QCOMPARE(launcherModel->get(1)->pinned(), false);
211 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
212 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
213 launcherModel->move(1, 0);
215 QCOMPARE(item0BeforeMove, launcherModel->get(1));
216 QCOMPARE(item1BeforeMove, launcherModel->get(0));
218 // moved item must be pinned now
219 QCOMPARE(item0BeforeMove->pinned(), false);
220 QCOMPARE(item1BeforeMove->pinned(), true);
224 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
225 QCOMPARE(launcherModel->get(0)->pinned(), false);
226 QCOMPARE(launcherModel->get(1)->pinned(), false);
227 launcherModel->pin(launcherModel->get(0)->appId());
228 QCOMPARE(launcherModel->get(0)->pinned(), true);
229 QCOMPARE(launcherModel->get(1)->pinned(), false);
230 QCOMPARE(spy.count() > 0, true);
231 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
233 // App should be pinned now
235 launcherModel->requestRemove(launcherModel->get(0)->appId());
236 QCOMPARE(launcherModel->get(0)->pinned(), false);
237 QCOMPARE(launcherModel->get(1)->pinned(), false);
238 QCOMPARE(spy.count(), 1);
239 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
241 // Now that the app is unpinned, nothing should change and the signal should not be emitted
243 launcherModel->requestRemove(launcherModel->get(0)->appId());
244 QCOMPARE(launcherModel->get(0)->pinned(), false);
245 QCOMPARE(launcherModel->get(1)->pinned(), false);
246 QCOMPARE(spy.count(), 0);
249 void testRemove_data() {
251 QTest::addColumn<bool>("pinned");
252 QTest::addColumn<bool>("running");
254 QTest::newRow("non-pinned, running") << false << true;
255 QTest::newRow("pinned, running") << true << true;
256 QTest::newRow("pinned, non-running") << true << false;
260 QFETCH(bool, pinned);
261 QFETCH(bool, running);
263 // In the beginning we always have two items
264 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
266 // pin one if required
268 launcherModel->pin("abs-icon");
271 // stop it if required
273 appManager->stopApplication("abs-icon");
277 launcherModel->requestRemove("abs-icon");
280 // both apps are running, both apps must still be here
281 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
283 // Item must be unpinned now
284 int index = launcherModel->findApplication("abs-icon");
285 QCOMPARE(launcherModel->get(index)->pinned(), false);
288 // Item 1 must go away, item 0 is here to stay
289 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
292 // done our checks. now stop the app if was still running
294 appManager->stopApplication("abs-icon");
297 // It needs to go away in any case now
298 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
301 void testQuickListPinningRemoving() {
302 // we start with 2 unpinned items
303 QCOMPARE(launcherModel->get(0)->pinned(), false);
304 QCOMPARE(launcherModel->get(1)->pinned(), false);
305 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
307 // find the Pin item in the quicklist
308 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
309 int pinActionIndex = -1;
310 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
311 if (model->get(i).actionId() == "pin_item") {
316 QVERIFY(pinActionIndex >= 0);
318 // trigger pin item quicklist action => Item must be pinned now.
319 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
320 QCOMPARE(launcherModel->get(0)->pinned(), true);
321 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
323 // quicklist needs to transform to remove item. trigger it and check it item goes away
324 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
325 QCOMPARE(launcherModel->get(0)->pinned(), false);
327 // still needs to be here as the app is still here
328 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
330 appManager->removeApplication(0);
331 // Now it needs to go away
332 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
335 void testApplicationRunning() {
336 launcherModel->pin("abs-icon");
337 launcherModel->pin("no-icon");
339 QCOMPARE(launcherModel->get(0)->running(), true);
340 QCOMPARE(launcherModel->get(1)->running(), true);
342 appManager->stopApplication("abs-icon");
343 QCOMPARE(launcherModel->get(0)->running(), false);
344 QCOMPARE(launcherModel->get(1)->running(), true);
346 appManager->stopApplication("no-icon");
347 QCOMPARE(launcherModel->get(0)->running(), false);
348 QCOMPARE(launcherModel->get(1)->running(), false);
351 void testApplicationFocused() {
352 // all apps unfocused at beginning...
353 QCOMPARE(launcherModel->get(0)->focused(), false);
354 QCOMPARE(launcherModel->get(1)->focused(), false);
356 appManager->focusApplication("abs-icon");
357 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
358 QCOMPARE(launcherModel->get(0)->focused(), true);
359 QCOMPARE(launcherModel->get(1)->focused(), false);
361 appManager->focusApplication("no-icon");
362 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
363 QCOMPARE(launcherModel->get(0)->focused(), false);
364 QCOMPARE(launcherModel->get(1)->focused(), true);
367 void testClosingApps() {
368 // At the start there are 2 items. Let's pin one.
369 launcherModel->pin("abs-icon");
370 while (appManager->count() > 0) {
371 appManager->removeApplication(0);
373 // The pinned one needs to stay, the other needs to disappear
374 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
375 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
378 void testQuitMenuItem() {
379 // we have 2 apps running, both should have the Quit action in its quick list
380 QCOMPARE(launcherModel->rowCount(), 2);
382 // stop the second one keeping it pinned so that it doesn't go away
383 launcherModel->pin("no-icon");
384 appManager->stopApplication("no-icon");
386 // find the first Quit item, should be there
387 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
388 int quitActionIndex = -1;
389 for (int i = 0; i < model->rowCount(); ++i) {
390 if (model->get(i).actionId() == "stop_item") {
395 QVERIFY(quitActionIndex >= 0);
397 // find the second Quit item, should NOT be there, the app is stopped
398 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
399 int quitActionIndex2 = -1;
400 for (int i = 0; i < model2->rowCount(); ++i) {
401 if (model2->get(i).actionId() == "stop_item") {
402 quitActionIndex2 = i;
406 QVERIFY(quitActionIndex2 == -1);
408 // trigger the first quit item quicklist action
409 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
410 // first app should be gone...
411 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
412 // ... the second app (now at index 0) should still be there, pinned and stopped
413 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
414 QCOMPARE(launcherModel->get(0)->pinned(), true);
415 QCOMPARE(launcherModel->get(0)->running(), false);
418 void testGetUrlForAppId() {
419 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
420 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
421 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
422 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
423 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
424 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
427 void testIntrospection() {
428 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
429 QDBusReply<QString> reply = interface.call("Introspect");
430 QStringList nodes = extractNodes(reply.value());
431 QCOMPARE(nodes.count(), launcherModel->rowCount());
433 appManager->addApplication(new MockApp("foobar"));
434 reply = interface.call("Introspect");
435 nodes = extractNodes(reply.value());
436 QCOMPARE(nodes.contains("foobar"), true);
438 appManager->removeApplication(2);
439 reply = interface.call("Introspect");
440 nodes = extractNodes(reply.value());
441 QCOMPARE(nodes.contains("foobar"), false);
444 QStringList extractNodes(const QString &introspectionXml) {
445 QXmlStreamReader introspectReply(introspectionXml);
448 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
449 QXmlStreamReader::TokenType token = introspectReply.readNext();
451 if (token == QXmlStreamReader::StartElement) {
452 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
453 ret << introspectReply.attributes().value("name").toString();
460 void testCountEmblems() {
461 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
463 // Call GetAll on abs-icon
464 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
465 QDBusReply<QVariantMap> reply = interface.call("GetAll");
466 QVariantMap map = reply.value();
468 // Check that the alerting-status is still false, and the item on the upper side of the API
469 int index = launcherModel->findApplication("abs-icon");
470 QCOMPARE(index >= 0, true);
471 QVERIFY(launcherModel->get(index)->alerting() == false);
473 // Make sure GetAll returns a map with count and countVisible props
474 QCOMPARE(map.contains("count"), true);
475 QCOMPARE(map.contains("countVisible"), true);
477 // Make sure count is intitilized to 0 and non-visible
478 QCOMPARE(map.value("count").toInt(), 0);
479 QCOMPARE(map.value("countVisible").toBool(), false);
481 // Now make it visible and set it to 55 through D-Bus
482 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
483 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
485 // Fetch it again using GetAll
486 reply = interface.call("GetAll");
489 // Make sure values have changed on the D-Bus interface
490 QCOMPARE(map.value("count").toInt(), 55);
491 QCOMPARE(map.value("countVisible").toBool(), true);
493 // Finally check, that the change to "count" implicitly also set the alerting-state to true
494 QVERIFY(launcherModel->get(index)->alerting() == true);
497 void testCountEmblemAddsRemovesItem_data() {
498 QTest::addColumn<bool>("isPinned");
499 QTest::addColumn<bool>("isRunning");
500 QTest::addColumn<bool>("startWhenVisible");
501 QTest::newRow("not pinned, not running") << false << false << false;
502 QTest::newRow("pinned, not running") << true << false << false;
503 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
504 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
505 QTest::newRow("not pinned, running") << false << true << false;
506 QTest::newRow("pinned, running") << true << true << false;
509 void testCountEmblemAddsRemovesItem() {
510 QFETCH(bool, isPinned);
511 QFETCH(bool, isRunning);
512 QFETCH(bool, startWhenVisible);
514 // Make sure item is here as expected after init() and that count is not visible
515 int index = launcherModel->findApplication("abs-icon");
516 QCOMPARE(index == -1, false);
517 QCOMPARE(launcherModel->get(index)->countVisible(), false);
521 launcherModel->pin("abs-icon");
523 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
525 // Stop it if we need to
527 appManager->stopApplication("abs-icon");
529 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
532 // set the count emblem to visible
533 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
534 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
535 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
537 // Make sure item is here and that count is visible
538 index = launcherModel->findApplication("abs-icon");
539 QCOMPARE(index == -1, false);
540 QCOMPARE(launcherModel->get(index)->countVisible(), true);
542 if (!isRunning && startWhenVisible) {
543 appManager->addApplication(new MockApp("abs-icon"));
546 // Hide count emblem again
547 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
549 // Make sure item is shown/hidden as expected
550 index = launcherModel->findApplication("abs-icon");
551 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
555 // Check that the alerting-status is still false
556 int index = launcherModel->findApplication("abs-icon");
557 QCOMPARE(index >= 0, true);
558 QVERIFY(launcherModel->get(index)->alerting() == false);
560 // Call Alert() on "abs-icon"
561 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
562 interface.call("Alert");
564 // Check that the alerting-status is now true
565 QVERIFY(launcherModel->get(index)->alerting() == true);
568 void testRefreshAfterDeletedDesktopFiles_data() {
569 QTest::addColumn<bool>("deleted");
570 QTest::newRow("have .desktop files") << false;
571 QTest::newRow("deleted .desktop files") << true;
574 void testRefreshAfterDeletedDesktopFiles() {
575 QFETCH(bool, deleted);
578 launcherModel->pin("abs-icon");
579 launcherModel->pin("no-icon");
581 appManager->removeApplication(0);
582 appManager->removeApplication(0);
584 // "delete" the .desktop files
586 // In testing mode, the launcher searches the current dir for the sample .desktop file
587 // We can make that fail by changing the current dir
588 QDir::setCurrent("..");
592 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
593 QDBusReply<void> reply = interface.call("Refresh");
595 // Make sure the call to Refresh returned without error.
596 QCOMPARE(reply.isValid(), true);
598 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
601 void testSettings() {
602 GSettings *settings = launcherModel->m_settings;
603 QSignalSpy spy(launcherModel, &LauncherModel::hint);
605 // Nothing pinned at startup
606 QCOMPARE(settings->storedApplications().count(), 0);
609 launcherModel->pin("abs-icon");
610 launcherModel->pin("no-icon");
611 QCOMPARE(spy.count(), 0);
613 // Now settings should have 2 apps
614 QCOMPARE(settings->storedApplications().count(), 2);
617 appManager->removeApplication(0);
618 appManager->removeApplication(0);
620 // Now settings should have 2 apps
621 QCOMPARE(settings->storedApplications().count(), 2);
623 // Now remove 1 app through the backend, make sure one is still there
624 settings->simulateDConfChanged(QStringList() << "abs-icon");
625 QCOMPARE(settings->storedApplications().count(), 1);
626 QCOMPARE(spy.count(), 1);
628 // Check if it disappeared from the frontend too
629 QCOMPARE(launcherModel->rowCount(), 1);
631 // Add them back but in reverse order
632 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
633 QCOMPARE(launcherModel->rowCount(), 2);
634 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
635 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
636 QCOMPARE(spy.count(), 2);
639 void testAddSyncsToAS() {
640 // Make sure launcher and AS are in sync when we start the test
641 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
643 int oldCount = launcherModel->rowCount();
644 appManager->addApplication(new MockApp("rel-icon"));
645 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
646 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
649 void testRemoveSyncsToAS() {
650 // Make sure launcher and AS are in sync when we start the test
651 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
653 int oldCount = launcherModel->rowCount();
654 appManager->stopApplication("abs-icon");
655 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
656 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
659 void testMoveSyncsToAS() {
660 // Make sure launcher and AS are in sync when we start the test
661 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
663 for (int i = 0; i < launcherModel->rowCount(); i++) {
664 QString launcherAppId = launcherModel->get(i)->appId();
665 QString asAppId = getASConfig().at(i).value("id").toString();
666 QCOMPARE(launcherAppId, asAppId);
669 launcherModel->move(0, 1);
671 for (int i = 0; i < launcherModel->rowCount(); i++) {
672 QString launcherAppId = launcherModel->get(i)->appId();
673 QString asAppId = getASConfig().at(i).value("id").toString();
674 QCOMPARE(launcherAppId, asAppId);
678 void testCountChangeSyncsToAS() {
679 // Find the index of the abs-icon app
680 int index = launcherModel->findApplication("abs-icon");
682 // Make sure it's invisible and 0 at the beginning
683 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
684 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
686 // Change the count of the abs-icon app through D-Bus
687 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
688 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
689 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
691 // Make sure it changed to visible and 55
692 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
693 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
697QTEST_GUILESS_MAIN(LauncherModelTest)
698#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