on febd475 help sign in
unity8/tests/plugins/Unity/Launcher/launchermodeltest.cpp
146 lines 5.3 kB history raw
1/*
2 * Copyright 2013 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>
23#include "launcheritem.h"
24#include "launchermodel.h"
26#include <QtTest>
28class LauncherModelTest : public QObject
30 Q_OBJECT
32private:
33 LauncherModel *launcherModel;
35private Q_SLOTS:
37 void initTestCase() {
38 launcherModel = new LauncherModel(this);
39 QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
40 }
42 void init() {
43 qDebug() << "init";
44 launcherModel->applicationFocused("abs-icon");
45 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
47 launcherModel->applicationFocused("no-icon.desktop");
48 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
50 launcherModel->applicationFocused(QString());
51 }
53 void cleanup() {
54 while (launcherModel->rowCount(QModelIndex()) > 0) {
55 launcherModel->requestRemove(launcherModel->get(0)->appId());
56 }
57 }
59 void testMove() {
60 QCOMPARE(launcherModel->get(0)->pinned(), false);
61 QCOMPARE(launcherModel->get(1)->pinned(), false);
63 LauncherItemInterface *item0BeforeMove = launcherModel->get(0);
64 LauncherItemInterface *item1BeforeMove = launcherModel->get(1);
65 launcherModel->move(1, 0);
67 QCOMPARE(item0BeforeMove, launcherModel->get(1));
68 QCOMPARE(item1BeforeMove, launcherModel->get(0));
70 // moved item must be pinned now
71 QCOMPARE(item0BeforeMove->pinned(), false);
72 QCOMPARE(item1BeforeMove->pinned(), true);
73 }
75 void testPinning() {
76 QCOMPARE(launcherModel->get(0)->pinned(), false);
77 QCOMPARE(launcherModel->get(1)->pinned(), false);
78 launcherModel->pin(launcherModel->get(0)->appId());
79 QCOMPARE(launcherModel->get(0)->pinned(), true);
80 QCOMPARE(launcherModel->get(1)->pinned(), false);
81 }
83 void testRemove() {
84 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
85 launcherModel->requestRemove(launcherModel->get(0)->appId());
86 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
87 }
89 void testQuickListPinningRemoving() {
90 // we start with 2 unpinned items
91 QCOMPARE(launcherModel->get(0)->pinned(), false);
92 QCOMPARE(launcherModel->get(1)->pinned(), false);
93 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
95 // find the Pin item in the quicklist
96 QuickListModel *model = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
97 int pinActionIndex = -1;
98 for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
99 if (model->get(i).actionId() == "pin_item") {
100 pinActionIndex = i;
101 break;
102 }
103 }
104 QVERIFY(pinActionIndex >= 0);
106 // trigger pin item quicklist action => Item must be pinned now.
107 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
108 QCOMPARE(launcherModel->get(0)->pinned(), true);
109 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
111 // quicklist needs to transform to remove item. trigger it and check it item goes away
112 launcherModel->quickListActionInvoked(launcherModel->get(0)->appId(), pinActionIndex);
113 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
114 }
116 void testApplicationFocused() {
117 // all apps unfocused at beginning...
118 QCOMPARE(launcherModel->get(0)->focused(), false);
119 QCOMPARE(launcherModel->get(1)->focused(), false);
121 launcherModel->applicationFocused("abs-icon");
122 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
123 QCOMPARE(launcherModel->get(0)->focused(), true);
124 QCOMPARE(launcherModel->get(1)->focused(), false);
126 launcherModel->applicationFocused("no-icon");
127 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
128 QCOMPARE(launcherModel->get(0)->focused(), false);
129 QCOMPARE(launcherModel->get(1)->focused(), true);
131 launcherModel->applicationFocused("rel-icon");
132 QCOMPARE(launcherModel->rowCount(QModelIndex()), 3);
133 QCOMPARE(launcherModel->get(0)->focused(), false);
134 QCOMPARE(launcherModel->get(1)->focused(), false);
135 QCOMPARE(launcherModel->get(2)->focused(), true);
137 launcherModel->applicationFocused(QString());
138 QCOMPARE(launcherModel->rowCount(QModelIndex()), 3);
139 QCOMPARE(launcherModel->get(0)->focused(), false);
140 QCOMPARE(launcherModel->get(1)->focused(), false);
141 QCOMPARE(launcherModel->get(2)->focused(), false);
142 }
143};
145QTEST_GUILESS_MAIN(LauncherModelTest)
146#include "launchermodeltest.moc"