on b83f384 help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
671 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; }
61 bool canSuspend() const override { return true; }
62 void setCanSuspend(bool) override {}
64 // Methods used for mocking (not in the interface)
65 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
66private:
67 QString m_appId;
68 bool m_focused;
69};
71// This is a mock, specifically to test the LauncherModel
72class MockAppManager: public unity::shell::application::ApplicationManagerInterface
74 Q_OBJECT
75public:
76 MockAppManager(QObject *parent = 0): ApplicationManagerInterface(parent) {}
77 ~MockAppManager() {}
78 int rowCount(const QModelIndex &) const override { return m_list.count(); }
79 QVariant data(const QModelIndex &, int ) const override { return QVariant(); }
80 QString focusedApplicationId() const override {
81 Q_FOREACH(MockApp *app, m_list) {
82 if (app->focused()) return app->appId();
83 }
84 return QString();
85 }
86 unity::shell::application::ApplicationInfoInterface *get(int index) const override { return m_list.at(index); }
87 unity::shell::application::ApplicationInfoInterface *findApplication(const QString &appId) const override {
88 Q_FOREACH(MockApp* app, m_list) {
89 if (app->appId() == appId) {
90 return app;
91 }
92 }
93 return nullptr;
94 }
95 unity::shell::application::ApplicationInfoInterface *startApplication(const QString &, const QStringList &) override { return nullptr; }
96 bool stopApplication(const QString &appId) override {
97 Q_FOREACH(MockApp* app, m_list) {
98 if (app->appId() == appId) {
99 removeApplication(m_list.indexOf(app));
100 return true;
101 }
102 }
103 return false;
104 }
105 bool focusApplication(const QString &appId) override {
106 Q_FOREACH(MockApp* app, m_list) {
107 app->setFocused(app->appId() == appId);
108 }
109 Q_EMIT focusedApplicationIdChanged();
110 return true;
111 }
113 void unfocusCurrentApplication() override { }
115 void addApplication(MockApp *app) {
116 beginInsertRows(QModelIndex(), count(), count());
117 m_list.append(app);
118 endInsertRows();
119 }
120 void removeApplication(int index) {
121 beginRemoveRows(QModelIndex(), index, index);
122 m_list.takeAt(index)->deleteLater();
123 endRemoveRows();
124 }
125 bool requestFocusApplication(const QString &appId) override { Q_UNUSED(appId); return true; }
127private:
128 QList<MockApp*> m_list;
129};
131class LauncherModelTest : public QObject
133 Q_OBJECT
135private:
136 LauncherModel *launcherModel;
137 MockAppManager *appManager;
139 QList<QVariantMap> getASConfig() {
140 AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
141 return as->getUserProperty("", "", "LauncherItems").value<QList<QVariantMap>>();
142 }
144private Q_SLOTS:
146 void initTestCase() {
147 launcherModel = new LauncherModel(this);
148 QCoreApplication::processEvents(); // to let the model register on DBus
149 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
151 appManager = new MockAppManager(this);
152 launcherModel->setApplicationManager(appManager);
153 }
155 // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
156 void init() {
157 appManager->addApplication(new MockApp("abs-icon"));
158 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
160 appManager->addApplication(new MockApp("no-icon"));
161 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
163 launcherModel->m_settings->setStoredApplications(QStringList());
164 }
166 // Removing apps from appmanager and launcher as pinned ones would stick
167 void cleanup() {
168 while (appManager->count() > 0) {
169 appManager->removeApplication(0);
170 }
171 while (launcherModel->rowCount(QModelIndex()) > 0) {
172 launcherModel->requestRemove(launcherModel->get(0)->appId());
173 }
174 }
176 void testMove() {
177 QCOMPARE(launcherModel->get(0)->pinned(), false);
178 QCOMPARE(launcherModel->get(1)->pinned(), false);
180 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
181 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
182 launcherModel->move(1, 0);
184 QCOMPARE(item0BeforeMove, launcherModel->get(1));
185 QCOMPARE(item1BeforeMove, launcherModel->get(0));
187 // moved item must be pinned now
188 QCOMPARE(item0BeforeMove->pinned(), false);
189 QCOMPARE(item1BeforeMove->pinned(), true);
190 }
192 void testPinning() {
193 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
194 QCOMPARE(launcherModel->get(0)->pinned(), false);
195 QCOMPARE(launcherModel->get(1)->pinned(), false);
196 launcherModel->pin(launcherModel->get(0)->appId());
197 QCOMPARE(launcherModel->get(0)->pinned(), true);
198 QCOMPARE(launcherModel->get(1)->pinned(), false);
199 QCOMPARE(spy.count() > 0, true);
200 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
202 // App should be pinned now
203 spy.clear();
204 launcherModel->requestRemove(launcherModel->get(0)->appId());
205 QCOMPARE(launcherModel->get(0)->pinned(), false);
206 QCOMPARE(launcherModel->get(1)->pinned(), false);
207 QCOMPARE(spy.count(), 1);
208 QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
210 // Now that the app is unpinned, nothing should change and the signal should not be emitted
211 spy.clear();
212 launcherModel->requestRemove(launcherModel->get(0)->appId());
213 QCOMPARE(launcherModel->get(0)->pinned(), false);
214 QCOMPARE(launcherModel->get(1)->pinned(), false);
215 QCOMPARE(spy.count(), 0);
216 }
218 void testRemove_data() {
220 QTest::addColumn<bool>("pinned");
221 QTest::addColumn<bool>("running");
223 QTest::newRow("non-pinned, running") << false << true;
224 QTest::newRow("pinned, running") << true << true;
225 QTest::newRow("pinned, non-running") << true << false;
226 }
228 void testRemove() {
229 QFETCH(bool, pinned);
230 QFETCH(bool, running);
232 // In the beginning we always have two items
233 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
235 // pin one if required
236 if (pinned) {
237 launcherModel->pin("abs-icon");
238 }
240 // stop it if required
241 if (!running) {
242 appManager->stopApplication("abs-icon");
243 }
245 // Now remove it
246 launcherModel->requestRemove("abs-icon");
248 if (running) {
249 // both apps are running, both apps must still be here
250 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
252 // Item must be unpinned now
253 int index = launcherModel->findApplication("abs-icon");
254 QCOMPARE(launcherModel->get(index)->pinned(), false);
256 } else if (pinned) {
257 // Item 1 must go away, item 0 is here to stay
258 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
259 }
261 // done our checks. now stop the app if was still running
262 if (running) {
263 appManager->stopApplication("abs-icon");
264 }
266 // It needs to go away in any case now
267 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
268 }
270 void testQuickListPinningRemoving() {
271 // we start with 2 unpinned items
272 QCOMPARE(launcherModel->get(0)->pinned(), false);
273 QCOMPARE(launcherModel->get(1)->pinned(), false);
274 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
276 // find the Pin item in the quicklist
277 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
278 int pinActionIndex = -1;
279 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
280 if (model->get(i).actionId() == "pin_item") {
281 pinActionIndex = i;
282 break;
283 }
284 }
285 QVERIFY(pinActionIndex >= 0);
287 // trigger pin item quicklist action => Item must be pinned now.
288 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
289 QCOMPARE(launcherModel->get(0)->pinned(), true);
290 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
292 // quicklist needs to transform to remove item. trigger it and check it item goes away
293 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
294 QCOMPARE(launcherModel->get(0)->pinned(), false);
296 // still needs to be here as the app is still here
297 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
298 // close the app
299 appManager->removeApplication(0);
300 // Now it needs to go away
301 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
302 }
304 void testApplicationRunning() {
305 launcherModel->pin("abs-icon");
306 launcherModel->pin("no-icon");
308 QCOMPARE(launcherModel->get(0)->running(), true);
309 QCOMPARE(launcherModel->get(1)->running(), true);
311 appManager->stopApplication("abs-icon");
312 QCOMPARE(launcherModel->get(0)->running(), false);
313 QCOMPARE(launcherModel->get(1)->running(), true);
315 appManager->stopApplication("no-icon");
316 QCOMPARE(launcherModel->get(0)->running(), false);
317 QCOMPARE(launcherModel->get(1)->running(), false);
318 }
320 void testApplicationFocused() {
321 // all apps unfocused at beginning...
322 QCOMPARE(launcherModel->get(0)->focused(), false);
323 QCOMPARE(launcherModel->get(1)->focused(), false);
325 appManager->focusApplication("abs-icon");
326 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
327 QCOMPARE(launcherModel->get(0)->focused(), true);
328 QCOMPARE(launcherModel->get(1)->focused(), false);
330 appManager->focusApplication("no-icon");
331 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
332 QCOMPARE(launcherModel->get(0)->focused(), false);
333 QCOMPARE(launcherModel->get(1)->focused(), true);
334 }
336 void testClosingApps() {
337 // At the start there are 2 items. Let's pin one.
338 launcherModel->pin("abs-icon");
339 while (appManager->count() > 0) {
340 appManager->removeApplication(0);
341 }
342 // The pinned one needs to stay, the other needs to disappear
343 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
344 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
345 }
347 void testQuitMenuItem() {
348 // we have 2 apps running, both should have the Quit action in its quick list
349 QCOMPARE(launcherModel->rowCount(), 2);
351 // stop the second one keeping it pinned so that it doesn't go away
352 launcherModel->pin("no-icon");
353 appManager->stopApplication("no-icon");
355 // find the first Quit item, should be there
356 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
357 int quitActionIndex = -1;
358 for (int i = 0; i < model->rowCount(); ++i) {
359 if (model->get(i).actionId() == "stop_item") {
360 quitActionIndex = i;
361 break;
362 }
363 }
364 QVERIFY(quitActionIndex >= 0);
366 // find the second Quit item, should NOT be there, the app is stopped
367 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
368 int quitActionIndex2 = -1;
369 for (int i = 0; i < model2->rowCount(); ++i) {
370 if (model2->get(i).actionId() == "stop_item") {
371 quitActionIndex2 = i;
372 break;
373 }
374 }
375 QVERIFY(quitActionIndex2 == -1);
377 // trigger the first quit item quicklist action
378 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
379 // first app should be gone...
380 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
381 // ... the second app (now at index 0) should still be there, pinned and stopped
382 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
383 QCOMPARE(launcherModel->get(0)->pinned(), true);
384 QCOMPARE(launcherModel->get(0)->running(), false);
385 }
387 void testGetUrlForAppId() {
388 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
389 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
390 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
391 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
392 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
393 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
394 }
396 void testIntrospection() {
397 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
398 QDBusReply<QString> reply = interface.call("Introspect");
399 QStringList nodes = extractNodes(reply.value());
400 QCOMPARE(nodes.count(), launcherModel->rowCount());
402 appManager->addApplication(new MockApp("foobar"));
403 reply = interface.call("Introspect");
404 nodes = extractNodes(reply.value());
405 QCOMPARE(nodes.contains("foobar"), true);
407 appManager->removeApplication(2);
408 reply = interface.call("Introspect");
409 nodes = extractNodes(reply.value());
410 QCOMPARE(nodes.contains("foobar"), false);
411 }
413 QStringList extractNodes(const QString &introspectionXml) {
414 QXmlStreamReader introspectReply(introspectionXml);
416 QStringList ret;
417 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
418 QXmlStreamReader::TokenType token = introspectReply.readNext();
420 if (token == QXmlStreamReader::StartElement) {
421 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
422 ret << introspectReply.attributes().value("name").toString();
423 }
424 }
425 }
426 return ret;
427 }
429 void testCountEmblems() {
430 QSignalSpy spy(launcherModel, &LauncherModel::dataChanged);
432 // Call GetAll on abs-icon
433 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
434 QDBusReply<QVariantMap> reply = interface.call("GetAll");
435 QVariantMap map = reply.value();
437 // Check that the alerting-status is still false, and the item on the upper side of the API
438 int index = launcherModel->findApplication("abs-icon");
439 QCOMPARE(index >= 0, true);
440 QVERIFY(launcherModel->get(index)->alerting() == false);
442 // Make sure GetAll returns a map with count and countVisible props
443 QCOMPARE(map.contains("count"), true);
444 QCOMPARE(map.contains("countVisible"), true);
446 // Make sure count is intitilized to 0 and non-visible
447 QCOMPARE(map.value("count").toInt(), 0);
448 QCOMPARE(map.value("countVisible").toBool(), false);
450 // Now make it visible and set it to 55 through D-Bus
451 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
452 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
454 // Fetch it again using GetAll
455 reply = interface.call("GetAll");
456 map = reply.value();
458 // Make sure values have changed on the D-Bus interface
459 QCOMPARE(map.value("count").toInt(), 55);
460 QCOMPARE(map.value("countVisible").toBool(), true);
462 // Finally check, that the change to "count" implicitly also set the alerting-state to true
463 QVERIFY(launcherModel->get(index)->alerting() == true);
464 }
466 void testCountEmblemAddsRemovesItem_data() {
467 QTest::addColumn<bool>("isPinned");
468 QTest::addColumn<bool>("isRunning");
469 QTest::addColumn<bool>("startWhenVisible");
470 QTest::newRow("not pinned, not running") << false << false << false;
471 QTest::newRow("pinned, not running") << true << false << false;
472 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
473 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
474 QTest::newRow("not pinned, running") << false << true << false;
475 QTest::newRow("pinned, running") << true << true << false;
476 }
478 void testCountEmblemAddsRemovesItem() {
479 QFETCH(bool, isPinned);
480 QFETCH(bool, isRunning);
481 QFETCH(bool, startWhenVisible);
483 // Make sure item is here as expected after init() and that count is not visible
484 int index = launcherModel->findApplication("abs-icon");
485 QCOMPARE(index == -1, false);
486 QCOMPARE(launcherModel->get(index)->countVisible(), false);
488 // Pin if we need to
489 if (isPinned) {
490 launcherModel->pin("abs-icon");
491 }
492 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
494 // Stop it if we need to
495 if (!isRunning) {
496 appManager->stopApplication("abs-icon");
497 }
498 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
501 // set the count emblem to visible
502 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
503 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
504 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
506 // Make sure item is here and that count is visible
507 index = launcherModel->findApplication("abs-icon");
508 QCOMPARE(index == -1, false);
509 QCOMPARE(launcherModel->get(index)->countVisible(), true);
511 if (!isRunning && startWhenVisible) {
512 appManager->addApplication(new MockApp("abs-icon"));
513 }
515 // Hide count emblem again
516 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
518 // Make sure item is shown/hidden as expected
519 index = launcherModel->findApplication("abs-icon");
520 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
521 }
523 void testAlert() {
524 // Check that the alerting-status is still false
525 int index = launcherModel->findApplication("abs-icon");
526 QCOMPARE(index >= 0, true);
527 QVERIFY(launcherModel->get(index)->alerting() == false);
529 // Call Alert() on "abs-icon"
530 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
531 interface.call("Alert");
533 // Check that the alerting-status is now true
534 QVERIFY(launcherModel->get(index)->alerting() == true);
535 }
537 void testRefreshAfterDeletedDesktopFiles_data() {
538 QTest::addColumn<bool>("deleted");
539 QTest::newRow("have .desktop files") << false;
540 QTest::newRow("deleted .desktop files") << true;
541 }
543 void testRefreshAfterDeletedDesktopFiles() {
544 QFETCH(bool, deleted);
546 // pin both apps
547 launcherModel->pin("abs-icon");
548 launcherModel->pin("no-icon");
549 // close both apps
550 appManager->removeApplication(0);
551 appManager->removeApplication(0);
553 // "delete" the .desktop files
554 QString oldCurrent = QDir::currentPath();
555 if (deleted) {
556 // In testing mode, the launcher searches the current dir for the sample .desktop file
557 // We can make that fail by changing the current dir
558 QDir::setCurrent("..");
559 }
561 // Call refresh
562 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
563 QDBusReply<void> reply = interface.call("Refresh");
565 // Make sure the call to Refresh returned without error.
566 QCOMPARE(reply.isValid(), true);
568 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
570 // Restoring current dir
571 QDir::setCurrent(oldCurrent);
572 }
574 void testSettings() {
575 GSettings *settings = launcherModel->m_settings;
576 QSignalSpy spy(launcherModel, &LauncherModel::hint);
578 // Nothing pinned at startup
579 QCOMPARE(settings->storedApplications().count(), 0);
581 // pin both apps
582 launcherModel->pin("abs-icon");
583 launcherModel->pin("no-icon");
584 QCOMPARE(spy.count(), 0);
586 // Now settings should have 2 apps
587 QCOMPARE(settings->storedApplications().count(), 2);
589 // close both apps
590 appManager->removeApplication(0);
591 appManager->removeApplication(0);
593 // Now settings should have 2 apps
594 QCOMPARE(settings->storedApplications().count(), 2);
596 // Now remove 1 app through the backend, make sure one is still there
597 settings->simulateDConfChanged(QStringList() << "abs-icon");
598 QCOMPARE(settings->storedApplications().count(), 1);
599 QCOMPARE(spy.count(), 1);
601 // Check if it disappeared from the frontend too
602 QCOMPARE(launcherModel->rowCount(), 1);
604 // Add them back but in reverse order
605 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
606 QCOMPARE(launcherModel->rowCount(), 2);
607 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
608 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
609 QCOMPARE(spy.count(), 2);
610 }
612 void testAddSyncsToAS() {
613 // Make sure launcher and AS are in sync when we start the test
614 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
616 int oldCount = launcherModel->rowCount();
617 appManager->addApplication(new MockApp("rel-icon"));
618 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
619 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
620 }
622 void testRemoveSyncsToAS() {
623 // Make sure launcher and AS are in sync when we start the test
624 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
626 int oldCount = launcherModel->rowCount();
627 appManager->stopApplication("abs-icon");
628 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
629 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
630 }
632 void testMoveSyncsToAS() {
633 // Make sure launcher and AS are in sync when we start the test
634 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
636 for (int i = 0; i < launcherModel->rowCount(); i++) {
637 QString launcherAppId = launcherModel->get(i)->appId();
638 QString asAppId = getASConfig().at(i).value("id").toString();
639 QCOMPARE(launcherAppId, asAppId);
640 }
642 launcherModel->move(0, 1);
644 for (int i = 0; i < launcherModel->rowCount(); i++) {
645 QString launcherAppId = launcherModel->get(i)->appId();
646 QString asAppId = getASConfig().at(i).value("id").toString();
647 QCOMPARE(launcherAppId, asAppId);
648 }
649 }
651 void testCountChangeSyncsToAS() {
652 // Find the index of the abs-icon app
653 int index = launcherModel->findApplication("abs-icon");
655 // Make sure it's invisible and 0 at the beginning
656 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
657 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
659 // Change the count of the abs-icon app through D-Bus
660 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
661 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
662 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
664 // Make sure it changed to visible and 55
665 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
666 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
667 }
668};
670QTEST_GUILESS_MAIN(LauncherModelTest)
671#include "launchermodeltest.moc"