on f137158 help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
652 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, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
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 testApplicationFocused() {
302 // all apps unfocused at beginning...
303 QCOMPARE(launcherModel->get(0)->focused(), false);
304 QCOMPARE(launcherModel->get(1)->focused(), false);
306 appManager->focusApplication("abs-icon");
307 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
308 QCOMPARE(launcherModel->get(0)->focused(), true);
309 QCOMPARE(launcherModel->get(1)->focused(), false);
311 appManager->focusApplication("no-icon");
312 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
313 QCOMPARE(launcherModel->get(0)->focused(), false);
314 QCOMPARE(launcherModel->get(1)->focused(), true);
315 }
317 void testClosingApps() {
318 // At the start there are 2 items. Let's pin one.
319 launcherModel->pin("abs-icon");
320 while (appManager->count() > 0) {
321 appManager->removeApplication(0);
322 }
323 // The pinned one needs to stay, the other needs to disappear
324 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
325 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
326 }
328 void testQuitMenuItem() {
329 // we have 2 apps running, both should have the Quit action in its quick list
330 QCOMPARE(launcherModel->rowCount(), 2);
332 // stop the second one keeping it pinned so that it doesn't go away
333 launcherModel->pin("no-icon");
334 appManager->stopApplication("no-icon");
336 // find the first Quit item, should be there
337 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
338 int quitActionIndex = -1;
339 for (int i = 0; i < model->rowCount(); ++i) {
340 if (model->get(i).actionId() == "stop_item") {
341 quitActionIndex = i;
342 break;
343 }
344 }
345 QVERIFY(quitActionIndex >= 0);
347 // find the second Quit item, should NOT be there, the app is stopped
348 QuickListModel *model2 = qobject_cast<QuickListModel*>(launcherModel->get(1)->quickList());
349 int quitActionIndex2 = -1;
350 for (int i = 0; i < model2->rowCount(); ++i) {
351 if (model2->get(i).actionId() == "stop_item") {
352 quitActionIndex2 = i;
353 break;
354 }
355 }
356 QVERIFY(quitActionIndex2 == -1);
358 // trigger the first quit item quicklist action
359 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), quitActionIndex);
360 // first app should be gone...
361 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
362 // ... the second app (now at index 0) should still be there, pinned and stopped
363 QCOMPARE(launcherModel->get(0)->appId(), QStringLiteral("no-icon"));
364 QCOMPARE(launcherModel->get(0)->pinned(), true);
365 QCOMPARE(launcherModel->get(0)->running(), false);
366 }
368 void testGetUrlForAppId() {
369 QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
370 QCOMPARE(launcherModel->getUrlForAppId(""), QString());
371 QCOMPARE(launcherModel->getUrlForAppId("no-name"), QString("application:///no-name.desktop"));
372 QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("application:///com.test.good.desktop"));
373 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/current-user-version"));
374 QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/current-user-version"));
375 }
377 void testIntrospection() {
378 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "org.freedesktop.DBus.Introspectable");
379 QDBusReply<QString> reply = interface.call("Introspect");
380 QStringList nodes = extractNodes(reply.value());
381 QCOMPARE(nodes.count(), launcherModel->rowCount());
383 appManager->addApplication(new MockApp("foobar"));
384 reply = interface.call("Introspect");
385 nodes = extractNodes(reply.value());
386 QCOMPARE(nodes.contains("foobar"), true);
388 appManager->removeApplication(2);
389 reply = interface.call("Introspect");
390 nodes = extractNodes(reply.value());
391 QCOMPARE(nodes.contains("foobar"), false);
392 }
394 QStringList extractNodes(const QString &introspectionXml) {
395 QXmlStreamReader introspectReply(introspectionXml);
397 QStringList ret;
398 while (!introspectReply.atEnd() && !introspectReply.hasError()) {
399 QXmlStreamReader::TokenType token = introspectReply.readNext();
401 if (token == QXmlStreamReader::StartElement) {
402 if (introspectReply.name() == "node" && introspectReply.attributes().count() > 0) {
403 ret << introspectReply.attributes().value("name").toString();
404 }
405 }
406 }
407 return ret;
408 }
410 void testCountEmblems() {
411 QSignalSpy spy(launcherModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
413 // Call GetAll on abs-icon
414 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
415 QDBusReply<QVariantMap> reply = interface.call("GetAll");
416 QVariantMap map = reply.value();
418 // Check that the alerting-status is still false, and the item on the upper side of the API
419 int index = launcherModel->findApplication("abs-icon");
420 QCOMPARE(index >= 0, true);
421 QVERIFY(launcherModel->get(index)->alerting() == false);
423 // Make sure GetAll returns a map with count and countVisible props
424 QCOMPARE(map.contains("count"), true);
425 QCOMPARE(map.contains("countVisible"), true);
427 // Make sure count is intitilized to 0 and non-visible
428 QCOMPARE(map.value("count").toInt(), 0);
429 QCOMPARE(map.value("countVisible").toBool(), false);
431 // Now make it visible and set it to 55 through D-Bus
432 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
433 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
435 // Fetch it again using GetAll
436 reply = interface.call("GetAll");
437 map = reply.value();
439 // Make sure values have changed on the D-Bus interface
440 QCOMPARE(map.value("count").toInt(), 55);
441 QCOMPARE(map.value("countVisible").toBool(), true);
443 // Finally check, that the change to "count" implicitly also set the alerting-state to true
444 QVERIFY(launcherModel->get(index)->alerting() == true);
445 }
447 void testCountEmblemAddsRemovesItem_data() {
448 QTest::addColumn<bool>("isPinned");
449 QTest::addColumn<bool>("isRunning");
450 QTest::addColumn<bool>("startWhenVisible");
451 QTest::newRow("not pinned, not running") << false << false << false;
452 QTest::newRow("pinned, not running") << true << false << false;
453 QTest::newRow("not pinned, not running, starting from notification") << false << false << true;
454 QTest::newRow("pinned, not running, starting from notification") << true << false << true;
455 QTest::newRow("not pinned, running") << false << true << false;
456 QTest::newRow("pinned, running") << true << true << false;
457 }
459 void testCountEmblemAddsRemovesItem() {
460 QFETCH(bool, isPinned);
461 QFETCH(bool, isRunning);
462 QFETCH(bool, startWhenVisible);
464 // Make sure item is here as expected after init() and that count is not visible
465 int index = launcherModel->findApplication("abs-icon");
466 QCOMPARE(index == -1, false);
467 QCOMPARE(launcherModel->get(index)->countVisible(), false);
469 // Pin if we need to
470 if (isPinned) {
471 launcherModel->pin("abs-icon");
472 }
473 QCOMPARE(launcherModel->get(0)->pinned(), isPinned);
475 // Stop it if we need to
476 if (!isRunning) {
477 appManager->stopApplication("abs-icon");
478 }
479 QCOMPARE(launcherModel->findApplication("abs-icon") >= 0, isRunning || isPinned);
482 // set the count emblem to visible
483 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
484 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
485 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
487 // Make sure item is here and that count is visible
488 index = launcherModel->findApplication("abs-icon");
489 QCOMPARE(index == -1, false);
490 QCOMPARE(launcherModel->get(index)->countVisible(), true);
492 if (!isRunning && startWhenVisible) {
493 appManager->addApplication(new MockApp("abs-icon"));
494 }
496 // Hide count emblem again
497 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(false)));
499 // Make sure item is shown/hidden as expected
500 index = launcherModel->findApplication("abs-icon");
501 QCOMPARE(index == -1, !isRunning && !isPinned && !startWhenVisible);
502 }
504 void testAlert() {
505 // Check that the alerting-status is still false
506 int index = launcherModel->findApplication("abs-icon");
507 QCOMPARE(index >= 0, true);
508 QVERIFY(launcherModel->get(index)->alerting() == false);
510 // Call Alert() on "abs-icon"
511 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "com.canonical.Unity.Launcher.Item");
512 interface.call("Alert");
514 // Check that the alerting-status is now true
515 QVERIFY(launcherModel->get(index)->alerting() == true);
516 }
518 void testRefreshAfterDeletedDesktopFiles_data() {
519 QTest::addColumn<bool>("deleted");
520 QTest::newRow("have .desktop files") << false;
521 QTest::newRow("deleted .desktop files") << true;
522 }
524 void testRefreshAfterDeletedDesktopFiles() {
525 QFETCH(bool, deleted);
527 // pin both apps
528 launcherModel->pin("abs-icon");
529 launcherModel->pin("no-icon");
530 // close both apps
531 appManager->removeApplication(0);
532 appManager->removeApplication(0);
534 // "delete" the .desktop files
535 QString oldCurrent = QDir::currentPath();
536 if (deleted) {
537 // In testing mode, the launcher searches the current dir for the sample .desktop file
538 // We can make that fail by changing the current dir
539 QDir::setCurrent("..");
540 }
542 // Call refresh
543 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher");
544 QDBusReply<void> reply = interface.call("Refresh");
546 // Make sure the call to Refresh returned without error.
547 QCOMPARE(reply.isValid(), true);
549 QCOMPARE(launcherModel->rowCount(), deleted ? 0 : 2);
551 // Restoring current dir
552 QDir::setCurrent(oldCurrent);
553 }
555 void testSettings() {
556 GSettings *settings = launcherModel->m_settings;
557 QSignalSpy spy(launcherModel, SIGNAL(hint()));
559 // Nothing pinned at startup
560 QCOMPARE(settings->storedApplications().count(), 0);
562 // pin both apps
563 launcherModel->pin("abs-icon");
564 launcherModel->pin("no-icon");
565 QCOMPARE(spy.count(), 0);
567 // Now settings should have 2 apps
568 QCOMPARE(settings->storedApplications().count(), 2);
570 // close both apps
571 appManager->removeApplication(0);
572 appManager->removeApplication(0);
574 // Now settings should have 2 apps
575 QCOMPARE(settings->storedApplications().count(), 2);
577 // Now remove 1 app through the backend, make sure one is still there
578 settings->simulateDConfChanged(QStringList() << "abs-icon");
579 QCOMPARE(settings->storedApplications().count(), 1);
580 QCOMPARE(spy.count(), 1);
582 // Check if it disappeared from the frontend too
583 QCOMPARE(launcherModel->rowCount(), 1);
585 // Add them back but in reverse order
586 settings->simulateDConfChanged(QStringList() << "no-icon" << "abs-icon");
587 QCOMPARE(launcherModel->rowCount(), 2);
588 QCOMPARE(launcherModel->get(0)->appId(), QString("no-icon"));
589 QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
590 QCOMPARE(spy.count(), 2);
591 }
593 void testAddSyncsToAS() {
594 // Make sure launcher and AS are in sync when we start the test
595 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
597 int oldCount = launcherModel->rowCount();
598 appManager->addApplication(new MockApp("rel-icon"));
599 QCOMPARE(launcherModel->rowCount(), oldCount + 1);
600 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
601 }
603 void testRemoveSyncsToAS() {
604 // Make sure launcher and AS are in sync when we start the test
605 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
607 int oldCount = launcherModel->rowCount();
608 appManager->stopApplication("abs-icon");
609 QCOMPARE(launcherModel->rowCount(), oldCount - 1);
610 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
611 }
613 void testMoveSyncsToAS() {
614 // Make sure launcher and AS are in sync when we start the test
615 QCOMPARE(launcherModel->rowCount(), getASConfig().count());
617 for (int i = 0; i < launcherModel->rowCount(); i++) {
618 QString launcherAppId = launcherModel->get(i)->appId();
619 QString asAppId = getASConfig().at(i).value("id").toString();
620 QCOMPARE(launcherAppId, asAppId);
621 }
623 launcherModel->move(0, 1);
625 for (int i = 0; i < launcherModel->rowCount(); i++) {
626 QString launcherAppId = launcherModel->get(i)->appId();
627 QString asAppId = getASConfig().at(i).value("id").toString();
628 QCOMPARE(launcherAppId, asAppId);
629 }
630 }
632 void testCountChangeSyncsToAS() {
633 // Find the index of the abs-icon app
634 int index = launcherModel->findApplication("abs-icon");
636 // Make sure it's invisible and 0 at the beginning
637 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
638 QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
640 // Change the count of the abs-icon app through D-Bus
641 QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
642 interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
643 interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
645 // Make sure it changed to visible and 55
646 QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
647 QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
648 }
649};
651QTEST_GUILESS_MAIN(LauncherModelTest)
652#include "launchermodeltest.moc"