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