Merge lp:~justinmcp/unity-chromium-extension/native-messaging-2 into lp:~webapps/unity-chromium-extension/staging
- native-messaging-2
- Merge into staging
Status: | Merged |
---|---|
Approved by: | Alberto Mardegan |
Approved revision: | 267 |
Merged at revision: | 255 |
Proposed branch: | lp:~justinmcp/unity-chromium-extension/native-messaging-2 |
Merge into: | lp:~webapps/unity-chromium-extension/staging |
Diff against target: |
882 lines (+590/-102) 12 files modified
README (+0/-1) chromium-extension/background-page.js (+4/-4) common-vars.pri (+1/-1) debian/changelog (+5/-5) debian/control (+1/-2) messaging-host/installation-host (+0/-74) messaging-host/main.cpp (+8/-4) messaging-host/messaging-host.pro (+7/-0) messaging-host/webapps-handler.cpp (+208/-10) tests/unit/messaging-host/messaging-host.pro (+2/-1) tests/unit/messaging-host/tst_webapps-handler.cpp (+324/-0) tests/unit/messaging-host/tst_webapps-handler.pro (+30/-0) |
To merge this branch: | bzr merge lp:~justinmcp/unity-chromium-extension/native-messaging-2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alberto Mardegan (community) | Approve | ||
Review via email: mp+221666@code.launchpad.net |
Commit message
Description of the change
Alberto Mardegan (mardy) wrote : | # |
Alberto Mardegan (mardy) wrote : | # |
I tested it with launchpad.net, and seems to work well! :-)
- 268. By Justin McPherson
-
Results of review
Justin McPherson (justinmcp) : | # |
Justin McPherson (justinmcp) wrote : | # |
@mardy; I have inverted the result of the installed. It is true that
allowed does not imply installed, but in this scenario, it is correct to
return an installed status.
On Wed, Jun 4, 2014 at 11:30 AM, <email address hidden> wrote:
> The proposal to merge
> lp:~justinmcp/unity-chromium-extension/native-messaging-2 into
> lp:~webapps/unity-chromium-extension/staging has been updated.
>
> Status: Approved => Merged
>
> For more details, see:
>
> https:/
> --
>
> https:/
> You are the owner of
> lp:~justinmcp/unity-chromium-extension/native-messaging-2.
>
Preview Diff
1 | === removed file 'AUTHORS' |
2 | === removed file 'NEWS' |
3 | === removed file 'README' |
4 | --- README 2012-11-14 20:26:07 +0000 |
5 | +++ README 1970-01-01 00:00:00 +0000 |
6 | @@ -1,1 +0,0 @@ |
7 | -+ |
8 | \ No newline at end of file |
9 | |
10 | === modified file 'chromium-extension/background-page.js' |
11 | --- chromium-extension/background-page.js 2014-05-21 07:36:09 +0000 |
12 | +++ chromium-extension/background-page.js 2014-06-04 01:24:00 +0000 |
13 | @@ -109,12 +109,12 @@ |
14 | windowInfos.tabId, |
15 | function (result) { |
16 | if (result && result.integrate) { |
17 | - sendNativeMessaging({ |
18 | + sendNativeMessage({ |
19 | "method" : "install", |
20 | "url" : url |
21 | }) |
22 | } else { |
23 | - sendNativeMessaging({ |
24 | + sendNativeMessage({ |
25 | "method" : "dont_ask", |
26 | "url" : url |
27 | }) |
28 | @@ -169,12 +169,12 @@ |
29 | sender.tab.id, |
30 | function (result) { |
31 | if (result && result.integrate) { |
32 | - sendNativeMessaging({ |
33 | + sendNativeMessage({ |
34 | "method" : "install", |
35 | "url" : request.options.url |
36 | }) |
37 | } else { |
38 | - sendNativeMessaging({ |
39 | + sendNativeMessage({ |
40 | "method" : "dont_ask", |
41 | "url" : request.options.url |
42 | }) |
43 | |
44 | === modified file 'common-vars.pri' |
45 | --- common-vars.pri 2014-05-19 14:04:19 +0000 |
46 | +++ common-vars.pri 2014-06-04 01:24:00 +0000 |
47 | @@ -3,4 +3,4 @@ |
48 | #----------------------------------------------------------------------------- |
49 | |
50 | PROJECT_NAME = unity_webapps_chromium |
51 | -PROJECT_VERSION = 3.1 |
52 | +PROJECT_VERSION = 3.2 |
53 | |
54 | === modified file 'debian/changelog' |
55 | --- debian/changelog 2014-05-14 07:59:30 +0000 |
56 | +++ debian/changelog 2014-06-04 01:24:00 +0000 |
57 | @@ -1,8 +1,8 @@ |
58 | -unity-chromium-extension (3.1.0+14.04.20140318-0ubuntu2) UNRELEASED; urgency=medium |
59 | - |
60 | - * Support native messaging. |
61 | - |
62 | - -- Justin McPherson <justin@ubuntu> Thu, 08 May 2014 14:25:18 +1000 |
63 | +unity-chromium-extension (3.2.0+14.04.20140318-0ubuntu3) UNRELEASED; urgency=medium |
64 | + |
65 | + * Support native messaging. (with Alberto Mardegan) |
66 | + |
67 | + -- Justin McPherson <justin.mcpherson@canonical.com> Fri, 23 May 2014 20:31:14 +1000 |
68 | |
69 | unity-chromium-extension (3.0.0+14.04.20140318-0ubuntu1) trusty; urgency=low |
70 | |
71 | |
72 | === modified file 'debian/control' |
73 | --- debian/control 2014-05-14 07:59:30 +0000 |
74 | +++ debian/control 2014-06-04 01:24:00 +0000 |
75 | @@ -4,7 +4,6 @@ |
76 | # FIXME: We should be using debhelper 9, but that breaks the build |
77 | # for some currently unknown reason. |
78 | Build-Depends: autotools-dev, |
79 | -# chromium-browser (>= 20.0.1132.47~r144678-0ubuntu4), |
80 | debhelper (>= 8), |
81 | dh-autoreconf, |
82 | gnome-common, |
83 | @@ -27,7 +26,7 @@ |
84 | |
85 | Package: unity-chromium-extension |
86 | Architecture: any |
87 | -Depends: chromium-browser (>= 20.0.1132.47~r144678-0ubuntu4), |
88 | +Depends: chromium-browser (>= 34.0.1847.116-0ubuntu2), |
89 | unity-webapps-service, |
90 | webbrowser-app, |
91 | ${misc:Depends}, |
92 | |
93 | === removed directory 'm4' |
94 | === removed file 'messaging-host/installation-host' |
95 | --- messaging-host/installation-host 2014-05-21 07:15:14 +0000 |
96 | +++ messaging-host/installation-host 1970-01-01 00:00:00 +0000 |
97 | @@ -1,74 +0,0 @@ |
98 | -#!/usr/bin/python |
99 | - |
100 | -import sys |
101 | -import select |
102 | -import struct |
103 | -import json |
104 | -from syslog import syslog |
105 | - |
106 | - |
107 | -SELECT_TIMEOUT = 10 # seconds |
108 | - |
109 | -def handle_start_service(message): |
110 | - syslog('NMH: handle_start_sevice') |
111 | - return {} |
112 | - |
113 | -def handle_url_loaded(message): |
114 | - syslog('NMH: handle_url_loaded') |
115 | - if message['url'] == 'http://slashdot.org/': |
116 | - return { 'available': True, "appName" : "Slashdot", "appDomain" : "http://slashdot.org/" } |
117 | - else: |
118 | - return { 'available' : False } |
119 | - |
120 | -def handle_dont_ask(message): |
121 | - return {} |
122 | - |
123 | -def handle_install(message): |
124 | - return {} |
125 | - |
126 | -def handle_message(message): |
127 | - syslog("NMH: handle message"); |
128 | - if message['method'] == 'start_service': |
129 | - return handle_start_service(message) |
130 | - if message['method'] == 'url_loaded': |
131 | - return handle_url_loaded(message); |
132 | - elif message['method'] == 'dont_ask': |
133 | - return handle_dont_ask(message); |
134 | - elif message['method'] == 'install': |
135 | - return handle_install(message); |
136 | - return {} |
137 | - |
138 | -def process_message(): |
139 | - syslog("NMH: process_message") |
140 | - try: |
141 | - packed_length = sys.stdin.read(4) |
142 | - if packed_length == '': |
143 | - return False |
144 | - length = struct.unpack('I', packed_length)[0] |
145 | - request = json.loads(sys.stdin.read(length).decode('utf-8')) |
146 | - reply = handle_message(request) |
147 | - |
148 | - syslog("recieved message from chrome %s" % request) |
149 | - reply = json.dumps(reply) |
150 | - sys.stdout.write(struct.pack('I', len(reply)) + reply) |
151 | - sys.stdout.flush() |
152 | - return True |
153 | - except Excepion, e: |
154 | - syslog("Exception from native host" + str(e)) |
155 | - sys.exit(1) |
156 | - |
157 | -def main(): |
158 | - while True: |
159 | - rl, wl, xl = select.select([sys.stdin],[],[], SELECT_TIMEOUT) |
160 | - if rl: |
161 | - if process_message() == False: |
162 | - syslog("Native Messaging Host: recved EOF") |
163 | - sys.exit(0) |
164 | - else: |
165 | - syslog("Native Messaging Host: timeout") |
166 | - sys.exit(0) |
167 | - |
168 | -if __name__ == '__main__': |
169 | - syslog("Started messaging host") |
170 | - main() |
171 | - |
172 | |
173 | === modified file 'messaging-host/main.cpp' |
174 | --- messaging-host/main.cpp 2014-05-22 07:10:55 +0000 |
175 | +++ messaging-host/main.cpp 2014-06-04 01:24:00 +0000 |
176 | @@ -46,7 +46,7 @@ |
177 | break; |
178 | } |
179 | |
180 | - syslog(syslog_type, "com.canonical.webapps.installer: %s", localMsg.constData()); |
181 | + syslog(syslog_type, "%s", localMsg.constData()); |
182 | } |
183 | |
184 | |
185 | @@ -56,7 +56,7 @@ |
186 | qInstallMessageHandler(syslogOutputHandler); |
187 | } |
188 | |
189 | - qDebug() << "started"; |
190 | + qDebug() << "Starting"; |
191 | |
192 | QCoreApplication app(argc, argv); |
193 | |
194 | @@ -64,7 +64,7 @@ |
195 | UnityWebapps::WebappsHandler handler; |
196 | service.addHandler(&handler); |
197 | |
198 | - UnityWebapps::InactivityTimer inactivityTimer(10 * 1000); |
199 | + UnityWebapps::InactivityTimer inactivityTimer(2 * 60 * 1000); |
200 | QObject::connect(&inactivityTimer, SIGNAL(timeout()), &app, SLOT(quit())); |
201 | inactivityTimer.watchObject(&service); |
202 | |
203 | @@ -79,6 +79,10 @@ |
204 | return EXIT_FAILURE; |
205 | } |
206 | |
207 | - return app.exec(); |
208 | + int r = app.exec(); |
209 | + |
210 | + qDebug() << "Finishing"; |
211 | + |
212 | + return r; |
213 | } |
214 | |
215 | |
216 | === modified file 'messaging-host/messaging-host.pro' |
217 | --- messaging-host/messaging-host.pro 2014-05-21 12:32:50 +0000 |
218 | +++ messaging-host/messaging-host.pro 2014-06-04 01:24:00 +0000 |
219 | @@ -4,11 +4,18 @@ |
220 | TARGET = unity-webapps-messaging-host |
221 | |
222 | CONFIG += \ |
223 | + link_pkgconfig \ |
224 | qt |
225 | |
226 | QT += \ |
227 | core |
228 | |
229 | +PKGCONFIG += \ |
230 | + glib-2.0 \ |
231 | + gobject-2.0 \ |
232 | + libunity_webapps-0.2 \ |
233 | + libunity-webapps-repository \ |
234 | + |
235 | SOURCES = \ |
236 | connection.cpp \ |
237 | inactivity-timer.cpp \ |
238 | |
239 | === modified file 'messaging-host/webapps-handler.cpp' |
240 | --- messaging-host/webapps-handler.cpp 2014-05-21 09:44:07 +0000 |
241 | +++ messaging-host/webapps-handler.cpp 2014-06-04 01:24:00 +0000 |
242 | @@ -16,6 +16,11 @@ |
243 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
244 | */ |
245 | |
246 | +extern "C" { |
247 | +#include <unity-webapps-permissions.h> |
248 | +#include <unity-webapps-application-repository.h> |
249 | +} |
250 | + |
251 | #include "webapps-handler.h" |
252 | |
253 | #include <QDebug> |
254 | @@ -32,20 +37,57 @@ |
255 | inline WebappsHandlerPrivate(WebappsHandler *service); |
256 | inline ~WebappsHandlerPrivate(); |
257 | |
258 | + UnityWebappsApplicationRepository *getRepository(); |
259 | + |
260 | private: |
261 | + static |
262 | + void installationCallback(UnityWebappsApplicationRepository *repository, |
263 | + const gchar *name, |
264 | + UnityWebappsApplicationStatus status, |
265 | + gpointer user_data); |
266 | + |
267 | mutable WebappsHandler *q_ptr; |
268 | + UnityWebappsApplicationRepository *applicationRepository; |
269 | }; |
270 | |
271 | } // namespace |
272 | |
273 | + |
274 | WebappsHandlerPrivate::WebappsHandlerPrivate(WebappsHandler *service): |
275 | - q_ptr(service) |
276 | + q_ptr(service), |
277 | + applicationRepository(0) |
278 | { |
279 | } |
280 | |
281 | WebappsHandlerPrivate::~WebappsHandlerPrivate() |
282 | { |
283 | -} |
284 | + if (applicationRepository != 0) { |
285 | + g_object_unref(G_OBJECT(applicationRepository)); |
286 | + } |
287 | +} |
288 | + |
289 | +UnityWebappsApplicationRepository *WebappsHandlerPrivate::getRepository() |
290 | +{ |
291 | + if (applicationRepository == 0) { |
292 | + applicationRepository = unity_webapps_application_repository_new_default(); |
293 | + unity_webapps_application_repository_prepare(applicationRepository); |
294 | + } |
295 | + return applicationRepository; |
296 | +} |
297 | + |
298 | +void WebappsHandlerPrivate::installationCallback( |
299 | + UnityWebappsApplicationRepository *repository, |
300 | + const gchar *name, |
301 | + UnityWebappsApplicationStatus status, |
302 | + gpointer user_data |
303 | +) |
304 | +{ |
305 | + Q_UNUSED(repository); |
306 | + Q_UNUSED(name); |
307 | + Q_UNUSED(status); |
308 | + Q_UNUSED(user_data); |
309 | +} |
310 | + |
311 | |
312 | WebappsHandler::WebappsHandler(QObject *parent): |
313 | QObject(parent), |
314 | @@ -60,26 +102,182 @@ |
315 | |
316 | QVariantMap WebappsHandler::url_loaded(const QVariantMap &message) |
317 | { |
318 | - qDebug() << Q_FUNC_INFO << message; |
319 | + Q_D(WebappsHandler); |
320 | + |
321 | QVariantMap reply; |
322 | - if (message.value("url").toString() == QStringLiteral("http://slashdot.org/")) { |
323 | - reply.insert("available", true); |
324 | - reply.insert("appName", QStringLiteral("Slashdot")); |
325 | - reply.insert("appDomain", QStringLiteral("http://slashdot.org/")); |
326 | - } |
327 | + |
328 | + if (!message.contains("url")) { |
329 | + reply.insert("error", QStringLiteral("malformed request")); |
330 | + return reply; |
331 | + } |
332 | + |
333 | + QString url = message.value("url").toString(); |
334 | + |
335 | + GList *apps = unity_webapps_application_repository_resolve_url( |
336 | + d->getRepository(), |
337 | + url.toLocal8Bit().constData() |
338 | + ); |
339 | + |
340 | + if (apps == 0) { |
341 | + reply.insert("available", false); |
342 | + return reply; |
343 | + } |
344 | + |
345 | + // As per original extension only look at the first entry |
346 | + const gchar *packageName = (const gchar*)apps->data; |
347 | + UnityWebappsApplicationStatus status = unity_webapps_application_repository_get_resolved_application_status( |
348 | + d->getRepository(), |
349 | + packageName); |
350 | + |
351 | + if (status == UNITY_WEBAPPS_APPLICATION_STATUS_UNRESOLVED) { |
352 | + reply.insert("available", false); |
353 | + g_list_free_full(apps, g_free); |
354 | + return reply; |
355 | + } |
356 | + |
357 | + const gchar *appName = unity_webapps_application_repository_get_resolved_application_name( |
358 | + d->getRepository(), |
359 | + packageName); |
360 | + |
361 | + const gchar *appDomain = unity_webapps_application_repository_get_resolved_application_domain( |
362 | + d->getRepository(), |
363 | + packageName); |
364 | + |
365 | + if (unity_webapps_permissions_get_domain_dontask(appDomain) || |
366 | + unity_webapps_permissions_get_domain_allowed(appDomain)) { |
367 | + reply.insert("available", false); |
368 | + g_list_free_full(apps, g_free); |
369 | + return reply; |
370 | + } |
371 | + |
372 | + reply.insert("available", true); |
373 | + reply.insert("appName", QString::fromUtf8(appName)); |
374 | + reply.insert("appDomain", QString::fromUtf8(appDomain)); |
375 | + |
376 | + g_list_free_full(apps, g_free); |
377 | + |
378 | return reply; |
379 | } |
380 | |
381 | QVariantMap WebappsHandler::dont_ask(const QVariantMap &message) |
382 | { |
383 | - qDebug() << Q_FUNC_INFO << message; |
384 | + Q_D(WebappsHandler); |
385 | + |
386 | QVariantMap reply; |
387 | + |
388 | + if (!message.contains("url")) { |
389 | + reply.insert("error", QLatin1String("malformed request")); |
390 | + return reply; |
391 | + } |
392 | + |
393 | + QString url = message.value("url").toString(); |
394 | + |
395 | + GList *apps = unity_webapps_application_repository_resolve_url( |
396 | + d->getRepository(), |
397 | + url.toLocal8Bit().constData() |
398 | + ); |
399 | + |
400 | + if (apps == 0) { |
401 | + reply.insert("available", false); |
402 | + reply.insert("dont_ask", false); |
403 | + return reply; |
404 | + } |
405 | + |
406 | + const gchar *packageName = (const gchar*)apps->data; |
407 | + |
408 | + const gchar *appDomain = unity_webapps_application_repository_get_resolved_application_domain( |
409 | + d->getRepository(), |
410 | + packageName); |
411 | + |
412 | + unity_webapps_permissions_dontask_domain(appDomain); |
413 | + |
414 | + reply.insert("dont_ask", true); |
415 | + |
416 | + g_list_free_full(apps, g_free); |
417 | + |
418 | return reply; |
419 | } |
420 | |
421 | QVariantMap WebappsHandler::install(const QVariantMap &message) |
422 | { |
423 | - qDebug() << Q_FUNC_INFO << message; |
424 | + Q_D(WebappsHandler); |
425 | + |
426 | QVariantMap reply; |
427 | + |
428 | + if (!message.contains("url")) { |
429 | + reply.insert("error", QLatin1String("malformed request")); |
430 | + return reply; |
431 | + } |
432 | + |
433 | + QString url = message.value("url").toString(); |
434 | + |
435 | + GList *apps = unity_webapps_application_repository_resolve_url( |
436 | + d->getRepository(), |
437 | + url.toLocal8Bit().constData() |
438 | + ); |
439 | + |
440 | + if (apps == 0) { |
441 | + reply.insert("available", false); |
442 | + reply.insert("installed", false); |
443 | + return reply; |
444 | + } |
445 | + |
446 | + const gchar *packageName = (const gchar*)apps->data; |
447 | + |
448 | + UnityWebappsApplicationStatus status = unity_webapps_application_repository_get_resolved_application_status( |
449 | + d->getRepository(), |
450 | + packageName); |
451 | + |
452 | + if (status == UNITY_WEBAPPS_APPLICATION_STATUS_UNRESOLVED) { |
453 | + reply.insert("available", false); |
454 | + reply.insert("installed", false); |
455 | + g_list_free_full(apps, g_free); |
456 | + return reply; |
457 | + } |
458 | + |
459 | + const gchar *appDomain = unity_webapps_application_repository_get_resolved_application_domain( |
460 | + d->getRepository(), |
461 | + packageName); |
462 | + const gchar *appName = unity_webapps_application_repository_get_resolved_application_name( |
463 | + d->getRepository(), |
464 | + packageName); |
465 | + |
466 | + switch (status) { |
467 | + case UNITY_WEBAPPS_APPLICATION_STATUS_AVAILABLE: |
468 | + if (unity_webapps_permissions_get_domain_dontask(appDomain)) { |
469 | + reply.insert("available", true); |
470 | + reply.insert("installed", false); |
471 | + g_list_free_full(apps, g_free); |
472 | + return reply; |
473 | + } |
474 | + unity_webapps_permissions_allow_domain(appDomain); |
475 | + unity_webapps_application_repository_install_application( |
476 | + d->getRepository(), |
477 | + packageName, |
478 | + WebappsHandlerPrivate::installationCallback, |
479 | + 0); |
480 | + break; |
481 | + |
482 | + case UNITY_WEBAPPS_APPLICATION_STATUS_INSTALLED: |
483 | + if (unity_webapps_permissions_get_domain_dontask(appDomain) || |
484 | + unity_webapps_permissions_get_domain_allowed(appDomain)) { |
485 | + reply.insert("available", true); |
486 | + reply.insert("installed", false); |
487 | + g_list_free_full(apps, g_free); |
488 | + return reply; |
489 | + } |
490 | + unity_webapps_application_repository_add_desktop_to_launcher(appName); |
491 | + unity_webapps_permissions_allow_domain(appDomain); |
492 | + break; |
493 | + case UNITY_WEBAPPS_APPLICATION_STATUS_UNRESOLVED: |
494 | + // handled above |
495 | + break; |
496 | + } |
497 | + |
498 | + reply.insert("installed", true); |
499 | + |
500 | + g_list_free_full(apps, g_free); |
501 | + |
502 | return reply; |
503 | } |
504 | + |
505 | |
506 | === modified file 'tests/unit/messaging-host/messaging-host.pro' |
507 | --- tests/unit/messaging-host/messaging-host.pro 2014-05-21 08:18:12 +0000 |
508 | +++ tests/unit/messaging-host/messaging-host.pro 2014-06-04 01:24:00 +0000 |
509 | @@ -3,7 +3,8 @@ |
510 | tst_connection \ |
511 | tst_connection_host \ |
512 | tst_inactivity_timer.pro \ |
513 | - tst_service.pro |
514 | + tst_service.pro \ |
515 | + tst_webapps-handler.pro \ |
516 | |
517 | tst_connection.file = tst_connection.pro |
518 | tst_connection_host.file = tst_connection_host.pro |
519 | |
520 | === added file 'tests/unit/messaging-host/tst_webapps-handler.cpp' |
521 | --- tests/unit/messaging-host/tst_webapps-handler.cpp 1970-01-01 00:00:00 +0000 |
522 | +++ tests/unit/messaging-host/tst_webapps-handler.cpp 2014-06-04 01:24:00 +0000 |
523 | @@ -0,0 +1,324 @@ |
524 | +/* |
525 | + * Copyright (C) 2014 Canonical Ltd. |
526 | + * |
527 | + * This file is part of unity-chromium-extension |
528 | + * |
529 | + * This program is free software: you can redistribute it and/or modify it |
530 | + * under the terms of the GNU General Public License version 3, as published |
531 | + * by the Free Software Foundation. |
532 | + * |
533 | + * This program is distributed in the hope that it will be useful, but |
534 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
535 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
536 | + * PURPOSE. See the GNU General Public License for more details. |
537 | + * |
538 | + * You should have received a copy of the GNU General Public License along |
539 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
540 | + */ |
541 | + |
542 | +extern "C" { |
543 | +#include <unity-webapps-permissions.h> |
544 | +#include <unity-webapps-application-repository.h> |
545 | +} |
546 | + |
547 | +#include "webapps-handler.h" |
548 | + |
549 | +#include <QDebug> |
550 | +#include <QSignalSpy> |
551 | +#include <QTest> |
552 | + |
553 | + |
554 | +// {{{ mock implementations |
555 | +struct AppInfo { |
556 | + bool install; |
557 | + bool allowed; |
558 | + bool dontask; |
559 | + UnityWebappsApplicationStatus status; |
560 | + QString name; |
561 | + QString domain; |
562 | +}; |
563 | + |
564 | +QMap<QString, AppInfo> _mock_app_info; |
565 | + |
566 | +UnityWebappsApplicationRepository *unity_webapps_application_repository_new_default() |
567 | +{ |
568 | + return (UnityWebappsApplicationRepository*)g_object_new(G_TYPE_OBJECT, 0); |
569 | +} |
570 | + |
571 | +gboolean unity_webapps_application_repository_prepare(UnityWebappsApplicationRepository *repository) |
572 | +{ |
573 | + Q_UNUSED(repository); |
574 | + |
575 | + return true; |
576 | +} |
577 | + |
578 | +GList * unity_webapps_application_repository_resolve_url(UnityWebappsApplicationRepository *repository, const gchar *url) |
579 | +{ |
580 | + Q_UNUSED(repository); |
581 | + |
582 | + if (!_mock_app_info.contains(QString::fromUtf8(url))) { |
583 | + return 0; |
584 | + } |
585 | + |
586 | + return g_list_append((GList*)0, (gpointer)g_strdup(url)); |
587 | +} |
588 | + |
589 | +UnityWebappsApplicationStatus |
590 | +unity_webapps_application_repository_get_resolved_application_status( |
591 | + UnityWebappsApplicationRepository *repository, |
592 | + const gchar *application |
593 | +) |
594 | +{ |
595 | + Q_UNUSED(repository); |
596 | + |
597 | + if (!_mock_app_info.contains(QString::fromUtf8(application))) { |
598 | + return UNITY_WEBAPPS_APPLICATION_STATUS_UNRESOLVED; |
599 | + } |
600 | + |
601 | + return _mock_app_info.value(QString::fromUtf8(application)).status; |
602 | +} |
603 | + |
604 | +const gchar * |
605 | +unity_webapps_application_repository_get_resolved_application_name(UnityWebappsApplicationRepository *repository, |
606 | + const gchar *application) |
607 | +{ |
608 | + Q_UNUSED(repository); |
609 | + |
610 | + if (!_mock_app_info.contains(QString::fromUtf8(application))) { |
611 | + return 0; |
612 | + } |
613 | + |
614 | + return g_strdup(_mock_app_info.value(QString::fromUtf8(application)).name.toLocal8Bit().constData()); |
615 | +} |
616 | + |
617 | +const gchar * |
618 | +unity_webapps_application_repository_get_resolved_application_domain(UnityWebappsApplicationRepository *repository, |
619 | + const gchar *application) |
620 | +{ |
621 | + Q_UNUSED(repository); |
622 | + |
623 | + if (!_mock_app_info.contains(QString::fromUtf8(application))) { |
624 | + return 0; |
625 | + } |
626 | + |
627 | + return g_strdup(_mock_app_info.value(QString::fromUtf8(application)).domain.toLocal8Bit().constData()); |
628 | +} |
629 | + |
630 | + |
631 | +gboolean unity_webapps_permissions_get_domain_allowed(const gchar *domain) |
632 | +{ |
633 | + Q_FOREACH(const QString &key, _mock_app_info.keys()) { |
634 | + AppInfo appInfo = _mock_app_info.value(key); |
635 | + if (appInfo.domain == QLatin1String(domain)) { |
636 | + return appInfo.allowed; |
637 | + } |
638 | + } |
639 | + |
640 | + return false; |
641 | +} |
642 | + |
643 | +gboolean unity_webapps_permissions_get_domain_dontask(const gchar *domain) |
644 | +{ |
645 | + Q_FOREACH(const QString &key, _mock_app_info.keys()) { |
646 | + AppInfo appInfo = _mock_app_info.value(key); |
647 | + if (appInfo.domain == QLatin1String(domain)) { |
648 | + return appInfo.dontask; |
649 | + } |
650 | + } |
651 | + |
652 | + return false; |
653 | +} |
654 | + |
655 | +void unity_webapps_permissions_dontask_domain(const gchar *domain) |
656 | +{ |
657 | + Q_UNUSED(domain); |
658 | +} |
659 | + |
660 | +void |
661 | +unity_webapps_application_repository_install_application(UnityWebappsApplicationRepository *repository, const gchar *name, |
662 | + UnityWebappsApplicationRepositoryInstallCallback callback, gpointer user_data) |
663 | +{ |
664 | + Q_UNUSED(repository); |
665 | + Q_UNUSED(name); |
666 | + Q_UNUSED(callback); |
667 | + Q_UNUSED(user_data); |
668 | +} |
669 | + |
670 | +// }}} |
671 | + |
672 | + |
673 | +class WebappsHandlerTest : public QObject |
674 | +{ |
675 | + Q_OBJECT |
676 | + |
677 | +public: |
678 | + WebappsHandlerTest(); |
679 | + |
680 | +private Q_SLOTS: |
681 | + void initTestCase(); |
682 | + void cleanupTestCase(); |
683 | + void testUrlLoadedMalformedRequest(); |
684 | + void testUrlLoaded_data(); |
685 | + void testUrlLoaded(); |
686 | + void testDontAskMalformedRequest(); |
687 | + void testDontAsk_data(); |
688 | + void testDontAsk(); |
689 | + void testInstallMalformedRequest(); |
690 | + void testInstall_data(); |
691 | + void testInstall(); |
692 | +}; |
693 | + |
694 | +WebappsHandlerTest::WebappsHandlerTest(): |
695 | + QObject(0) |
696 | +{ |
697 | +} |
698 | + |
699 | + |
700 | +void WebappsHandlerTest::initTestCase() |
701 | +{ |
702 | + _mock_app_info.insert("https://mail.google.com/", { true, false, false, UNITY_WEBAPPS_APPLICATION_STATUS_AVAILABLE, "Gmail", "mail.google.com" }); |
703 | + _mock_app_info.insert("http://www.tumblr.com/", { false, true, true, UNITY_WEBAPPS_APPLICATION_STATUS_AVAILABLE, "Tumblr", "www.tumblr.com" }); |
704 | +} |
705 | + |
706 | +void WebappsHandlerTest::cleanupTestCase() |
707 | +{ |
708 | +} |
709 | + |
710 | +void WebappsHandlerTest::testUrlLoadedMalformedRequest() |
711 | +{ |
712 | + UnityWebapps::WebappsHandler handler; |
713 | + |
714 | + QVariantMap message; |
715 | + message.insert("method", QString("url_loaded")); |
716 | + |
717 | + QVariantMap reply = handler.url_loaded(message); |
718 | + |
719 | + QVERIFY(!reply.empty()); |
720 | + QCOMPARE(reply.value("error").toString(), QStringLiteral("malformed request")); |
721 | +} |
722 | + |
723 | +void WebappsHandlerTest::testUrlLoaded_data() |
724 | +{ |
725 | + QTest::addColumn<QString>("url"); |
726 | + QTest::addColumn<bool>("available"); |
727 | + QTest::addColumn<QString>("appName"); |
728 | + QTest::addColumn<QString>("appDomain"); |
729 | + |
730 | + QTest::newRow("available") << "https://mail.google.com/" << true << "Gmail" << "mail.google.com"; |
731 | + QTest::newRow("not_available") << "http://www.example.com/" << false << "None" << "None"; |
732 | +} |
733 | + |
734 | +void WebappsHandlerTest::testUrlLoaded() |
735 | +{ |
736 | + QFETCH(QString, url); |
737 | + QFETCH(bool, available); |
738 | + QFETCH(QString, appName); |
739 | + QFETCH(QString, appDomain); |
740 | + |
741 | + QVariantMap message; |
742 | + message.insert("method", QString("url_loaded")); |
743 | + message.insert("url", url); |
744 | + |
745 | + UnityWebapps::WebappsHandler handler; |
746 | + QVariantMap reply = handler.url_loaded(message); |
747 | + |
748 | + QVERIFY(!reply.empty()); |
749 | + QCOMPARE(reply.value("available").toBool(), available); |
750 | + if (available) { |
751 | + QCOMPARE(appName, reply.value("appName").toString()); |
752 | + QCOMPARE(appDomain, reply.value("appDomain").toString()); |
753 | + } |
754 | +} |
755 | + |
756 | +void WebappsHandlerTest::testDontAskMalformedRequest() |
757 | +{ |
758 | + UnityWebapps::WebappsHandler handler; |
759 | + |
760 | + QVariantMap message; |
761 | + message.insert("method", QString("dont_ask")); |
762 | + |
763 | + QVariantMap reply = handler.url_loaded(message); |
764 | + |
765 | + QVERIFY(!reply.empty()); |
766 | + QCOMPARE(reply.value("error").toString(), QStringLiteral("malformed request")); |
767 | +} |
768 | + |
769 | +void WebappsHandlerTest::testDontAsk_data() |
770 | +{ |
771 | + QTest::addColumn<QString>("url"); |
772 | + QTest::addColumn<bool>("available"); |
773 | + |
774 | + QTest::newRow("ask") << "https://mail.google.com/" << true; |
775 | + QTest::newRow("dont_ask") << "http://www.tumblr.com/" << true; |
776 | + QTest::newRow("no app") << "http://www.example.com/" << false; |
777 | +} |
778 | + |
779 | +void WebappsHandlerTest::testDontAsk() |
780 | +{ |
781 | + QFETCH(QString, url); |
782 | + QFETCH(bool, available); |
783 | + |
784 | + UnityWebapps::WebappsHandler handler; |
785 | + |
786 | + QVariantMap message; |
787 | + message.insert("method", QString("dont_ask")); |
788 | + message.insert("url", url); |
789 | + |
790 | + QVariantMap reply = handler.dont_ask(message); |
791 | + |
792 | + QVERIFY(!reply.empty()); |
793 | + if (available) { |
794 | + QCOMPARE(reply.value("dont_ask").toBool(), true); |
795 | + } else { |
796 | + QCOMPARE(reply.value("dont_ask").toBool(), false); |
797 | + QCOMPARE(reply.value("available").toBool(), false); |
798 | + } |
799 | +} |
800 | + |
801 | +void WebappsHandlerTest::testInstallMalformedRequest() |
802 | +{ |
803 | + UnityWebapps::WebappsHandler handler; |
804 | + |
805 | + QVariantMap message; |
806 | + message.insert("method", QString("install")); |
807 | + |
808 | + QVariantMap reply = handler.url_loaded(message); |
809 | + |
810 | + QVERIFY(!reply.empty()); |
811 | + QCOMPARE(reply.value("error").toString(), QStringLiteral("malformed request")); |
812 | +} |
813 | + |
814 | +void WebappsHandlerTest::testInstall_data() |
815 | +{ |
816 | + QTest::addColumn<QString>("url"); |
817 | + QTest::addColumn<bool>("available"); |
818 | + QTest::addColumn<bool>("installed"); |
819 | + |
820 | + QTest::newRow("installs") << "https://mail.google.com/" << true << true; |
821 | + QTest::newRow("wont install") << "http://www.tumblr.com/" << true << false; |
822 | + QTest::newRow("no app") << "http://www.example.com/" << false << false; |
823 | +} |
824 | + |
825 | +void WebappsHandlerTest::testInstall() |
826 | +{ |
827 | + QFETCH(QString, url); |
828 | + QFETCH(bool, available); |
829 | + QFETCH(bool, installed); |
830 | + |
831 | + QVariantMap message; |
832 | + message.insert("method", QString("install")); |
833 | + message.insert("url", url); |
834 | + |
835 | + UnityWebapps::WebappsHandler handler; |
836 | + QVariantMap reply = handler.install(message); |
837 | + |
838 | + QVERIFY(!reply.empty()); |
839 | + QCOMPARE(reply.value("installed").toBool(), installed); |
840 | + if (!available) { |
841 | + QCOMPARE(reply.value("available").toBool(), false); |
842 | + } |
843 | +} |
844 | + |
845 | +QTEST_MAIN(WebappsHandlerTest); |
846 | + |
847 | +#include "tst_webapps-handler.moc" |
848 | |
849 | === added file 'tests/unit/messaging-host/tst_webapps-handler.pro' |
850 | --- tests/unit/messaging-host/tst_webapps-handler.pro 1970-01-01 00:00:00 +0000 |
851 | +++ tests/unit/messaging-host/tst_webapps-handler.pro 2014-06-04 01:24:00 +0000 |
852 | @@ -0,0 +1,30 @@ |
853 | +include(messaging-host.pri) |
854 | + |
855 | +TARGET = tst_webapps-handler |
856 | + |
857 | +QMAKE_CXXFLAGS += -std=c++11 |
858 | + |
859 | +CONFIG += \ |
860 | + link_pkgconfig \ |
861 | + qt |
862 | + |
863 | +QT += \ |
864 | + core \ |
865 | + testlib |
866 | + |
867 | +PKGCONFIG += \ |
868 | + glib-2.0 \ |
869 | + gobject-2.0 \ |
870 | + libunity_webapps-0.2 \ |
871 | + libunity-webapps-repository \ |
872 | + |
873 | +SOURCES += \ |
874 | + $${SRC_DIR}/webapps-handler.cpp \ |
875 | + tst_webapps-handler.cpp |
876 | + |
877 | +HEADERS += \ |
878 | + $${SRC_DIR}/webapps-handler.h |
879 | + |
880 | +check.commands = "xvfb-run -s '-screen 0 640x480x24' -a ./$${TARGET}" |
881 | +check.depends = $${TARGET} |
882 | +QMAKE_EXTRA_TARGETS += check |
I'll test it soon, meanwhile I've just added some comments about the code.