on xenial help sign in
Make method more robust in the face of weird inputs
e0441d6Michael Terry
plugins/Unity/Launcher/launchermodel.cpp+5−2
@@ -202,6 +202,9 @@ QString LauncherModel::getUrlForAppId(const QString &appId) const
202 QString url;
202 QString url;
203 gchar *longAppId;
203 gchar *longAppId;
204
204
205+ if (appId.isEmpty())
206+ return QString();
207+
205 // assume legacy app until proven otherwise
208 // assume legacy app until proven otherwise
206 url = "application:///" + appId + ".desktop";
209 url = "application:///" + appId + ".desktop";
207
210
@@ -210,10 +213,10 @@ QString LauncherModel::getUrlForAppId(const QString &appId) const
210 QString package = parts.value(0);
213 QString package = parts.value(0);
211 QString app = parts.value(1);
214 QString app = parts.value(1);
212 longAppId = upstart_app_launch_triplet_to_app_id(package.toLatin1().constData(),
215 longAppId = upstart_app_launch_triplet_to_app_id(package.toLatin1().constData(),
213− app.toLatin1().constData(),
216+ app.isEmpty() ? nullptr : app.toLatin1().constData(),
214 nullptr);
217 nullptr);
215 if (longAppId != nullptr) { // it is a click app!
218 if (longAppId != nullptr) { // it is a click app!
216− url = "appid://" + parts.join('/') + "/current-user-version";
219+ url = "appid://" + QString(longAppId).replace('_', '/');
217 g_free(longAppId);
220 g_free(longAppId);
218 }
221 }
219
222
tests/CMakeLists.txt+2
@@ -1,3 +1,5 @@
1+configure_file("data/click/db/test.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/data/click/db/test.conf" @ONLY)
2+
1# QML tests that do not require graphical capabilities.
3# QML tests that do not require graphical capabilities.
2add_custom_target(qmlunittests)
4add_custom_target(qmlunittests)
3
5
tests/data/click/db/test.conf.innew file+2
@@ -0,0 +1,2 @@
1+[Click Database]
2+root = @CMAKE_SOURCE_DIR@/tests/data/click/root
tests/data/click/root/.click/users/test-user/com.test.goodnew file+1
@@ -0,0 +1 @@
1+../../../com.test.good/1.2.3
tests/data/click/root/com.test.good/1.2.3new file+1
@@ -0,0 +1 @@
1+../../app
tests/plugins/Unity/Launcher/CMakeLists.txt+1
@@ -16,6 +16,7 @@ include_directories(
16
16
17add_definitions(-DSM_BUSNAME=sessionBus)
17add_definitions(-DSM_BUSNAME=sessionBus)
18add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
18add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
19+add_definitions(-DCMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}")
19add_definitions(-DLAUNCHER_TESTING)
20add_definitions(-DLAUNCHER_TESTING)
20
21
21### LauncherBackendTest
22### LauncherBackendTest
tests/plugins/Unity/Launcher/launchermodeltest.cpp+18
@@ -127,6 +127,9 @@ private Q_SLOTS:
127
127
128 appManager->addApplication(new MockApp("no-icon"));
128 appManager->addApplication(new MockApp("no-icon"));
129 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
129 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
130+
131+ qputenv("TEST_CLICK_DB", CMAKE_BINARY_DIR "/tests/data/click/db");
132+ qputenv("TEST_CLICK_USER", "test-user");
130 }
133 }
131
134
132 // Removing apps from appmanager and launcher as pinned ones would stick
135 // Removing apps from appmanager and launcher as pinned ones would stick
@@ -137,6 +140,8 @@ private Q_SLOTS:
137 while (launcherModel->rowCount(QModelIndex()) > 0) {
140 while (launcherModel->rowCount(QModelIndex()) > 0) {
138 launcherModel->requestRemove(launcherModel->get(0)->appId());
141 launcherModel->requestRemove(launcherModel->get(0)->appId());
139 }
142 }
143+ qputenv("TEST_CLICK_DB", "");
144+ qputenv("TEST_CLICK_USER", "");
140 }
145 }
141
146
142 void testMove() {
147 void testMove() {
@@ -274,6 +279,19 @@ private Q_SLOTS:
274 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
279 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
275 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
280 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
276 }
281 }
282+
283+ void testGetUrlForAppId() {
284+ QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
285+ QCOMPARE(launcherModel->getUrlForAppId(""), QString());
286+ QCOMPARE(launcherModel->getUrlForAppId("not-an-app"), QString("application:///not-an-app.desktop"));
287+ QCOMPARE(launcherModel->getUrlForAppId("not_an_app"), QString("application:///not_an_app.desktop"));
288+ QCOMPARE(launcherModel->getUrlForAppId("notes-app"), QString("application:///notes-app.desktop"));
289+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("appid://com.test.good/application/1.2.3"));
290+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/1.2.3"));
291+ // Note that this version change is intentional -- we want to fix old links to use latest current version
292+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_0.0.0"), QString("appid://com.test.good/application/1.2.3"));
293+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/1.2.3"));
294+ }
277};
295};
278
296
279QTEST_GUILESS_MAIN(LauncherModelTest)
297QTEST_GUILESS_MAIN(LauncherModelTest)