Merge lp:~mir-team/unity-mir/mir-0.2.0-compatibility-changes into lp:unity-mir/devel-mir-next
- mir-0.2.0-compatibility-changes
- Merge into devel-mir-next
Status: | Merged |
---|---|
Approved by: | kevin gunn |
Approved revision: | 223 |
Merged at revision: | 223 |
Proposed branch: | lp:~mir-team/unity-mir/mir-0.2.0-compatibility-changes |
Merge into: | lp:unity-mir/devel-mir-next |
Diff against target: |
1111 lines (+359/-178) 23 files modified
debian/changelog (+15/-0) src/modules/Unity/Application/application.cpp (+10/-2) src/modules/Unity/Application/application.h (+2/-0) src/modules/Unity/Application/application_manager.cpp (+55/-14) src/modules/Unity/Application/applicationcontroller.h (+3/-0) src/modules/Unity/Application/desktopfilereader.cpp (+6/-47) src/modules/Unity/Application/desktopfilereader.h (+2/-5) src/modules/Unity/Application/taskcontroller.cpp (+5/-0) src/modules/Unity/Application/taskcontroller.h (+1/-0) src/modules/Unity/Application/upstart/applicationcontroller.cpp (+92/-10) src/modules/Unity/Application/upstart/applicationcontroller.h (+7/-5) src/unity-mir/messageprocessor.cpp (+5/-0) src/unity-mir/messageprocessor.h (+1/-0) src/unity-mir/sessionauthorizer.cpp (+13/-9) src/unity-mir/sessionauthorizer.h (+3/-3) src/unity-mir/sessioncreator.cpp (+3/-3) src/unity-mir/sessioncreator.h (+3/-3) src/unity-mir/shellserverconfiguration.cpp (+3/-3) src/unity-mir/shellserverconfiguration.h (+1/-1) tests/application_manager_test.cpp (+85/-3) tests/mock_application_controller.h (+11/-0) tests/mock_desktop_file_reader.h (+31/-70) tests/taskcontroller_test.cpp (+2/-0) |
To merge this branch: | bzr merge lp:~mir-team/unity-mir/mir-0.2.0-compatibility-changes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Nick Dedekind (community) | Abstain | ||
Review via email: mp+218734@code.launchpad.net |
Commit message
Compatiblity changes for mir 0.2.0
Description of the change
Compatiblity changes for mir 0.2.0
PS Jenkins bot (ps-jenkins) wrote : | # |
- 222. By kevin gunn
-
merge trunk
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:222
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 223. By Alberto Aguirre
-
Update to use new namespace for DisplayServer interface
Have wrapper implement MessageProcessor::client_ pid
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:223
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Gerry Boland (gerboland) wrote : | # |
Launchpad a bit confused? The shortAppId stuff landed already...
Nick Dedekind (nick-dedekind) wrote : | # |
Needs another mir/devel update.
/tmp/buildd/
std:
Nick Dedekind (nick-dedekind) wrote : | # |
My bad. Works on local build...
Nick Dedekind (nick-dedekind) wrote : | # |
Looks like it's not building against mir/devel.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:223
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2014-04-30 15:56:52 +0000 |
3 | +++ debian/changelog 2014-05-19 18:20:32 +0000 |
4 | @@ -1,3 +1,18 @@ |
5 | +unity-mir (0.4+14.10.20140516.2-0ubuntu1) utopic; urgency=low |
6 | + |
7 | + [ Gerry Boland ] |
8 | + * Add support for short appIds Shells should use only short AppIds |
9 | + (i.e. appId without the version string). In order to support this, |
10 | + needed to slightly decouple appId from the desktop file path, now |
11 | + need to ask the ApplicationController implementation for the path to |
12 | + the desktop file. DesktopFileReader now just a dumb file reader. in |
13 | + the upstart ApplicationController interface & implementation, |
14 | + convert any long appIds to short appIds. in ApplicationManager, to |
15 | + ease transition, have startApplication support both long & short |
16 | + appIds. But otherwise it uses short appIds only. (LP: #1239750) |
17 | + |
18 | + -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 16 May 2014 12:21:06 +0000 |
19 | + |
20 | unity-mir (0.4+14.10.20140430.3-0ubuntu1) utopic; urgency=low |
21 | |
22 | [ Alberto Aguirre ] |
23 | |
24 | === modified file 'src/modules/Unity/Application/application.cpp' |
25 | --- src/modules/Unity/Application/application.cpp 2014-04-15 14:31:02 +0000 |
26 | +++ src/modules/Unity/Application/application.cpp 2014-05-19 18:20:32 +0000 |
27 | @@ -52,6 +52,9 @@ |
28 | |
29 | m_suspendTimer->setSingleShot(true); |
30 | connect(m_suspendTimer, SIGNAL(timeout()), this, SLOT(suspend())); |
31 | + |
32 | + // FIXME(greyback) need to save long appId internally until upstart-app-launch can hide it from us |
33 | + m_longAppId = desktopFileReader->file().remove(QRegExp(".desktop$")).split('/').last(); |
34 | } |
35 | |
36 | Application::~Application() |
37 | @@ -276,13 +279,13 @@ |
38 | void Application::suspend() |
39 | { |
40 | DLOG("Application::suspend (this=%p)", this); |
41 | - m_taskController->suspend(appId()); |
42 | + m_taskController->suspend(longAppId()); |
43 | } |
44 | |
45 | void Application::resume() |
46 | { |
47 | DLOG("Application::resume (this=%p)", this); |
48 | - m_taskController->resume(appId()); |
49 | + m_taskController->resume(longAppId()); |
50 | } |
51 | |
52 | void Application::respawn() |
53 | @@ -291,4 +294,9 @@ |
54 | m_taskController->start(appId(), m_arguments); |
55 | } |
56 | |
57 | +QString Application::longAppId() const |
58 | +{ |
59 | + return m_longAppId; |
60 | +} |
61 | + |
62 | } // namespace unitymir |
63 | |
64 | === modified file 'src/modules/Unity/Application/application.h' |
65 | --- src/modules/Unity/Application/application.h 2014-04-15 14:31:02 +0000 |
66 | +++ src/modules/Unity/Application/application.h 2014-05-19 18:20:32 +0000 |
67 | @@ -89,6 +89,7 @@ |
68 | void visibleChanged(); |
69 | |
70 | private: |
71 | + QString longAppId() const; |
72 | void setPid(pid_t pid); |
73 | void setState(State state); |
74 | void setFocused(bool focus); |
75 | @@ -98,6 +99,7 @@ |
76 | |
77 | QSharedPointer<TaskController> m_taskController; |
78 | DesktopFileReader* m_desktopData; |
79 | + QString m_longAppId; |
80 | qint64 m_pid; |
81 | Stage m_stage; |
82 | State m_state; |
83 | |
84 | === modified file 'src/modules/Unity/Application/application_manager.cpp' |
85 | --- src/modules/Unity/Application/application_manager.cpp 2014-04-15 14:31:02 +0000 |
86 | +++ src/modules/Unity/Application/application_manager.cpp 2014-05-19 18:20:32 +0000 |
87 | @@ -76,6 +76,17 @@ |
88 | ); |
89 | } |
90 | |
91 | +// FIXME: To be removed once shell has fully adopted short appIds!! |
92 | +QString toShortAppIdIfPossible(const QString &appId) { |
93 | + QRegExp longAppIdMask("[a-z0-9][a-z0-9+.-]+_[a-zA-Z0-9+.-]+_[0-9][a-zA-Z0-9.+:~-]*"); |
94 | + if (longAppIdMask.exactMatch(appId)) { |
95 | + LOG("WARNING: long App ID encountered: %s", qPrintable(appId)); |
96 | + // input string a long AppId, chop the version string off the end |
97 | + QStringList parts = appId.split("_"); |
98 | + return QString("%1_%2").arg(parts.first()).arg(parts.at(1)); |
99 | + } |
100 | + return appId; |
101 | +} |
102 | |
103 | void connectToSessionListener(ApplicationManager * manager, SessionListener * listener) |
104 | { |
105 | @@ -262,8 +273,10 @@ |
106 | return m_applications.at(index); |
107 | } |
108 | |
109 | -Application* ApplicationManager::findApplication(const QString &appId) const |
110 | +Application* ApplicationManager::findApplication(const QString &inputAppId) const |
111 | { |
112 | + const QString appId = toShortAppIdIfPossible(inputAppId); |
113 | + |
114 | for (Application *app : m_applications) { |
115 | if (app->appId() == appId) { |
116 | return app; |
117 | @@ -272,8 +285,10 @@ |
118 | return nullptr; |
119 | } |
120 | |
121 | -bool ApplicationManager::requestFocusApplication(const QString &appId) |
122 | +bool ApplicationManager::requestFocusApplication(const QString &inputAppId) |
123 | { |
124 | + const QString appId = toShortAppIdIfPossible(inputAppId); |
125 | + |
126 | DLOG("ApplicationManager::requestFocusApplication (this=%p, appId=%s)", this, qPrintable(appId)); |
127 | Application *application = findApplication(appId); |
128 | |
129 | @@ -355,8 +370,10 @@ |
130 | application->setState(Application::Running); |
131 | } |
132 | |
133 | -bool ApplicationManager::focusApplication(const QString &appId) |
134 | +bool ApplicationManager::focusApplication(const QString &inputAppId) |
135 | { |
136 | + const QString appId = toShortAppIdIfPossible(inputAppId); |
137 | + |
138 | Application *application = findApplication(appId); |
139 | DLOG("ApplicationManager::focusApplication (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); |
140 | |
141 | @@ -412,9 +429,26 @@ |
142 | return startApplication(appId, NoFlag, arguments); |
143 | } |
144 | |
145 | -Application *ApplicationManager::startApplication(const QString &appId, ExecFlags flags, |
146 | +/** |
147 | + * @brief ApplicationManager::startApplication launches an application identified by an "application id" or appId. |
148 | + * |
149 | + * Note: due to an implementation detail, appIds come in two forms: |
150 | + * * long appId: $(click_package)_$(application)_$(version) |
151 | + * * short appId: $(click_package)_$(application) |
152 | + * It is expected that the shell uses _only_ short appIds (but long appIds are accepted by this method for legacy |
153 | + * reasons - but be warned, this ability will be removed) |
154 | + * |
155 | + * Unless stated otherwise, we always use short appIds in this API. |
156 | + * |
157 | + * @param inputAppId AppId of application to launch (long appId supported) |
158 | + * @param flags Shell specific flags to modify the initial state of the application |
159 | + * @param arguments Command line arguments to pass to the application to be launched |
160 | + * @return Pointer to Application object representing the launched process |
161 | + */ |
162 | +Application *ApplicationManager::startApplication(const QString &inputAppId, ExecFlags flags, |
163 | const QStringList &arguments) |
164 | { |
165 | + QString appId = toShortAppIdIfPossible(inputAppId); |
166 | DLOG("ApplicationManager::startApplication (this=%p, appId=%s)", this, qPrintable(appId)); |
167 | |
168 | if (!m_taskController->start(appId, arguments)) { |
169 | @@ -425,15 +459,15 @@ |
170 | { |
171 | Application * application = findApplication(appId); |
172 | if (application) { |
173 | - DLOG("ApplicationManager::startApplication - application already " |
174 | - "exists: (this=%p, app=%p, appId=%s)", |
175 | + DLOG("ApplicationManager::startApplication - application already exists: (this=%p, app=%p, appId=%s)", |
176 | this, application, qPrintable(appId)); |
177 | + return application; |
178 | } |
179 | } |
180 | |
181 | Application* application = new Application( |
182 | m_taskController, |
183 | - m_desktopFileReaderFactory->createInstanceForAppId(appId), |
184 | + m_desktopFileReaderFactory->createInstance(appId, m_taskController->findDesktopFileForAppId(appId)), |
185 | Application::Starting, |
186 | arguments, |
187 | this); |
188 | @@ -467,7 +501,7 @@ |
189 | if (!application) { // if shell did not start this application, but upstart did |
190 | application = new Application( |
191 | m_taskController, |
192 | - m_desktopFileReaderFactory->createInstanceForAppId(appId), |
193 | + m_desktopFileReaderFactory->createInstance(appId, m_taskController->findDesktopFileForAppId(appId)), |
194 | Application::Starting, |
195 | QStringList(), this); |
196 | if (!application->isValid()) { |
197 | @@ -489,8 +523,10 @@ |
198 | } |
199 | } |
200 | |
201 | -bool ApplicationManager::stopApplication(const QString &appId) |
202 | +bool ApplicationManager::stopApplication(const QString &inputAppId) |
203 | { |
204 | + const QString appId = toShortAppIdIfPossible(inputAppId); |
205 | + |
206 | Application *application = findApplication(appId); |
207 | DLOG("ApplicationManager::stopApplication (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); |
208 | |
209 | @@ -504,7 +540,7 @@ |
210 | remove(application); |
211 | m_dbusWindowStack->WindowDestroyed(0, application->appId()); |
212 | |
213 | - bool result = m_taskController->stop(application->appId()); |
214 | + bool result = m_taskController->stop(application->longAppId()); |
215 | |
216 | LOG_IF(result == false, "FAILED to ask Upstart to stop application '%s'", qPrintable(application->appId())); |
217 | |
218 | @@ -521,8 +557,10 @@ |
219 | return result; |
220 | } |
221 | |
222 | -bool ApplicationManager::updateScreenshot(const QString &appId) |
223 | +bool ApplicationManager::updateScreenshot(const QString &inputAppId) |
224 | { |
225 | + const QString appId = toShortAppIdIfPossible(inputAppId); |
226 | + |
227 | Application *application = findApplication(appId); |
228 | |
229 | if (!application) { |
230 | @@ -642,7 +680,7 @@ |
231 | |
232 | for (Application *app : m_applications) { |
233 | if (app->state() == Application::Starting |
234 | - && m_taskController->appIdHasProcessId(app->appId(), pid)) { |
235 | + && m_taskController->appIdHasProcessId(app->longAppId(), pid)) { |
236 | app->setPid(pid); |
237 | DLOG("ApplicationManager::authorizeSession - connecting: application=%p and pid=%lld", app, pid); |
238 | authorized = true; |
239 | @@ -678,13 +716,16 @@ |
240 | |
241 | DLOG("Process supplied desktop_file_hint, loading '%s'", desktopFileName.get().toLatin1().data()); |
242 | |
243 | + // Guess appId from the desktop file hint |
244 | + QString appId = toShortAppIdIfPossible(desktopFileName.get().remove(QRegExp(".desktop$")).split('/').last()); |
245 | + |
246 | // FIXME: right now we support --desktop_file_hint=appId for historical reasons. So let's try that in |
247 | // case we didn't get an existing .desktop file path |
248 | DesktopFileReader* desktopData; |
249 | if (QFileInfo(desktopFileName.get()).exists()) { |
250 | - desktopData = m_desktopFileReaderFactory->createInstanceForDesktopFile(QFileInfo(desktopFileName.get())); |
251 | + desktopData = m_desktopFileReaderFactory->createInstance(appId, QFileInfo(desktopFileName.get())); |
252 | } else { |
253 | - desktopData = m_desktopFileReaderFactory->createInstanceForAppId(desktopFileName.get()); |
254 | + desktopData = m_desktopFileReaderFactory->createInstance(appId, m_taskController->findDesktopFileForAppId(appId)); |
255 | } |
256 | |
257 | if (!desktopData->loaded()) { |
258 | |
259 | === modified file 'src/modules/Unity/Application/applicationcontroller.h' |
260 | --- src/modules/Unity/Application/applicationcontroller.h 2014-02-28 16:51:31 +0000 |
261 | +++ src/modules/Unity/Application/applicationcontroller.h 2014-05-19 18:20:32 +0000 |
262 | @@ -21,6 +21,7 @@ |
263 | #include <QObject> |
264 | #include <QString> |
265 | #include <QStringList> |
266 | +#include <QFileInfo> |
267 | |
268 | namespace unitymir |
269 | { |
270 | @@ -47,6 +48,8 @@ |
271 | virtual bool stopApplicationWithAppId(const QString& appId) = 0; |
272 | virtual bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) = 0; |
273 | |
274 | + virtual QFileInfo findDesktopFileForAppId(const QString &appId) const = 0; |
275 | + |
276 | Q_SIGNALS: |
277 | void applicationAboutToBeStarted(QString id); |
278 | void applicationStarted(QString id); |
279 | |
280 | === modified file 'src/modules/Unity/Application/desktopfilereader.cpp' |
281 | --- src/modules/Unity/Application/desktopfilereader.cpp 2014-02-28 16:51:31 +0000 |
282 | +++ src/modules/Unity/Application/desktopfilereader.cpp 2014-05-19 18:20:32 +0000 |
283 | @@ -22,8 +22,6 @@ |
284 | |
285 | // Qt |
286 | #include <QFile> |
287 | -#include <QDir> |
288 | -#include <QStandardPaths> |
289 | |
290 | namespace unitymir |
291 | { |
292 | @@ -36,38 +34,23 @@ |
293 | { |
294 | } |
295 | |
296 | -DesktopFileReader* DesktopFileReader::Factory::createInstanceForAppId(const QString& appId) |
297 | -{ |
298 | - return new DesktopFileReader(appId); |
299 | -} |
300 | - |
301 | -DesktopFileReader* DesktopFileReader::Factory::createInstanceForDesktopFile(const QFileInfo& fi) |
302 | -{ |
303 | - return new DesktopFileReader(fi); |
304 | +DesktopFileReader* DesktopFileReader::Factory::createInstance(const QString &appId, const QFileInfo& fi) |
305 | +{ |
306 | + return new DesktopFileReader(appId, fi); |
307 | } |
308 | |
309 | // Retrieves the size of an array at compile time. |
310 | #define ARRAY_SIZE(a) \ |
311 | ((sizeof(a) / sizeof(*(a))) / static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) |
312 | |
313 | -DesktopFileReader::DesktopFileReader(const QString &appId) |
314 | +DesktopFileReader::DesktopFileReader(const QString &appId, const QFileInfo &desktopFile) |
315 | : appId_(appId) |
316 | , entries_(DesktopFileReader::kNumberOfEntries, "") |
317 | { |
318 | - DLOG("DesktopFileReader::DesktopFileReader (this=%p, appId='%s')", this, appId.toLatin1().data()); |
319 | - DASSERT(appId != NULL); |
320 | - |
321 | - file_ = findDesktopFile(appId); |
322 | - loaded_ = loadDesktopFile(file_); |
323 | -} |
324 | - |
325 | -DesktopFileReader::DesktopFileReader(const QFileInfo &desktopFile) |
326 | - : entries_(DesktopFileReader::kNumberOfEntries, "") |
327 | -{ |
328 | - DLOG("DesktopFileReader::DesktopFileReader (this=%p, desktopFile='%s')", this, desktopFile.absoluteFilePath().toLatin1().data()); |
329 | + DLOG("DesktopFileReader::DesktopFileReader (this=%p, appId='%s', desktopFile='%s')", this, |
330 | + qPrintable(appId), qPrintable(desktopFile.absoluteFilePath())); |
331 | DASSERT(desktopFile.exists()); |
332 | |
333 | - appId_ = desktopFile.completeBaseName(); |
334 | file_ = desktopFile.absoluteFilePath(); |
335 | loaded_ = loadDesktopFile(file_); |
336 | } |
337 | @@ -78,30 +61,6 @@ |
338 | entries_.clear(); |
339 | } |
340 | |
341 | - |
342 | -QString DesktopFileReader::findDesktopFile(const QString &appId) const |
343 | -{ |
344 | - DLOG("DesktopFileReader::findDesktopFile (appId='%s')", appId.toLatin1().data()); |
345 | - |
346 | - int dashPos = -1; |
347 | - QString helper = appId; |
348 | - QString desktopFile; |
349 | - |
350 | - do { |
351 | - if (dashPos != -1) { |
352 | - helper = helper.replace(dashPos, 1, '/'); |
353 | - } |
354 | - |
355 | - desktopFile = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, QString("%1.desktop").arg(helper)); |
356 | - if (!desktopFile.isEmpty()) return desktopFile; |
357 | - |
358 | - dashPos = helper.indexOf("-"); |
359 | - } while (dashPos != -1); |
360 | - |
361 | - return QString(); |
362 | -} |
363 | - |
364 | - |
365 | bool DesktopFileReader::loadDesktopFile(QString desktopFile) |
366 | { |
367 | DLOG("DesktopFileReader::loadDesktopFile (this=%p, desktopFile='%s')", |
368 | |
369 | === modified file 'src/modules/Unity/Application/desktopfilereader.h' |
370 | --- src/modules/Unity/Application/desktopfilereader.h 2014-02-28 16:51:31 +0000 |
371 | +++ src/modules/Unity/Application/desktopfilereader.h 2014-05-19 18:20:32 +0000 |
372 | @@ -35,8 +35,7 @@ |
373 | |
374 | Factory& operator=(const Factory&) = delete; |
375 | |
376 | - virtual DesktopFileReader* createInstanceForAppId(const QString& appId); |
377 | - virtual DesktopFileReader* createInstanceForDesktopFile(const QFileInfo& fi); |
378 | + virtual DesktopFileReader* createInstance(const QString &appId, const QFileInfo& fi); |
379 | }; |
380 | |
381 | virtual ~DesktopFileReader(); |
382 | @@ -50,13 +49,11 @@ |
383 | virtual QString path() const { return entries_[kPathIndex]; } |
384 | virtual QString stageHint() const { return entries_[kStageHintIndex]; } |
385 | virtual bool loaded() const { return loaded_; } |
386 | - virtual QString findDesktopFile(const QString &appId) const; |
387 | |
388 | protected: |
389 | friend class DesktopFileReaderFactory; |
390 | |
391 | - DesktopFileReader(const QString &appId); |
392 | - DesktopFileReader(const QFileInfo &desktopFile); |
393 | + DesktopFileReader(const QString &appId, const QFileInfo &desktopFile); |
394 | |
395 | private: |
396 | static const int kNameIndex = 0, |
397 | |
398 | === modified file 'src/modules/Unity/Application/taskcontroller.cpp' |
399 | --- src/modules/Unity/Application/taskcontroller.cpp 2014-02-28 16:51:31 +0000 |
400 | +++ src/modules/Unity/Application/taskcontroller.cpp 2014-05-19 18:20:32 +0000 |
401 | @@ -107,6 +107,11 @@ |
402 | return m_appController->appIdHasProcessId(pid, appId); |
403 | } |
404 | |
405 | +QFileInfo TaskController::findDesktopFileForAppId(const QString &appId) const |
406 | +{ |
407 | + return m_appController->findDesktopFileForAppId(appId); |
408 | +} |
409 | + |
410 | bool TaskController::suspend(const QString& appId) |
411 | { |
412 | DLOG("TaskController::suspend (this=%p, application=%p)", this, qPrintable(appId)); |
413 | |
414 | === modified file 'src/modules/Unity/Application/taskcontroller.h' |
415 | --- src/modules/Unity/Application/taskcontroller.h 2014-02-28 16:51:31 +0000 |
416 | +++ src/modules/Unity/Application/taskcontroller.h 2014-05-19 18:20:32 +0000 |
417 | @@ -45,6 +45,7 @@ |
418 | bool resume(const QString& appId); |
419 | |
420 | bool appIdHasProcessId(const QString& appId, const quint64 pid); |
421 | + QFileInfo findDesktopFileForAppId(const QString &appId) const; |
422 | |
423 | Q_SIGNALS: |
424 | void processStartReport(const QString& appId, const bool failure); |
425 | |
426 | === modified file 'src/modules/Unity/Application/upstart/applicationcontroller.cpp' |
427 | --- src/modules/Unity/Application/upstart/applicationcontroller.cpp 2014-04-16 17:45:59 +0000 |
428 | +++ src/modules/Unity/Application/upstart/applicationcontroller.cpp 2014-05-19 18:20:32 +0000 |
429 | @@ -20,6 +20,9 @@ |
430 | // unity-mir |
431 | #include <logging.h> |
432 | |
433 | +// Qt |
434 | +#include <QStandardPaths> |
435 | + |
436 | // upstart |
437 | extern "C" { |
438 | #include "upstart-app-launch.h" |
439 | @@ -40,33 +43,89 @@ |
440 | upstart_app_launch_app_failed_observer_t failureCallback = nullptr; |
441 | }; |
442 | |
443 | +namespace { |
444 | +/** |
445 | + * @brief toShortAppIdIfPossible |
446 | + * @param appId - any string that you think is an appId |
447 | + * @return if a valid appId was input, a shortened appId is returned, else returns the input string unaltered |
448 | + */ |
449 | +QString toShortAppIdIfPossible(const QString &appId) { |
450 | + gchar *package, *application; |
451 | + if (upstart_app_launch_app_id_parse(appId.toLatin1().constData(), &package, &application, nullptr)) { |
452 | + // is long appId, so assemble its short appId |
453 | + QString shortAppId = QString("%1_%2").arg(package).arg(application); |
454 | + g_free(package); |
455 | + g_free(application); |
456 | + return shortAppId; |
457 | + } else { |
458 | + return appId; |
459 | + } |
460 | +} |
461 | + |
462 | +/** |
463 | + * @brief toLongAppIdIfPossible |
464 | + * @param shortAppId - any string that you think is a short appId |
465 | + * @return if valid short appId was input, the corresponding long appId is returned. If a long appId was |
466 | + * entered, it is returned unchanged. Anything else is also returned unchanged. |
467 | + */ |
468 | +QString toLongAppIdIfPossible(const QString &shortAppId) { |
469 | + if (upstart_app_launch_app_id_parse(shortAppId.toLatin1().constData(), nullptr, nullptr, nullptr)) { |
470 | + // then we got a long appId after all, just return it |
471 | + return shortAppId; |
472 | + } else { |
473 | + // try to parse the string in the form "$package_$application" |
474 | + QRegExp shortAppIdMask("[a-z0-9][a-z0-9+.-]+_[a-zA-Z0-9+.-]+"); |
475 | + if (!shortAppIdMask.exactMatch(shortAppId)) { |
476 | + // input string not a short appId, so just return it unchanged |
477 | + return shortAppId; |
478 | + } |
479 | + |
480 | + // ask upstart for the long appId corresponding to this short appId |
481 | + QStringList parts = shortAppId.split("_"); |
482 | + gchar *longAppId; |
483 | + longAppId = upstart_app_launch_triplet_to_app_id(parts.first().toLatin1().constData(), |
484 | + parts.last().toLatin1().constData(), |
485 | + nullptr); |
486 | + if (longAppId == nullptr) { |
487 | + // was unable to construct a long appId from the short appId, return input unchanged |
488 | + return shortAppId; |
489 | + } else { |
490 | + QString appId(longAppId); |
491 | + g_free(longAppId); |
492 | + return appId; |
493 | + } |
494 | + } |
495 | +} |
496 | + |
497 | +} // namespace |
498 | + |
499 | ApplicationController::ApplicationController() |
500 | : unitymir::ApplicationController(), |
501 | impl(new Private()) |
502 | { |
503 | impl->preStartCallback = [](const gchar * appId, gpointer userData) { |
504 | auto thiz = static_cast<ApplicationController*>(userData); |
505 | - Q_EMIT(thiz->applicationAboutToBeStarted(appId)); |
506 | + Q_EMIT(thiz->applicationAboutToBeStarted(toShortAppIdIfPossible(appId))); |
507 | }; |
508 | |
509 | impl->startedCallback = [](const gchar * appId, gpointer userData) { |
510 | auto thiz = static_cast<ApplicationController*>(userData); |
511 | - Q_EMIT(thiz->applicationStarted(appId)); |
512 | + Q_EMIT(thiz->applicationStarted(toShortAppIdIfPossible(appId))); |
513 | }; |
514 | |
515 | impl->stopCallback = [](const gchar * appId, gpointer userData) { |
516 | auto thiz = static_cast<ApplicationController*>(userData); |
517 | - Q_EMIT(thiz->applicationStopped(appId)); |
518 | + Q_EMIT(thiz->applicationStopped(toShortAppIdIfPossible(appId))); |
519 | }; |
520 | |
521 | impl->focusCallback = [](const gchar * appId, gpointer userData) { |
522 | auto thiz = static_cast<ApplicationController*>(userData); |
523 | - Q_EMIT(thiz->applicationFocusRequest(appId)); |
524 | + Q_EMIT(thiz->applicationFocusRequest(toShortAppIdIfPossible(appId))); |
525 | }; |
526 | |
527 | impl->resumeCallback = [](const gchar * appId, gpointer userData) { |
528 | auto thiz = static_cast<ApplicationController*>(userData); |
529 | - Q_EMIT(thiz->applicationResumeRequest(appId)); |
530 | + Q_EMIT(thiz->applicationResumeRequest(toShortAppIdIfPossible(appId))); |
531 | }; |
532 | |
533 | impl->failureCallback = [](const gchar * appId, upstart_app_launch_app_failed_t failureType, gpointer userData) { |
534 | @@ -78,7 +137,7 @@ |
535 | } |
536 | |
537 | auto thiz = static_cast<ApplicationController*>(userData); |
538 | - Q_EMIT(thiz->applicationError(appId, error)); |
539 | + Q_EMIT(thiz->applicationError(toShortAppIdIfPossible(appId), error)); |
540 | }; |
541 | |
542 | upstart_app_launch_observer_add_app_starting(impl->preStartCallback, this); |
543 | @@ -101,7 +160,7 @@ |
544 | |
545 | pid_t ApplicationController::primaryPidForAppId(const QString& appId) |
546 | { |
547 | - GPid pid = upstart_app_launch_get_primary_pid(appId.toLatin1().constData()); |
548 | + GPid pid = upstart_app_launch_get_primary_pid(toLongAppIdIfPossible(appId).toLatin1().constData()); |
549 | DLOG_IF(!pid, "ApplicationController::stopApplication appId='%s' FAILED", qPrintable(appId)); |
550 | |
551 | return pid; |
552 | @@ -109,12 +168,12 @@ |
553 | |
554 | bool ApplicationController::appIdHasProcessId(pid_t pid, const QString& appId) |
555 | { |
556 | - return upstart_app_launch_pid_in_app_id(pid, appId.toLatin1().constData()); |
557 | + return upstart_app_launch_pid_in_app_id(pid, toLongAppIdIfPossible(appId).toLatin1().constData()); |
558 | } |
559 | |
560 | bool ApplicationController::stopApplicationWithAppId(const QString& appId) |
561 | { |
562 | - auto result = upstart_app_launch_stop_application(appId.toLatin1().constData()); |
563 | + auto result = upstart_app_launch_stop_application(toLongAppIdIfPossible(appId).toLatin1().constData()); |
564 | DLOG_IF(!result, "ApplicationController::stopApplicationWithAppId appId='%s' FAILED", qPrintable(appId)); |
565 | return result; |
566 | } |
567 | @@ -130,7 +189,7 @@ |
568 | } |
569 | |
570 | auto result = upstart_app_launch_start_application( |
571 | - appId.toLatin1().constData(), |
572 | + toLongAppIdIfPossible(appId).toLatin1().constData(), |
573 | static_cast<const gchar * const *>(upstartArgs)); |
574 | |
575 | g_strfreev(upstartArgs); |
576 | @@ -139,5 +198,28 @@ |
577 | return result; |
578 | } |
579 | |
580 | +QFileInfo ApplicationController::findDesktopFileForAppId(const QString &appId) const |
581 | +{ |
582 | + DLOG("ApplicationController::desktopFilePathForAppId (appId='%s')", qPrintable(appId)); |
583 | + |
584 | + // Search for the correct desktop file using a simple heuristic |
585 | + int dashPos = -1; |
586 | + QString helper = toLongAppIdIfPossible(appId); |
587 | + QString desktopFile; |
588 | + |
589 | + do { |
590 | + if (dashPos != -1) { |
591 | + helper = helper.replace(dashPos, 1, '/'); |
592 | + } |
593 | + |
594 | + desktopFile = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, QString("%1.desktop").arg(helper)); |
595 | + if (!desktopFile.isEmpty()) return desktopFile; |
596 | + |
597 | + dashPos = helper.indexOf("-"); |
598 | + } while (dashPos != -1); |
599 | + |
600 | + return QFileInfo(); |
601 | +} |
602 | + |
603 | } // namespace upstart |
604 | } // namespace unitymir |
605 | |
606 | === modified file 'src/modules/Unity/Application/upstart/applicationcontroller.h' |
607 | --- src/modules/Unity/Application/upstart/applicationcontroller.h 2014-02-28 16:51:31 +0000 |
608 | +++ src/modules/Unity/Application/upstart/applicationcontroller.h 2014-05-19 18:20:32 +0000 |
609 | @@ -31,11 +31,13 @@ |
610 | ApplicationController(); |
611 | ~ApplicationController(); |
612 | |
613 | - pid_t primaryPidForAppId(const QString& appId); |
614 | - bool appIdHasProcessId(pid_t pid, const QString& appId); |
615 | - |
616 | - bool stopApplicationWithAppId(const QString& appId); |
617 | - bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments); |
618 | + pid_t primaryPidForAppId(const QString& appId) override; |
619 | + bool appIdHasProcessId(pid_t pid, const QString& appId) override; |
620 | + |
621 | + bool stopApplicationWithAppId(const QString& appId) override; |
622 | + bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) override; |
623 | + |
624 | + QFileInfo findDesktopFileForAppId(const QString &appId) const override; |
625 | |
626 | private: |
627 | struct Private; |
628 | |
629 | === modified file 'src/unity-mir/messageprocessor.cpp' |
630 | --- src/unity-mir/messageprocessor.cpp 2014-02-06 12:12:21 +0000 |
631 | +++ src/unity-mir/messageprocessor.cpp 2014-05-19 18:20:32 +0000 |
632 | @@ -39,6 +39,11 @@ |
633 | } |
634 | } |
635 | |
636 | +void MessageProcessor::client_pid(int pid) |
637 | +{ |
638 | + m_wrapped->client_pid(pid); |
639 | +} |
640 | + |
641 | void MessageProcessor::send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response) |
642 | { |
643 | m_sender->send_response(id, response, {}); |
644 | |
645 | === modified file 'src/unity-mir/messageprocessor.h' |
646 | --- src/unity-mir/messageprocessor.h 2014-02-06 12:12:21 +0000 |
647 | +++ src/unity-mir/messageprocessor.h 2014-05-19 18:20:32 +0000 |
648 | @@ -33,6 +33,7 @@ |
649 | m_unityService(unityService) {} |
650 | |
651 | bool dispatch(mir::frontend::detail::Invocation const& invocation); |
652 | + void client_pid(int pid); |
653 | |
654 | void send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response); |
655 | |
656 | |
657 | === modified file 'src/unity-mir/sessionauthorizer.cpp' |
658 | --- src/unity-mir/sessionauthorizer.cpp 2014-03-27 14:22:08 +0000 |
659 | +++ src/unity-mir/sessionauthorizer.cpp 2014-05-19 18:20:32 +0000 |
660 | @@ -17,6 +17,10 @@ |
661 | #include "sessionauthorizer.h" |
662 | #include "logging.h" |
663 | |
664 | +#include <mir/frontend/session_credentials.h> |
665 | + |
666 | +namespace mf = mir::frontend; |
667 | + |
668 | SessionAuthorizer::SessionAuthorizer(QObject *parent) |
669 | : QObject(parent) |
670 | { |
671 | @@ -26,28 +30,28 @@ |
672 | { |
673 | } |
674 | |
675 | -bool SessionAuthorizer::connection_is_allowed(pid_t pid) |
676 | +bool SessionAuthorizer::connection_is_allowed(mf::SessionCredentials const& creds) |
677 | { |
678 | - DLOG("SessionAuthorizer::connection_is_allowed (this=%p, pid=%d", this, pid); |
679 | + DLOG("SessionAuthorizer::connection_is_allowed (this=%p, pid=%d", this, creds.pid()); |
680 | bool authorized = true; |
681 | |
682 | - Q_EMIT requestAuthorizationForSession(pid, authorized); // needs to block until authorized value returned |
683 | + Q_EMIT requestAuthorizationForSession(creds.pid(), authorized); // needs to block until authorized value returned |
684 | return authorized; |
685 | } |
686 | |
687 | -bool SessionAuthorizer::configure_display_is_allowed(pid_t pid) |
688 | +bool SessionAuthorizer::configure_display_is_allowed(mf::SessionCredentials const& creds) |
689 | { |
690 | - DLOG("SessionAuthorizer::configure_display_is_allowed (this=%p, pid=%d)", this, pid); |
691 | + DLOG("SessionAuthorizer::configure_display_is_allowed (this=%p, pid=%d)", this, creds.pid()); |
692 | |
693 | //FIXME(ricmm) Actually mediate this access for clients |
694 | - Q_UNUSED(pid) |
695 | + Q_UNUSED(creds) |
696 | return true; |
697 | } |
698 | |
699 | -bool SessionAuthorizer::screencast_is_allowed(pid_t pid) |
700 | +bool SessionAuthorizer::screencast_is_allowed(mf::SessionCredentials const& creds) |
701 | { |
702 | - DLOG("SessionAuthorizer::screencast_is_allowed (this=%p, pid=%d)", this, pid); |
703 | - Q_UNUSED(pid) |
704 | + DLOG("SessionAuthorizer::screencast_is_allowed (this=%p, pid=%d)", this, creds.pid()); |
705 | + Q_UNUSED(creds) |
706 | return true; |
707 | } |
708 | |
709 | |
710 | === modified file 'src/unity-mir/sessionauthorizer.h' |
711 | --- src/unity-mir/sessionauthorizer.h 2014-03-27 14:22:08 +0000 |
712 | +++ src/unity-mir/sessionauthorizer.h 2014-05-19 18:20:32 +0000 |
713 | @@ -34,9 +34,9 @@ |
714 | SessionAuthorizer(QObject *parent = 0); |
715 | ~SessionAuthorizer(); |
716 | |
717 | - virtual bool connection_is_allowed(pid_t pid) override; |
718 | - virtual bool configure_display_is_allowed(pid_t pid) override; |
719 | - virtual bool screencast_is_allowed(pid_t pid) override; |
720 | + virtual bool connection_is_allowed(mir::frontend::SessionCredentials const& creds) override; |
721 | + virtual bool configure_display_is_allowed(mir::frontend::SessionCredentials const& creds) override; |
722 | + virtual bool screencast_is_allowed(mir::frontend::SessionCredentials const& creds) override; |
723 | |
724 | Q_SIGNALS: |
725 | // needs to be blocked queued signal which returns value for authorized |
726 | |
727 | === modified file 'src/unity-mir/sessioncreator.cpp' |
728 | --- src/unity-mir/sessioncreator.cpp 2014-02-06 12:12:21 +0000 |
729 | +++ src/unity-mir/sessioncreator.cpp 2014-05-19 18:20:32 +0000 |
730 | @@ -22,17 +22,17 @@ |
731 | std::shared_ptr<mir::frontend::ProtobufIpcFactory> const& ipc_factory, |
732 | std::shared_ptr<mir::frontend::SessionAuthorizer> const& session_authorizer, |
733 | std::shared_ptr<mir::frontend::MessageProcessorReport> const& report) |
734 | - : ProtobufSessionCreator(ipc_factory, session_authorizer, report) |
735 | + : ProtobufConnectionCreator(ipc_factory, session_authorizer, report) |
736 | , m_unityService(unityService) |
737 | { |
738 | } |
739 | |
740 | std::shared_ptr<mir::frontend::detail::MessageProcessor> SessionCreator::create_processor( |
741 | std::shared_ptr<mir::frontend::detail::ProtobufMessageSender> const& sender, |
742 | - std::shared_ptr<mir::protobuf::DisplayServer> const& display_server, |
743 | + std::shared_ptr<mir::frontend::detail::DisplayServer> const& display_server, |
744 | std::shared_ptr<mir::frontend::MessageProcessorReport> const& report) const |
745 | { |
746 | - auto const wrapped = mir::frontend::ProtobufSessionCreator::create_processor( |
747 | + auto const wrapped = mir::frontend::ProtobufConnectionCreator::create_processor( |
748 | sender, |
749 | display_server, |
750 | report); |
751 | |
752 | === modified file 'src/unity-mir/sessioncreator.h' |
753 | --- src/unity-mir/sessioncreator.h 2014-02-06 12:12:21 +0000 |
754 | +++ src/unity-mir/sessioncreator.h 2014-05-19 18:20:32 +0000 |
755 | @@ -17,7 +17,7 @@ |
756 | #ifndef SESSIONCREATOR_H |
757 | #define SESSIONCREATOR_H |
758 | |
759 | -#include <mir/frontend/protobuf_session_creator.h> |
760 | +#include <mir/frontend/protobuf_connection_creator.h> |
761 | |
762 | namespace unity { |
763 | namespace protobuf { |
764 | @@ -25,7 +25,7 @@ |
765 | } |
766 | } |
767 | |
768 | -class SessionCreator : public mir::frontend::ProtobufSessionCreator |
769 | +class SessionCreator : public mir::frontend::ProtobufConnectionCreator |
770 | { |
771 | public: |
772 | SessionCreator( |
773 | @@ -36,7 +36,7 @@ |
774 | |
775 | std::shared_ptr<mir::frontend::detail::MessageProcessor> create_processor( |
776 | std::shared_ptr<mir::frontend::detail::ProtobufMessageSender> const& sender, |
777 | - std::shared_ptr<mir::protobuf::DisplayServer> const& display_server, |
778 | + std::shared_ptr<mir::frontend::detail::DisplayServer> const& display_server, |
779 | std::shared_ptr<mir::frontend::MessageProcessorReport> const& report) const override; |
780 | private: |
781 | std::shared_ptr<unity::protobuf::UnityService> m_unityService; |
782 | |
783 | === modified file 'src/unity-mir/shellserverconfiguration.cpp' |
784 | --- src/unity-mir/shellserverconfiguration.cpp 2014-04-15 14:31:02 +0000 |
785 | +++ src/unity-mir/shellserverconfiguration.cpp 2014-05-19 18:20:32 +0000 |
786 | @@ -94,10 +94,10 @@ |
787 | }); |
788 | } |
789 | |
790 | -std::shared_ptr<mir::frontend::SessionCreator> |
791 | -ShellServerConfiguration::the_session_creator() |
792 | +std::shared_ptr<mir::frontend::ConnectionCreator> |
793 | +ShellServerConfiguration::the_connection_creator() |
794 | { |
795 | - return session_creator([this] |
796 | + return connection_creator([this] |
797 | { |
798 | return std::make_shared<SessionCreator>( |
799 | m_unityService, |
800 | |
801 | === modified file 'src/unity-mir/shellserverconfiguration.h' |
802 | --- src/unity-mir/shellserverconfiguration.h 2014-04-15 14:31:02 +0000 |
803 | +++ src/unity-mir/shellserverconfiguration.h 2014-05-19 18:20:32 +0000 |
804 | @@ -52,7 +52,7 @@ |
805 | std::shared_ptr<mir::shell::FocusSetter> the_shell_focus_setter() override; |
806 | std::shared_ptr<mir::ServerStatusListener> the_server_status_listener() override; |
807 | std::shared_ptr<mir::frontend::SessionAuthorizer> the_session_authorizer() override; |
808 | - std::shared_ptr<mir::frontend::SessionCreator> the_session_creator() override; |
809 | + std::shared_ptr<mir::frontend::ConnectionCreator> the_connection_creator() override; |
810 | |
811 | /* qt specific */ |
812 | // getters |
813 | |
814 | === modified file 'tests/application_manager_test.cpp' |
815 | --- tests/application_manager_test.cpp 2014-04-15 14:31:02 +0000 |
816 | +++ tests/application_manager_test.cpp 2014-05-19 18:20:32 +0000 |
817 | @@ -82,8 +82,9 @@ |
818 | const QString appId("com.canonical.does.not.exist"); |
819 | |
820 | EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(_, _)).Times(1); |
821 | + EXPECT_CALL(appController, findDesktopFileForAppId(appId)).Times(1); |
822 | |
823 | - EXPECT_CALL(desktopFileReaderFactory, createInstanceForAppId(appId)).Times(1); |
824 | + EXPECT_CALL(desktopFileReaderFactory, createInstance(_, _)).Times(1); |
825 | |
826 | EXPECT_CALL(processController, sigStopProcessGroupForPid(_)).Times(1); |
827 | EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1); |
828 | @@ -225,6 +226,85 @@ |
829 | EXPECT_EQ(beforeFailure, afterFailure); |
830 | } |
831 | |
832 | +TEST_F(ApplicationManagerTests,startApplicationSupportsShortAppId) |
833 | +{ |
834 | + using namespace ::testing; |
835 | + |
836 | + const QString shortAppId("com.canonical.test_test"); |
837 | + |
838 | + EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(_, _)).Times(1); |
839 | + EXPECT_CALL(appController, findDesktopFileForAppId(shortAppId)).Times(1); |
840 | + |
841 | + EXPECT_CALL(desktopFileReaderFactory, createInstance(_, _)).Times(1); |
842 | + |
843 | + auto application = applicationManager.startApplication( |
844 | + shortAppId, |
845 | + ApplicationManager::NoFlag, |
846 | + QStringList()); |
847 | + |
848 | + EXPECT_EQ(shortAppId, application->appId()); |
849 | +} |
850 | + |
851 | +TEST_F(ApplicationManagerTests,startApplicationSupportsLongAppId) |
852 | +{ |
853 | + using namespace ::testing; |
854 | + |
855 | + const QString longAppId("com.canonical.test_test_0.1.235"); |
856 | + const QString shortAppId("com.canonical.test_test"); |
857 | + |
858 | + EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(_, _)).Times(1); |
859 | + EXPECT_CALL(appController, findDesktopFileForAppId(shortAppId)).Times(1); |
860 | + |
861 | + EXPECT_CALL(desktopFileReaderFactory, createInstance(_, _)).Times(1); |
862 | + |
863 | + auto application = applicationManager.startApplication( |
864 | + longAppId, |
865 | + ApplicationManager::NoFlag, |
866 | + QStringList()); |
867 | + |
868 | + EXPECT_EQ(shortAppId, application->appId()); |
869 | +} |
870 | + |
871 | +TEST_F(ApplicationManagerTests,testAppIdGuessFromDesktopFileName) |
872 | +{ |
873 | + using namespace ::testing; |
874 | + quint64 procId = 5921; |
875 | + QString appId("sudoku-app"); |
876 | + QString cmdLine = QString("/usr/bin/my-app --desktop_file_hint=/usr/share/click/preinstalled/com.ubuntu.sudoku/1.0.180/%1.desktop").arg(appId); |
877 | + |
878 | + EXPECT_CALL(procInfo,command_line(procId)) |
879 | + .Times(1) |
880 | + .WillOnce(Return(qPrintable(cmdLine))); |
881 | + |
882 | + bool authed = true; |
883 | + applicationManager.authorizeSession(procId, authed); |
884 | + Application *app = applicationManager.findApplication(appId); |
885 | + |
886 | + EXPECT_EQ(true, authed); |
887 | + EXPECT_NE(app, nullptr); |
888 | + EXPECT_EQ(appId, app->appId()); |
889 | +} |
890 | + |
891 | +TEST_F(ApplicationManagerTests,testAppIdGuessFromDesktopFileNameWithLongAppId) |
892 | +{ |
893 | + using namespace ::testing; |
894 | + quint64 procId = 5921; |
895 | + QString shortAppId("com.ubuntu.desktop_desktop"); |
896 | + QString cmdLine = QString("/usr/bin/my-app --desktop_file_hint=/usr/share/applications/%1_1.0.180.desktop").arg(shortAppId); |
897 | + |
898 | + EXPECT_CALL(procInfo,command_line(procId)) |
899 | + .Times(1) |
900 | + .WillOnce(Return(qPrintable(cmdLine))); |
901 | + |
902 | + bool authed = true; |
903 | + applicationManager.authorizeSession(procId, authed); |
904 | + Application *app = applicationManager.findApplication(shortAppId); |
905 | + |
906 | + EXPECT_EQ(true, authed); |
907 | + EXPECT_NE(app, nullptr); |
908 | + EXPECT_EQ(shortAppId, app->appId()); |
909 | +} |
910 | + |
911 | TEST_F(ApplicationManagerTests,bug_case_1281075_session_ptrs_always_distributed_to_last_started_app) |
912 | { |
913 | using namespace ::testing; |
914 | @@ -305,11 +385,13 @@ |
915 | using namespace ::testing; |
916 | QString appId("sideStage"); |
917 | |
918 | - auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId); |
919 | + EXPECT_CALL(appController, findDesktopFileForAppId(appId)).Times(1); |
920 | + |
921 | + auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId, QFileInfo()); |
922 | ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true)); |
923 | ON_CALL(*mockDesktopFileReader, stageHint()).WillByDefault(Return("SideStage")); |
924 | |
925 | - ON_CALL(desktopFileReaderFactory, createInstanceForAppId(appId)).WillByDefault(Return(mockDesktopFileReader)); |
926 | + ON_CALL(desktopFileReaderFactory, createInstance(appId, _)).WillByDefault(Return(mockDesktopFileReader)); |
927 | |
928 | // mock upstart launching an app which reports itself as sidestage, but we're on phone |
929 | applicationManager.onProcessStartReportReceived(appId, false); |
930 | |
931 | === modified file 'tests/mock_application_controller.h' |
932 | --- tests/mock_application_controller.h 2014-02-28 16:51:31 +0000 |
933 | +++ tests/mock_application_controller.h 2014-05-19 18:20:32 +0000 |
934 | @@ -30,6 +30,7 @@ |
935 | { |
936 | MOCK_METHOD1(primaryPidForAppId, pid_t(const QString& appId)); |
937 | MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&)); |
938 | + MOCK_CONST_METHOD1(findDesktopFileForAppId, QFileInfo(const QString &appId)); |
939 | |
940 | MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&)); |
941 | MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&)); |
942 | @@ -45,6 +46,10 @@ |
943 | .WillByDefault( |
944 | Invoke(this, &MockApplicationController::doAppIdHasProcessId)); |
945 | |
946 | + ON_CALL(*this, findDesktopFileForAppId(_)) |
947 | + .WillByDefault( |
948 | + Invoke(this, &MockApplicationController::doFindDesktopFileForAppId)); |
949 | + |
950 | ON_CALL(*this, stopApplicationWithAppId(_)) |
951 | .WillByDefault( |
952 | Invoke(this, &MockApplicationController::doStopApplicationWithAppId)); |
953 | @@ -72,6 +77,12 @@ |
954 | return it->pid() == pid; |
955 | } |
956 | |
957 | + QFileInfo doFindDesktopFileForAppId(const QString& appId) const |
958 | + { |
959 | + QString path = QString("/usr/share/applications/%1.desktop").arg(appId); |
960 | + return QFileInfo(path); |
961 | + } |
962 | + |
963 | bool doStopApplicationWithAppId(const QString& appId) |
964 | { |
965 | (void) appId; |
966 | |
967 | === modified file 'tests/mock_desktop_file_reader.h' |
968 | --- tests/mock_desktop_file_reader.h 2014-02-28 16:51:31 +0000 |
969 | +++ tests/mock_desktop_file_reader.h 2014-05-19 18:20:32 +0000 |
970 | @@ -26,38 +26,20 @@ |
971 | { |
972 | struct MockDesktopFileReader : public unitymir::DesktopFileReader |
973 | { |
974 | - MockDesktopFileReader(const QString& appId) |
975 | - : unitymir::DesktopFileReader(appId) |
976 | - { |
977 | - using namespace ::testing; |
978 | - |
979 | - ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile)); |
980 | - ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId)); |
981 | - ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName)); |
982 | - ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment)); |
983 | - ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon)); |
984 | - ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec)); |
985 | - ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath)); |
986 | - ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint)); |
987 | - ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded)); |
988 | - ON_CALL(*this, findDesktopFile(_)).WillByDefault(Invoke(this, &MockDesktopFileReader::doFindDesktopFile)); |
989 | - } |
990 | - |
991 | - MockDesktopFileReader(const QFileInfo& fileInfo) |
992 | - : DesktopFileReader(fileInfo) |
993 | - { |
994 | - using namespace ::testing; |
995 | - |
996 | - ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile)); |
997 | - ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId)); |
998 | - ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName)); |
999 | - ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment)); |
1000 | - ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon)); |
1001 | - ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec)); |
1002 | - ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath)); |
1003 | - ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint)); |
1004 | - ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded)); |
1005 | - ON_CALL(*this, findDesktopFile(_)).WillByDefault(Invoke(this, &MockDesktopFileReader::doFindDesktopFile)); |
1006 | + MockDesktopFileReader(const QString &appId, const QFileInfo& fileInfo) |
1007 | + : DesktopFileReader(appId, fileInfo) |
1008 | + { |
1009 | + using namespace ::testing; |
1010 | + |
1011 | + ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile)); |
1012 | + ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId)); |
1013 | + ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName)); |
1014 | + ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment)); |
1015 | + ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon)); |
1016 | + ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec)); |
1017 | + ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath)); |
1018 | + ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint)); |
1019 | + ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded)); |
1020 | } |
1021 | |
1022 | MOCK_CONST_METHOD0(file, QString()); |
1023 | @@ -69,7 +51,6 @@ |
1024 | MOCK_CONST_METHOD0(path, QString()); |
1025 | MOCK_CONST_METHOD0(stageHint, QString()); |
1026 | MOCK_CONST_METHOD0(loaded, bool()); |
1027 | - MOCK_CONST_METHOD1(findDesktopFile, QString(const QString&)); |
1028 | |
1029 | QString doFile() const |
1030 | { |
1031 | @@ -115,11 +96,6 @@ |
1032 | { |
1033 | return DesktopFileReader::loaded(); |
1034 | } |
1035 | - |
1036 | - QString doFindDesktopFile(const QString& appId) const |
1037 | - { |
1038 | - return DesktopFileReader::findDesktopFile(appId); |
1039 | - } |
1040 | }; |
1041 | |
1042 | struct MockDesktopFileReaderFactory : public unitymir::DesktopFileReader::Factory |
1043 | @@ -127,38 +103,23 @@ |
1044 | MockDesktopFileReaderFactory() |
1045 | { |
1046 | using namespace ::testing; |
1047 | - ON_CALL(*this, createInstanceForAppId(_)) |
1048 | - .WillByDefault( |
1049 | - Invoke( |
1050 | - this, |
1051 | - &MockDesktopFileReaderFactory::doCreateInstanceForAppId)); |
1052 | - ON_CALL(*this, createInstanceForDesktopFile(_)) |
1053 | - .WillByDefault( |
1054 | - Invoke( |
1055 | - this, |
1056 | - &MockDesktopFileReaderFactory::doCreateInstanceForDesktopFile)); |
1057 | - } |
1058 | - |
1059 | - virtual unitymir::DesktopFileReader* doCreateInstanceForAppId(const QString& appId) |
1060 | - { |
1061 | - using namespace ::testing; |
1062 | - auto instance = new NiceMock<MockDesktopFileReader>(appId); |
1063 | - ON_CALL(*instance, loaded()).WillByDefault(Return(true)); |
1064 | - |
1065 | - return instance; |
1066 | - } |
1067 | - |
1068 | - virtual unitymir::DesktopFileReader* doCreateInstanceForDesktopFile(const QFileInfo& fi) |
1069 | - { |
1070 | - using namespace ::testing; |
1071 | - auto instance = new NiceMock<MockDesktopFileReader>(fi); |
1072 | - ON_CALL(*instance, loaded()).WillByDefault(Return(true)); |
1073 | - |
1074 | - return instance; |
1075 | - } |
1076 | - |
1077 | - MOCK_METHOD1(createInstanceForAppId, unitymir::DesktopFileReader*(const QString&)); |
1078 | - MOCK_METHOD1(createInstanceForDesktopFile, unitymir::DesktopFileReader*(const QFileInfo&)); |
1079 | + ON_CALL(*this, createInstance(_, _)) |
1080 | + .WillByDefault( |
1081 | + Invoke( |
1082 | + this, |
1083 | + &MockDesktopFileReaderFactory::doCreateInstance)); |
1084 | + } |
1085 | + |
1086 | + virtual unitymir::DesktopFileReader* doCreateInstance(const QString &appId, const QFileInfo &fi) |
1087 | + { |
1088 | + using namespace ::testing; |
1089 | + auto instance = new NiceMock<MockDesktopFileReader>(appId, fi); |
1090 | + ON_CALL(*instance, loaded()).WillByDefault(Return(true)); |
1091 | + |
1092 | + return instance; |
1093 | + } |
1094 | + |
1095 | + MOCK_METHOD2(createInstance, unitymir::DesktopFileReader*(const QString &appId, const QFileInfo &fi)); |
1096 | }; |
1097 | } |
1098 | |
1099 | |
1100 | === modified file 'tests/taskcontroller_test.cpp' |
1101 | --- tests/taskcontroller_test.cpp 2014-02-28 16:51:31 +0000 |
1102 | +++ tests/taskcontroller_test.cpp 2014-05-19 18:20:32 +0000 |
1103 | @@ -49,6 +49,8 @@ |
1104 | |
1105 | MOCK_METHOD1(primaryPidForAppId, pid_t (const QString&)); |
1106 | MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&)); |
1107 | + MOCK_CONST_METHOD1(findDesktopFileForAppId, QFileInfo(const QString &appId)); |
1108 | + |
1109 | MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&)); |
1110 | MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&)); |
1111 | }; |
FAILED: Continuous integration, rev:221 jenkins. qa.ubuntu. com/job/ unity-mir- devel-ci/ 4/ jenkins. qa.ubuntu. com/job/ unity-mir- devel-utopic- amd64-ci/ 4/console jenkins. qa.ubuntu. com/job/ unity-mir- devel-utopic- armhf-ci/ 4/console jenkins. qa.ubuntu. com/job/ unity-mir- devel-utopic- i386-ci/ 4/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- mir-devel- ci/4/rebuild
http://