on 32ba487 help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
637 lines 26 kB history raw
1/*
2 * Copyright 2013-2015 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
20// unity-api
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"
27#include "gsettings.h"
28#include "asadapter.h"
29#include "AccountsServiceDBusAdaptor.h"
31#include <QtTest>
32#include <QDBusInterface>
33#include <QDBusReply>
34#include <QDomDocument>
36// This is a mock, specifically to test the LauncherModel
37class MockApp: public unity::shell::application::ApplicationInfoInterface
39 Q_OBJECT
40public:
41 MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
42 QString appId() const override { return m_appId; }
43 QString name() const override { return "mock"; }
44 QString comment() const override { return "this is a mock"; }
45 QUrl icon() const override { return QUrl(); }
46 ApplicationInfoInterface::Stage stage() const override { return ApplicationInfoInterface::MainStage; }
47 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
48 bool focused() const override { return m_focused; }
49 QString splashTitle() const override { return QString(); }
50 QUrl splashImage() const override { return QUrl(); }
51 bool splashShowHeader() const override { return true; }
52 QColor splashColor() const override { return QColor(0,0,0,0); }
53 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
54 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
55 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
56 bool rotatesWindowContents() const override { return false; }
58 // Methods used for mocking (not in the interface)
59 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
60private:
61 QString m_appId;
62 bool m_focused;
63};
65// This is a mock, specifically to test the LauncherModel
66class MockAppManager: public unity::shell::application::ApplicationManagerInterface
68 Q_OBJECT
69public:
70 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
71 ~MockAppManager() {}
72 int rowCount(const QModelIndex &) const override { return m_list.count(); }
73 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
74 QString focusedApplicationId() const override {
75 Q_FOREACH(MockApp *app, m_list) {
76 if (app->focused()) return app->appId();
77 }
78 return QString();
79 }
80 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
81 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
82 Q_FOREACH(MockApp* app, m_list) {
83 if (app->appId() == appId) {
84 return app;
85 }
86 }
87 return nullptr;
88 }
89 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
90 bool stopApplication(const QString &appId) override {
91 Q_FOREACH(MockApp* app, m_list) {
92 if (app->appId() == appId) {
93 removeApplication(m_list.indexOf(app));
94 return true;
95 }
96 }
97 return false;
98 }
99 bool focusApplication(const QString &appId) override {
100 Q_FOREACH(MockApp* app, m_list) {
101 app->setFocused(app->appId() == appId);
102 }
103 Q_EMIT focusedApplicationIdChanged();
104 return true;
105 }
107 void unfocusCurrentApplication() override { }
109 void addApplication(MockApp *app) {
110 beginInsertRows(QModelIndex(), count(), count());
111 m_list.append(app);
112 endInsertRows();
113 }
114 void removeApplication(int index) {
115 beginRemoveRows(QModelIndex(), index, index);
116 m_list.takeAt(index)->deleteLater();
117 endRemoveRows();
118 }
119 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
120 bool suspended() const override { return false; }
121 void setSuspended(bool) override {}
122 bool forceDashActive() const override { return false; }
123 void setForceDashActive(bool) override {}
125private:
126 QList<MockApp*> m_list;
127};
129class LauncherModelTest : public QObject
131 Q_OBJECT
133private:
134 LauncherModel *launcherModel;
135 MockAppManager *appManager;
137 QList<QVariantMap> getASConfig() {
138 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
139 return as->getUserProperty("", "", "LauncherItems").value<QList<QVariantMap>>();
140 }
142private Q_SLOTS:
144 void initTestCase() {
145 launcherModel = new LauncherModel(this);
146 QCoreApplication::processEvents(); // to let the model register on DBus
147 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
149 appManager = new MockAppManager(this);
150 launcherModel->setApplicationManager(appManager);
151 }
153 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
154 void init() {
155 appManager->addApplication(new MockApp("abs-icon"));
156 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
158 appManager->addApplication(new MockApp("no-icon"));
159 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
161 launcherModel->m_settings->setStoredApplications(QStringList());
162 }
164 // Removing apps from appmanager and launcher as pinned ones would stick
165 void cleanup() {
166 while (appManager->count() > 0) {
167 appManager->removeApplication(0);
168 }
169 while (launcherModel->rowCount(QModelIndex()) > 0) {
170 launcherModel->requestRemove(launcherModel->get(0)->appId());
171 }
172 }
174 void testMove() {
175 QCOMPARE(launcherModel->get(0)->pinned(), false);
176 QCOMPARE(launcherModel->get(1)->pinned(), false);
178 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
179 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
180 launcherModel->move(1, 0);
182 QCOMPARE(item0BeforeMove, launcherModel->get(1));
183 QCOMPARE(item1BeforeMove, launcherModel->get(0));
185 // moved item must be pinned now
186 QCOMPARE(item0BeforeMove->pinned(), false);
187 QCOMPARE(item1BeforeMove->pinned(), true);
188 }
190 void testPinning() {
191 QSignalSpy spy(launcherModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
192 QCOMPARE(launcherModel->get(0)->pinned(), false);
193 QCOMPARE(launcherModel->get(1)->pinned(), false);
194 launcherModel->pin(launcherModel->get(0)->appId());
195 QCOMPARE(launcherModel->get(0)->pinned(), true);
196 QCOMPARE(launcherModel->get(1)->pinned(), false);
197 QCOMPARE(spy.count() > 0, true);
198 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
200 // App should be pinned now
201 spy.clear();
202 launcherModel->requestRemove(launcherModel->get(0)->appId());
203 QCOMPARE(launcherModel->get(0)->pinned(), false);
204 QCOMPARE(launcherModel->get(1)->pinned(), false);
205 QCOMPARE(spy.count(), 1);
206 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
208 // Now that the app is unpinned, nothing should change and the signal should not be emitted
209 spy.clear();
210 launcherModel->requestRemove(launcherModel->get(0)->appId());
211 QCOMPARE(launcherModel->get(0)->pinned(), false);
212 QCOMPARE(launcherModel->get(1)->pinned(), false);
213 QCOMPARE(spy.count(), 0);
214 }
216 void testRemove_data() {
218 QTest::addColumn<bool>("pinned");
219 QTest::addColumn<bool>("running");
221 QTest::newRow("non-pinned, running") << false << true;
222 QTest::newRow("pinned, running") << true << true;
223 QTest::newRow("pinned, non-running") << true << false;
224 }
226 void testRemove() {
227 QFETCH(bool, pinned);
228 QFETCH(bool, running);
230 // In the beginning we always have two items
231 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
233 // pin one if required
234 if (pinned) {
235 launcherModel->pin("abs-icon");
236 }
238 // stop it if required
239 if (!running) {
240 appManager->stopApplication("abs-icon");
241 }
243 // Now remove it
244 launcherModel->requestRemove("abs-icon");
246 if (running) {
247 // both apps are running, both apps must still be here
248 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
250 // Item must be unpinned now
251 int index = launcherModel->findApplication("abs-icon");
252 QCOMPARE(launcherModel->get(index)->pinned(), false);
254 } else if (pinned) {
255 // Item 1 must go away, item 0 is here to stay
256 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
257 }
259 // done our checks. now stop the app if was still running
260 if (running) {
261 appManager->stopApplication("abs-icon");
262 }
264 // It needs to go away in any case now
265 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
266 }
268 void testQuickListPinningRemoving() {
269 // we start with 2 unpinned items
270 QCOMPARE(launcherModel->get(0)->pinned(), false);
271 QCOMPARE(launcherModel->get(1)->pinned(), false);
272 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
274 // find the Pin item in the quicklist
275 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
276 int pinActionIndex = -1;
277 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
278 if (model->get(i).actionId() == "pin_item") {
279 pinActionIndex = i;
280 break;
281 }
282 }
283 QVERIFY(pinActionIndex >= 0);
285 // trigger pin item quicklist action => Item must be pinned now.
286 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
287 QCOMPARE(launcherModel->get(0)->pinned(), true);
288 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
290 // quicklist needs to transform to remove item. trigger it and check it item goes away
291 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
292 QCOMPARE(launcherModel->get(0)->pinned(), false);
294 // still needs to be here as the app is still here
295 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
296 // close the app
297 appManager->removeApplication(0);
298 // Now it needs to go away
299 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
300 }
302 void testApplicationFocused() {
303 // all apps unfocused at beginning...
304 QCOMPARE(launcherModel->get(0)->focused(), false);
305 QCOMPARE(launcherModel->get(1)->focused(), false);
307 appManager->focusApplication("abs-icon");
308 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
309 QCOMPARE(launcherModel->get(0)->focused(), true);
310 QCOMPARE(launcherModel->get(1)->focused(), false);
312 appManager->focusApplication("no-icon");
313 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
314 QCOMPARE(launcherModel->get(0)->focused(), false);
315 QCOMPARE(launcherModel->get(1)->focused(), true);
316 }
318 void testClosingApps() {
319 // At the start there are 2 items. Let's pin one.
320 launcherModel->pin("abs-icon");
321 while (appManager->count() > 0) {
322 appManager->removeApplication(0);
323 }
324 // The pinned one needs to stay, the other needs to disappear
325 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
326 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
327 }
329 void testQuitMenuItem() {
330 // we have 2 apps running, both should have the Quit action in its quick list
331 QCOMPARE(launcherModel->rowCount(), 2);
333 // stop the second one keeping it pinned so that it doesn't go away
334 launcherModel->pin("no-icon");
335 appManager->stopApplication("no-icon");
337 // find the first Quit item, should be there
338 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
339 int quitActionIndex = -1;
340 for (int i = 0; i < model->rowCount(); ++i) {
341 if (model->get(i).actionId() == "stop_item") {
342 quitActionIndex = i;
343 break;
344 }
345 }
346 QVERIFY(quitActionIndex >= 0);
348 // find the second Quit item, should NOT be there, the app is stopped
349 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
350 int quitActionIndex2 = -1;
351 for (int i = 0; i < model2->rowCount(); ++i) {
352 if (model2->get(i).actionId() == "stop_item") {
353 quitActionIndex2 = i;
354 break;
355 }
356 }
357 QVERIFY(quitActionIndex2 == -1);
359 // trigger the first quit item quicklist action
360 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
361 // first app should be gone...
362 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
363 // ... the second app (now at index 0) should still be there, pinned and stopped
364 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
365 QCOMPARE(launcherModel->get(0)->pinned(), true);
366 QCOMPARE(launcherModel->get(0)->running(), false);
367 }
369 void testGetUrlForAppId() {
370 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
371 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
372 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
373 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
374 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
375 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
376 }
378 void testIntrospection() {
379 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
380 QDBusReply<QString> reply = interface.call("Introspect");
381 QStringList nodes = extractNodes(reply.value());
382 QCOMPARE(nodes.count(), launcherModel->rowCount());
384 appManager->addApplication(new MockApp("foobar"));
385 reply = interface.call("Introspect");
386 nodes = extractNodes(reply.value());
387 QCOMPARE(nodes.contains("foobar"), true);
389 appManager->removeApplication(2);
390 reply = interface.call("Introspect");
391 nodes = extractNodes(reply.value());
392 QCOMPARE(nodes.contains("foobar"), false);
393 }
395 QStringList extractNodes(const QString &introspectionXml) {
396 QXmlStreamReader introspectReply(introspectionXml);
398 QStringList ret;
399 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
400 QXmlStreamReader::TokenType token = introspectReply.readNext();
402 if (token == QXmlStreamReader::StartElement) {
403 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
404 ret << introspectReply.attributes().value("name").toString();
405 }
406 }
407 }
408 return ret;
409 }
411 void testCountEmblems() {
412 // Call GetAll on abs-icon
413 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
414 QDBusReply<QVariantMap> reply = interface.call("GetAll");
415 QVariantMap map = reply.value();
417 // Make sure GetAll returns a map with count and countVisible props
418 QCOMPARE(map.contains("count"), true);
419 QCOMPARE(map.contains("countVisible"), true);
421 // Make sure count is intitilized to 0 and non-visible
422 QCOMPARE(map.value("count").toInt(), 0);
423 QCOMPARE(map.value("countVisible").toBool(), false);
425 // Now make it visible and set it to 55 through D-Bus
426 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
427 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
429 // Fetch it again using GetAll
430 reply = interface.call("GetAll");
431 map = reply.value();
433 // Make sure values have changed on the D-Bus interface
434 QCOMPARE(map.value("count").toInt(), 55);
435 QCOMPARE(map.value("countVisible").toBool(), true);
437 // Now the item on the upper side of the API
438 int index = launcherModel->findApplication("abs-icon");
439 QCOMPARE(index >= 0, true);
441 // And make sure values have changed there as well
442 QCOMPARE(launcherModel->get(index)->countVisible(), true);
443 QCOMPARE(launcherModel->get(index)->count(), 55);
444 }
446 void testCountEmblemAddsRemovesItem_data() {
447 QTest::addColumn<bool>("isPinned");
448 QTest::addColumn<bool>("isRunning");
449 QTest::addColumn<bool>("startWhenVisible");
450 QTest::newRow("not pinned, not running") << false << false << false;
451 QTest::newRow("pinned, not running") << true << false << false;
452 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
453 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
454 QTest::newRow("not pinned, running") << false << true << false;
455 QTest::newRow("pinned, running") << true << true << false;
456 }
458 void testCountEmblemAddsRemovesItem() {
459 QFETCH(bool, isPinned);
460 QFETCH(bool, isRunning);
461 QFETCH(bool, startWhenVisible);
463 // Make sure item is here as expected after init() and that count is not visible
464 int index = launcherModel->findApplication("abs-icon");
465 QCOMPARE(index == -1, false);
466 QCOMPARE(launcherModel->get(index)->countVisible(), false);
468 // Pin if we need to
469 if (isPinned) {
470 launcherModel->pin("abs-icon");
471 }
472 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
474 // Stop it if we need to
475 if (!isRunning) {
476 appManager->stopApplication("abs-icon");
477 }
478 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
481 // set the count emblem to visible
482 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
483 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
484 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
486 // Make sure item is here and that count is visible
487 index = launcherModel->findApplication("abs-icon");
488 QCOMPARE(index == -1, false);
489 QCOMPARE(launcherModel->get(index)->countVisible(), true);
491 if (!isRunning && startWhenVisible) {
492 appManager->addApplication(new MockApp("abs-icon"));
493 }
495 // Hide count emblem again
496 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
498 // Make sure item is shown/hidden as expected
499 index = launcherModel->findApplication("abs-icon");
500 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
501 }
503 void testRefreshAfterDeletedDesktopFiles_data() {
504 QTest::addColumn<bool>("deleted");
505 QTest::newRow("have .desktop files") << false;
506 QTest::newRow("deleted .desktop files") << true;
507 }
509 void testRefreshAfterDeletedDesktopFiles() {
510 QFETCH(bool, deleted);
512 // pin both apps
513 launcherModel->pin("abs-icon");
514 launcherModel->pin("no-icon");
515 // close both apps
516 appManager->removeApplication(0);
517 appManager->removeApplication(0);
519 // "delete" the .desktop files
520 QString oldCurrent = QDir::currentPath();
521 if (deleted) {
522 // In testing mode, the launcher searches the current dir for the sample .desktop file
523 // We can make that fail by changing the current dir
524 QDir::setCurrent("..");
525 }
527 // Call refresh
528 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
529 QDBusReply<void> reply = interface.call("Refresh");
531 // Make sure the call to Refresh returned without error.
532 QCOMPARE(reply.isValid(), true);
534 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
536 // Restoring current dir
537 QDir::setCurrent(oldCurrent);
538 }
540 void testSettings() {
541 GSettings *settings = launcherModel->m_settings;
542 QSignalSpy spy(launcherModel, SIGNAL(hint()));
544 // Nothing pinned at startup
545 QCOMPARE(settings->storedApplications().count(), 0);
547 // pin both apps
548 launcherModel->pin("abs-icon");
549 launcherModel->pin("no-icon");
550 QCOMPARE(spy.count(), 0);
552 // Now settings should have 2 apps
553 QCOMPARE(settings->storedApplications().count(), 2);
555 // close both apps
556 appManager->removeApplication(0);
557 appManager->removeApplication(0);
559 // Now settings should have 2 apps
560 QCOMPARE(settings->storedApplications().count(), 2);
562 // Now remove 1 app through the backend, make sure one is still there
563 settings->simulateDConfChanged(QStringList() << "abs-icon");
564 QCOMPARE(settings->storedApplications().count(), 1);
565 QCOMPARE(spy.count(), 1);
567 // Check if it disappeared from the frontend too
568 QCOMPARE(launcherModel->rowCount(), 1);
570 // Add them back but in reverse order
571 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
572 QCOMPARE(launcherModel->rowCount(), 2);
573 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
574 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
575 QCOMPARE(spy.count(), 2);
576 }
578 void testAddSyncsToAS() {
579 // Make sure launcher and AS are in sync when we start the test
580 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
582 int oldCount = launcherModel->rowCount();
583 appManager->addApplication(new MockApp("rel-icon"));
584 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
585 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
586 }
588 void testRemoveSyncsToAS() {
589 // Make sure launcher and AS are in sync when we start the test
590 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
592 int oldCount = launcherModel->rowCount();
593 appManager->stopApplication("abs-icon");
594 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
595 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
596 }
598 void testMoveSyncsToAS() {
599 // Make sure launcher and AS are in sync when we start the test
600 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
602 for (int i = 0; i < launcherModel->rowCount(); i++) {
603 QString launcherAppId = launcherModel->get(i)->appId();
604 QString asAppId = getASConfig().at(i).value("id").toString();
605 QCOMPARE(launcherAppId, asAppId);
606 }
608 launcherModel->move(0, 1);
610 for (int i = 0; i < launcherModel->rowCount(); i++) {
611 QString launcherAppId = launcherModel->get(i)->appId();
612 QString asAppId = getASConfig().at(i).value("id").toString();
613 QCOMPARE(launcherAppId, asAppId);
614 }
615 }
617 void testCountChangeSyncsToAS() {
618 // Find the index of the abs-icon app
619 int index = launcherModel->findApplication("abs-icon");
621 // Make sure it's invisible and 0 at the beginning
622 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
623 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
625 // Change the count of the abs-icon app through D-Bus
626 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
627 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
628 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
630 // Make sure it changed to visible and 55
631 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
632 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
633 }
634};
636QTEST_GUILESS_MAIN(LauncherModelTest)
637#include "launchermodeltest.moc"