on b018d4e help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
669 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) { }
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::Stage stage() const override { return ApplicationInfoInterface::MainStage; }
50 ApplicationInfoInterface::State state() const override { return ApplicationInfoInterface::Running; }
51 bool focused() const override { return m_focused; }
52 QString splashTitle() const override { return QString(); }
53 QUrl splashImage() const override { return QUrl(); }
54 bool splashShowHeader() const override { return true; }
55 QColor splashColor() const override { return QColor(0,0,0,0); }
56 QColor splashColorHeader() const override { return QColor(0,0,0,0); }
57 QColor splashColorFooter() const override { return QColor(0,0,0,0); }
58 Qt::ScreenOrientations supportedOrientations() const override { return Qt::PortraitOrientation; }
59 bool rotatesWindowContents() const override { return false; }
60 bool isTouchApp() const override { return true; }
62 // Methods used for mocking (not in the interface)
63 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
64private:
65 QString m_appId;
66 bool m_focused;
67};
69// This is a mock, specifically to test the LauncherModel
70class MockAppManager: public unity::shell::application::ApplicationManagerInterface
72 Q_OBJECT
73public:
74 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
75 ~MockAppManager() {}
76 int rowCount(const QModelIndex &) const override { return m_list.count(); }
77 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
78 QString focusedApplicationId() const override {
79 Q_FOREACH(MockApp *app, m_list) {
80 if (app->focused()) return app->appId();
81 }
82 return QString();
83 }
84 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
85 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
86 Q_FOREACH(MockApp* app, m_list) {
87 if (app->appId() == appId) {
88 return app;
89 }
90 }
91 return nullptr;
92 }
93 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
94 bool stopApplication(const QString &appId) override {
95 Q_FOREACH(MockApp* app, m_list) {
96 if (app->appId() == appId) {
97 removeApplication(m_list.indexOf(app));
98 return true;
99 }
100 }
101 return false;
102 }
103 bool focusApplication(const QString &appId) override {
104 Q_FOREACH(MockApp* app, m_list) {
105 app->setFocused(app->appId() == appId);
106 }
107 Q_EMIT focusedApplicationIdChanged();
108 return true;
109 }
111 void unfocusCurrentApplication() override { }
113 void addApplication(MockApp *app) {
114 beginInsertRows(QModelIndex(), count(), count());
115 m_list.append(app);
116 endInsertRows();
117 }
118 void removeApplication(int index) {
119 beginRemoveRows(QModelIndex(), index, index);
120 m_list.takeAt(index)->deleteLater();
121 endRemoveRows();
122 }
123 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
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, &LauncherModel::dataChanged);
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 testApplicationRunning() {
303 launcherModel->pin("abs-icon");
304 launcherModel->pin("no-icon");
306 QCOMPARE(launcherModel->get(0)->running(), true);
307 QCOMPARE(launcherModel->get(1)->running(), true);
309 appManager->stopApplication("abs-icon");
310 QCOMPARE(launcherModel->get(0)->running(), false);
311 QCOMPARE(launcherModel->get(1)->running(), true);
313 appManager->stopApplication("no-icon");
314 QCOMPARE(launcherModel->get(0)->running(), false);
315 QCOMPARE(launcherModel->get(1)->running(), false);
316 }
318 void testApplicationFocused() {
319 // all apps unfocused at beginning...
320 QCOMPARE(launcherModel->get(0)->focused(), false);
321 QCOMPARE(launcherModel->get(1)->focused(), false);
323 appManager->focusApplication("abs-icon");
324 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
325 QCOMPARE(launcherModel->get(0)->focused(), true);
326 QCOMPARE(launcherModel->get(1)->focused(), false);
328 appManager->focusApplication("no-icon");
329 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
330 QCOMPARE(launcherModel->get(0)->focused(), false);
331 QCOMPARE(launcherModel->get(1)->focused(), true);
332 }
334 void testClosingApps() {
335 // At the start there are 2 items. Let's pin one.
336 launcherModel->pin("abs-icon");
337 while (appManager->count() > 0) {
338 appManager->removeApplication(0);
339 }
340 // The pinned one needs to stay, the other needs to disappear
341 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
342 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
343 }
345 void testQuitMenuItem() {
346 // we have 2 apps running, both should have the Quit action in its quick list
347 QCOMPARE(launcherModel->rowCount(), 2);
349 // stop the second one keeping it pinned so that it doesn't go away
350 launcherModel->pin("no-icon");
351 appManager->stopApplication("no-icon");
353 // find the first Quit item, should be there
354 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
355 int quitActionIndex = -1;
356 for (int i = 0; i < model->rowCount(); ++i) {
357 if (model->get(i).actionId() == "stop_item") {
358 quitActionIndex = i;
359 break;
360 }
361 }
362 QVERIFY(quitActionIndex >= 0);
364 // find the second Quit item, should NOT be there, the app is stopped
365 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
366 int quitActionIndex2 = -1;
367 for (int i = 0; i < model2->rowCount(); ++i) {
368 if (model2->get(i).actionId() == "stop_item") {
369 quitActionIndex2 = i;
370 break;
371 }
372 }
373 QVERIFY(quitActionIndex2 == -1);
375 // trigger the first quit item quicklist action
376 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
377 // first app should be gone...
378 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
379 // ... the second app (now at index 0) should still be there, pinned and stopped
380 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
381 QCOMPARE(launcherModel->get(0)->pinned(), true);
382 QCOMPARE(launcherModel->get(0)->running(), false);
383 }
385 void testGetUrlForAppId() {
386 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
387 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
388 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
389 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
390 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
391 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
392 }
394 void testIntrospection() {
395 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
396 QDBusReply<QString> reply = interface.call("Introspect");
397 QStringList nodes = extractNodes(reply.value());
398 QCOMPARE(nodes.count(), launcherModel->rowCount());
400 appManager->addApplication(new MockApp("foobar"));
401 reply = interface.call("Introspect");
402 nodes = extractNodes(reply.value());
403 QCOMPARE(nodes.contains("foobar"), true);
405 appManager->removeApplication(2);
406 reply = interface.call("Introspect");
407 nodes = extractNodes(reply.value());
408 QCOMPARE(nodes.contains("foobar"), false);
409 }
411 QStringList extractNodes(const QString &introspectionXml) {
412 QXmlStreamReader introspectReply(introspectionXml);
414 QStringList ret;
415 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
416 QXmlStreamReader::TokenType token = introspectReply.readNext();
418 if (token == QXmlStreamReader::StartElement) {
419 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
420 ret << introspectReply.attributes().value("name").toString();
421 }
422 }
423 }
424 return ret;
425 }
427 void testCountEmblems() {
428 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
430 // Call GetAll on abs-icon
431 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
432 QDBusReply<QVariantMap> reply = interface.call("GetAll");
433 QVariantMap map = reply.value();
435 // Check that the alerting-status is still false, and the item on the upper side of the API
436 int index = launcherModel->findApplication("abs-icon");
437 QCOMPARE(index >= 0, true);
438 QVERIFY(launcherModel->get(index)->alerting() == false);
440 // Make sure GetAll returns a map with count and countVisible props
441 QCOMPARE(map.contains("count"), true);
442 QCOMPARE(map.contains("countVisible"), true);
444 // Make sure count is intitilized to 0 and non-visible
445 QCOMPARE(map.value("count").toInt(), 0);
446 QCOMPARE(map.value("countVisible").toBool(), false);
448 // Now make it visible and set it to 55 through D-Bus
449 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
450 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
452 // Fetch it again using GetAll
453 reply = interface.call("GetAll");
454 map = reply.value();
456 // Make sure values have changed on the D-Bus interface
457 QCOMPARE(map.value("count").toInt(), 55);
458 QCOMPARE(map.value("countVisible").toBool(), true);
460 // Finally check, that the change to "count" implicitly also set the alerting-state to true
461 QVERIFY(launcherModel->get(index)->alerting() == true);
462 }
464 void testCountEmblemAddsRemovesItem_data() {
465 QTest::addColumn<bool>("isPinned");
466 QTest::addColumn<bool>("isRunning");
467 QTest::addColumn<bool>("startWhenVisible");
468 QTest::newRow("not pinned, not running") << false << false << false;
469 QTest::newRow("pinned, not running") << true << false << false;
470 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
471 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
472 QTest::newRow("not pinned, running") << false << true << false;
473 QTest::newRow("pinned, running") << true << true << false;
474 }
476 void testCountEmblemAddsRemovesItem() {
477 QFETCH(bool, isPinned);
478 QFETCH(bool, isRunning);
479 QFETCH(bool, startWhenVisible);
481 // Make sure item is here as expected after init() and that count is not visible
482 int index = launcherModel->findApplication("abs-icon");
483 QCOMPARE(index == -1, false);
484 QCOMPARE(launcherModel->get(index)->countVisible(), false);
486 // Pin if we need to
487 if (isPinned) {
488 launcherModel->pin("abs-icon");
489 }
490 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
492 // Stop it if we need to
493 if (!isRunning) {
494 appManager->stopApplication("abs-icon");
495 }
496 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
499 // set the count emblem to visible
500 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
501 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
502 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
504 // Make sure item is here and that count is visible
505 index = launcherModel->findApplication("abs-icon");
506 QCOMPARE(index == -1, false);
507 QCOMPARE(launcherModel->get(index)->countVisible(), true);
509 if (!isRunning && startWhenVisible) {
510 appManager->addApplication(new MockApp("abs-icon"));
511 }
513 // Hide count emblem again
514 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
516 // Make sure item is shown/hidden as expected
517 index = launcherModel->findApplication("abs-icon");
518 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
519 }
521 void testAlert() {
522 // Check that the alerting-status is still false
523 int index = launcherModel->findApplication("abs-icon");
524 QCOMPARE(index >= 0, true);
525 QVERIFY(launcherModel->get(index)->alerting() == false);
527 // Call Alert() on "abs-icon"
528 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
529 interface.call("Alert");
531 // Check that the alerting-status is now true
532 QVERIFY(launcherModel->get(index)->alerting() == true);
533 }
535 void testRefreshAfterDeletedDesktopFiles_data() {
536 QTest::addColumn<bool>("deleted");
537 QTest::newRow("have .desktop files") << false;
538 QTest::newRow("deleted .desktop files") << true;
539 }
541 void testRefreshAfterDeletedDesktopFiles() {
542 QFETCH(bool, deleted);
544 // pin both apps
545 launcherModel->pin("abs-icon");
546 launcherModel->pin("no-icon");
547 // close both apps
548 appManager->removeApplication(0);
549 appManager->removeApplication(0);
551 // "delete" the .desktop files
552 QString oldCurrent = QDir::currentPath();
553 if (deleted) {
554 // In testing mode, the launcher searches the current dir for the sample .desktop file
555 // We can make that fail by changing the current dir
556 QDir::setCurrent("..");
557 }
559 // Call refresh
560 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
561 QDBusReply<void> reply = interface.call("Refresh");
563 // Make sure the call to Refresh returned without error.
564 QCOMPARE(reply.isValid(), true);
566 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
568 // Restoring current dir
569 QDir::setCurrent(oldCurrent);
570 }
572 void testSettings() {
573 GSettings *settings = launcherModel->m_settings;
574 QSignalSpy spy(launcherModel, &LauncherModel::hint);
576 // Nothing pinned at startup
577 QCOMPARE(settings->storedApplications().count(), 0);
579 // pin both apps
580 launcherModel->pin("abs-icon");
581 launcherModel->pin("no-icon");
582 QCOMPARE(spy.count(), 0);
584 // Now settings should have 2 apps
585 QCOMPARE(settings->storedApplications().count(), 2);
587 // close both apps
588 appManager->removeApplication(0);
589 appManager->removeApplication(0);
591 // Now settings should have 2 apps
592 QCOMPARE(settings->storedApplications().count(), 2);
594 // Now remove 1 app through the backend, make sure one is still there
595 settings->simulateDConfChanged(QStringList() << "abs-icon");
596 QCOMPARE(settings->storedApplications().count(), 1);
597 QCOMPARE(spy.count(), 1);
599 // Check if it disappeared from the frontend too
600 QCOMPARE(launcherModel->rowCount(), 1);
602 // Add them back but in reverse order
603 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
604 QCOMPARE(launcherModel->rowCount(), 2);
605 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
606 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
607 QCOMPARE(spy.count(), 2);
608 }
610 void testAddSyncsToAS() {
611 // Make sure launcher and AS are in sync when we start the test
612 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
614 int oldCount = launcherModel->rowCount();
615 appManager->addApplication(new MockApp("rel-icon"));
616 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
617 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
618 }
620 void testRemoveSyncsToAS() {
621 // Make sure launcher and AS are in sync when we start the test
622 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
624 int oldCount = launcherModel->rowCount();
625 appManager->stopApplication("abs-icon");
626 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
627 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
628 }
630 void testMoveSyncsToAS() {
631 // Make sure launcher and AS are in sync when we start the test
632 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
634 for (int i = 0; i < launcherModel->rowCount(); i++) {
635 QString launcherAppId = launcherModel->get(i)->appId();
636 QString asAppId = getASConfig().at(i).value("id").toString();
637 QCOMPARE(launcherAppId, asAppId);
638 }
640 launcherModel->move(0, 1);
642 for (int i = 0; i < launcherModel->rowCount(); i++) {
643 QString launcherAppId = launcherModel->get(i)->appId();
644 QString asAppId = getASConfig().at(i).value("id").toString();
645 QCOMPARE(launcherAppId, asAppId);
646 }
647 }
649 void testCountChangeSyncsToAS() {
650 // Find the index of the abs-icon app
651 int index = launcherModel->findApplication("abs-icon");
653 // Make sure it's invisible and 0 at the beginning
654 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
655 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
657 // Change the count of the abs-icon app through D-Bus
658 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
659 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
660 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
662 // Make sure it changed to visible and 55
663 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
664 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
665 }
666};
668QTEST_GUILESS_MAIN(LauncherModelTest)
669#include "launchermodeltest.moc"