on dbe8d46 help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
653 lines 27 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 QSignalSpy spy(launcherModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
414 // Call GetAll on abs-icon
415 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
416 QDBusReply<QVariantMap> reply = interface.call("GetAll");
417 QVariantMap map = reply.value();
419 // Check that the alerting-status is still false, and the item on the upper side of the API
420 int index = launcherModel->findApplication("abs-icon");
421 QCOMPARE(index >= 0, true);
422 QVERIFY(launcherModel->get(index)->alerting() == false);
424 // Make sure GetAll returns a map with count and countVisible props
425 QCOMPARE(map.contains("count"), true);
426 QCOMPARE(map.contains("countVisible"), true);
428 // Make sure count is intitilized to 0 and non-visible
429 QCOMPARE(map.value("count").toInt(), 0);
430 QCOMPARE(map.value("countVisible").toBool(), false);
432 // Now make it visible and set it to 55 through D-Bus
433 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
434 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
436 // Fetch it again using GetAll
437 reply = interface.call("GetAll");
438 map = reply.value();
440 // Make sure values have changed on the D-Bus interface
441 QCOMPARE(map.value("count").toInt(), 55);
442 QCOMPARE(map.value("countVisible").toBool(), true);
444 // Finally check, that the change to "count" implicitly also set the alerting-state to true
445 QVERIFY(launcherModel->get(index)->alerting() == true);
446 }
448 void testCountEmblemAddsRemovesItem_data() {
449 QTest::addColumn<bool>("isPinned");
450 QTest::addColumn<bool>("isRunning");
451 QTest::addColumn<bool>("startWhenVisible");
452 QTest::newRow("not pinned, not running") << false << false << false;
453 QTest::newRow("pinned, not running") << true << false << false;
454 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
455 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
456 QTest::newRow("not pinned, running") << false << true << false;
457 QTest::newRow("pinned, running") << true << true << false;
458 }
460 void testCountEmblemAddsRemovesItem() {
461 QFETCH(bool, isPinned);
462 QFETCH(bool, isRunning);
463 QFETCH(bool, startWhenVisible);
465 // Make sure item is here as expected after init() and that count is not visible
466 int index = launcherModel->findApplication("abs-icon");
467 QCOMPARE(index == -1, false);
468 QCOMPARE(launcherModel->get(index)->countVisible(), false);
470 // Pin if we need to
471 if (isPinned) {
472 launcherModel->pin("abs-icon");
473 }
474 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
476 // Stop it if we need to
477 if (!isRunning) {
478 appManager->stopApplication("abs-icon");
479 }
480 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
483 // set the count emblem to visible
484 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
485 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
486 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
488 // Make sure item is here and that count is visible
489 index = launcherModel->findApplication("abs-icon");
490 QCOMPARE(index == -1, false);
491 QCOMPARE(launcherModel->get(index)->countVisible(), true);
493 if (!isRunning && startWhenVisible) {
494 appManager->addApplication(new MockApp("abs-icon"));
495 }
497 // Hide count emblem again
498 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
500 // Make sure item is shown/hidden as expected
501 index = launcherModel->findApplication("abs-icon");
502 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
503 }
505 void testAlert() {
506 // Check that the alerting-status is still false
507 int index = launcherModel->findApplication("abs-icon");
508 QCOMPARE(index >= 0, true);
509 QVERIFY(launcherModel->get(index)->alerting() == false);
511 // Call Alert() on "abs-icon"
512 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
513 interface.call("Alert");
515 // Check that the alerting-status is now true
516 QVERIFY(launcherModel->get(index)->alerting() == true);
517 }
519 void testRefreshAfterDeletedDesktopFiles_data() {
520 QTest::addColumn<bool>("deleted");
521 QTest::newRow("have .desktop files") << false;
522 QTest::newRow("deleted .desktop files") << true;
523 }
525 void testRefreshAfterDeletedDesktopFiles() {
526 QFETCH(bool, deleted);
528 // pin both apps
529 launcherModel->pin("abs-icon");
530 launcherModel->pin("no-icon");
531 // close both apps
532 appManager->removeApplication(0);
533 appManager->removeApplication(0);
535 // "delete" the .desktop files
536 QString oldCurrent = QDir::currentPath();
537 if (deleted) {
538 // In testing mode, the launcher searches the current dir for the sample .desktop file
539 // We can make that fail by changing the current dir
540 QDir::setCurrent("..");
541 }
543 // Call refresh
544 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
545 QDBusReply<void> reply = interface.call("Refresh");
547 // Make sure the call to Refresh returned without error.
548 QCOMPARE(reply.isValid(), true);
550 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
552 // Restoring current dir
553 QDir::setCurrent(oldCurrent);
554 }
556 void testSettings() {
557 GSettings *settings = launcherModel->m_settings;
558 QSignalSpy spy(launcherModel, SIGNAL(hint()));
560 // Nothing pinned at startup
561 QCOMPARE(settings->storedApplications().count(), 0);
563 // pin both apps
564 launcherModel->pin("abs-icon");
565 launcherModel->pin("no-icon");
566 QCOMPARE(spy.count(), 0);
568 // Now settings should have 2 apps
569 QCOMPARE(settings->storedApplications().count(), 2);
571 // close both apps
572 appManager->removeApplication(0);
573 appManager->removeApplication(0);
575 // Now settings should have 2 apps
576 QCOMPARE(settings->storedApplications().count(), 2);
578 // Now remove 1 app through the backend, make sure one is still there
579 settings->simulateDConfChanged(QStringList() << "abs-icon");
580 QCOMPARE(settings->storedApplications().count(), 1);
581 QCOMPARE(spy.count(), 1);
583 // Check if it disappeared from the frontend too
584 QCOMPARE(launcherModel->rowCount(), 1);
586 // Add them back but in reverse order
587 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
588 QCOMPARE(launcherModel->rowCount(), 2);
589 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
590 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
591 QCOMPARE(spy.count(), 2);
592 }
594 void testAddSyncsToAS() {
595 // Make sure launcher and AS are in sync when we start the test
596 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
598 int oldCount = launcherModel->rowCount();
599 appManager->addApplication(new MockApp("rel-icon"));
600 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
601 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
602 }
604 void testRemoveSyncsToAS() {
605 // Make sure launcher and AS are in sync when we start the test
606 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
608 int oldCount = launcherModel->rowCount();
609 appManager->stopApplication("abs-icon");
610 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
611 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
612 }
614 void testMoveSyncsToAS() {
615 // Make sure launcher and AS are in sync when we start the test
616 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
618 for (int i = 0; i < launcherModel->rowCount(); i++) {
619 QString launcherAppId = launcherModel->get(i)->appId();
620 QString asAppId = getASConfig().at(i).value("id").toString();
621 QCOMPARE(launcherAppId, asAppId);
622 }
624 launcherModel->move(0, 1);
626 for (int i = 0; i < launcherModel->rowCount(); i++) {
627 QString launcherAppId = launcherModel->get(i)->appId();
628 QString asAppId = getASConfig().at(i).value("id").toString();
629 QCOMPARE(launcherAppId, asAppId);
630 }
631 }
633 void testCountChangeSyncsToAS() {
634 // Find the index of the abs-icon app
635 int index = launcherModel->findApplication("abs-icon");
637 // Make sure it's invisible and 0 at the beginning
638 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
639 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
641 // Change the count of the abs-icon app through D-Bus
642 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
643 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
644 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
646 // Make sure it changed to visible and 55
647 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
648 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
649 }
650};
652QTEST_GUILESS_MAIN(LauncherModelTest)
653#include "launchermodeltest.moc"