Merge lp:~mandel/ubuntu-download-manager/mms-download-start into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 225
Merged at revision: 222
Proposed branch: lp:~mandel/ubuntu-download-manager/mms-download-start
Merge into: lp:ubuntu-download-manager
Diff against target: 1501 lines (+1039/-18)
36 files modified
docs/com.canonical.applications.download_manager.xml (+9/-0)
ubuntu-download-manager-priv/downloads/download.cpp (+5/-0)
ubuntu-download-manager-priv/downloads/download.h (+16/-1)
ubuntu-download-manager-priv/downloads/download_manager_adaptor.cpp (+8/-0)
ubuntu-download-manager-priv/downloads/download_manager_adaptor.h (+11/-2)
ubuntu-download-manager-priv/downloads/factory.cpp (+26/-0)
ubuntu-download-manager-priv/downloads/factory.h (+7/-0)
ubuntu-download-manager-priv/downloads/file_download.cpp (+3/-3)
ubuntu-download-manager-priv/downloads/file_download.h (+3/-1)
ubuntu-download-manager-priv/downloads/manager.cpp (+15/-0)
ubuntu-download-manager-priv/downloads/manager.h (+5/-0)
ubuntu-download-manager-priv/downloads/mms_file_download.cpp (+51/-0)
ubuntu-download-manager-priv/downloads/mms_file_download.h (+54/-0)
ubuntu-download-manager-priv/downloads/queue.cpp (+28/-3)
ubuntu-download-manager-priv/downloads/queue.h (+2/-1)
ubuntu-download-manager-priv/system/apn_proxy.cpp (+41/-0)
ubuntu-download-manager-priv/system/apn_proxy.h (+46/-0)
ubuntu-download-manager-priv/system/apn_request_factory.cpp (+39/-0)
ubuntu-download-manager-priv/system/apn_request_factory.h (+47/-0)
ubuntu-download-manager-priv/system/request_factory.h (+3/-1)
ubuntu-download-manager-priv/ubuntu-download-manager-priv.pro (+8/-2)
ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro (+4/-2)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.cpp (+50/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.h (+43/-0)
ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h (+3/-0)
ubuntu-download-manager-tests/downloads/test_base_download.cpp (+130/-0)
ubuntu-download-manager-tests/downloads/test_base_download.h (+58/-0)
ubuntu-download-manager-tests/downloads/test_download_factory.cpp (+20/-0)
ubuntu-download-manager-tests/downloads/test_download_factory.h (+1/-0)
ubuntu-download-manager-tests/downloads/test_download_queue.cpp (+53/-0)
ubuntu-download-manager-tests/downloads/test_download_queue.h (+6/-0)
ubuntu-download-manager-tests/downloads/test_mms_download.cpp (+68/-0)
ubuntu-download-manager-tests/downloads/test_mms_download.h (+70/-0)
ubuntu-download-manager-tests/system/test_apn_request_factory.cpp (+57/-0)
ubuntu-download-manager-tests/system/test_apn_request_factory.h (+41/-0)
ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro (+8/-2)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/mms-download-start
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+203722@code.launchpad.net

Commit message

Provide a new method that allows to create mms downloads that are not queued and take the APN proxy details to be used for the get request.

Description of the change

Provide a new method that allows to create mms downloads that are not queued and take the APN proxy details to be used for the get request.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/com.canonical.applications.download_manager.xml'
2--- docs/com.canonical.applications.download_manager.xml 2013-12-03 13:03:53 +0000
3+++ docs/com.canonical.applications.download_manager.xml 2014-01-29 12:16:44 +0000
4@@ -6,6 +6,15 @@
5 <arg name="downloadPath" type="o" direction="out" />
6 </method>
7
8+ <method name="createMmsDownload">
9+ <arg name="url" type="s" direction="in" />
10+ <arg name="hostname" type="s" direction="in" />
11+ <arg name="port" type="i" direction="in" />
12+ <arg name="username" type="s" direction="in" />
13+ <arg name="password" type="s" direction="in" />
14+ <arg name="downloadPath" type="o" direction="out" />
15+ </method>
16+
17 <method name="createDownloadGroup">
18 <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="StructList"/>
19 <annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantMap"/>
20
21=== modified file 'ubuntu-download-manager-priv/downloads/download.cpp'
22--- ubuntu-download-manager-priv/downloads/download.cpp 2014-01-28 16:03:24 +0000
23+++ ubuntu-download-manager-priv/downloads/download.cpp 2014-01-29 12:16:44 +0000
24@@ -96,6 +96,11 @@
25 }
26
27 void
28+Download::setAddToQueue(bool addToQueue) {
29+ _addToQueue = addToQueue;
30+}
31+
32+void
33 Download::setLastError(const QString& lastError) {
34 _lastError = lastError;
35 }
36
37=== modified file 'ubuntu-download-manager-priv/downloads/download.h'
38--- ubuntu-download-manager-priv/downloads/download.h 2014-01-10 16:38:56 +0000
39+++ ubuntu-download-manager-priv/downloads/download.h 2014-01-29 12:16:44 +0000
40@@ -97,6 +97,11 @@
41 virtual bool isValid() const {
42 return _isValid;
43 }
44+
45+ bool addToQueue() const {
46+ return _addToQueue;
47+ }
48+
49 virtual QString lastError() const {
50 return _lastError;
51 }
52@@ -125,18 +130,26 @@
53
54 inline void cancel() {
55 setState(Download::CANCEL);
56+ if(!_addToQueue)
57+ cancelDownload();
58 }
59
60 inline void pause() {
61 setState(Download::PAUSE);
62+ if(!_addToQueue)
63+ pauseDownload();
64 }
65
66 inline void resume() {
67 setState(Download::RESUME);
68+ if(!_addToQueue)
69+ resumeDownload();
70 }
71
72 inline void start() {
73 setState(Download::START);
74+ if(!_addToQueue)
75+ startDownload();
76 }
77
78 // slots to be implemented by the children
79@@ -158,11 +171,13 @@
80
81 protected:
82 void setIsValid(bool isValid);
83+ void setAddToQueue(bool addToQueue);
84 void setLastError(const QString& lastError);
85 virtual void emitError(const QString& error);
86
87 private:
88 bool _isValid = true;
89+ bool _addToQueue = true;
90 QString _lastError = "";
91 QString _id;
92 qulonglong _throttle;
93@@ -174,7 +189,7 @@
94 QVariantMap _metadata;
95 QMap<QString, QString> _headers;
96 SystemNetworkInfo* _networkInfo;
97- QObject* _adaptor = NULL;
98+ QObject* _adaptor = nullptr;
99 };
100
101 } // Daemon
102
103=== modified file 'ubuntu-download-manager-priv/downloads/download_manager_adaptor.cpp'
104--- ubuntu-download-manager-priv/downloads/download_manager_adaptor.cpp 2014-01-09 15:21:14 +0000
105+++ ubuntu-download-manager-priv/downloads/download_manager_adaptor.cpp 2014-01-29 12:16:44 +0000
106@@ -61,6 +61,14 @@
107 return download;
108 }
109
110+QDBusObjectPath DownloadManagerAdaptor::createMmsDownload(const QString &url, const QString &hostname, int port, const QString &username, const QString &password)
111+{
112+ // handle method call com.canonical.applications.DownloadManager.createMmsDownload
113+ QDBusObjectPath downloadPath;
114+ QMetaObject::invokeMethod(parent(), "createMmsDownload", Q_RETURN_ARG(QDBusObjectPath, downloadPath), Q_ARG(QString, url), Q_ARG(QString, hostname), Q_ARG(int, port), Q_ARG(QString, username), Q_ARG(QString, password));
115+ return downloadPath;
116+}
117+
118 qulonglong DownloadManagerAdaptor::defaultThrottle()
119 {
120 // handle method call com.canonical.applications.DownloadManager.defaultThrottle
121
122=== modified file 'ubuntu-download-manager-priv/downloads/download_manager_adaptor.h'
123--- ubuntu-download-manager-priv/downloads/download_manager_adaptor.h 2013-12-11 13:55:36 +0000
124+++ ubuntu-download-manager-priv/downloads/download_manager_adaptor.h 2014-01-29 12:16:44 +0000
125@@ -9,8 +9,8 @@
126 * before re-generating it.
127 */
128
129-#ifndef DOWNLOAD_MANAGER_ADAPTOR_H_1379689315
130-#define DOWNLOAD_MANAGER_ADAPTOR_H_1379689315
131+#ifndef DOWNLOAD_MANAGER_ADAPTOR_H_1390996214
132+#define DOWNLOAD_MANAGER_ADAPTOR_H_1390996214
133
134 #include <QtCore/QObject>
135 #include <QtDBus/QtDBus>
136@@ -45,6 +45,14 @@
137 " <arg direction=\"in\" type=\"(sssa{sv}a{ss})\" name=\"download\"/>\n"
138 " <arg direction=\"out\" type=\"o\" name=\"downloadPath\"/>\n"
139 " </method>\n"
140+" <method name=\"createMmsDownload\">\n"
141+" <arg direction=\"in\" type=\"s\" name=\"url\"/>\n"
142+" <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n"
143+" <arg direction=\"in\" type=\"i\" name=\"port\"/>\n"
144+" <arg direction=\"in\" type=\"s\" name=\"username\"/>\n"
145+" <arg direction=\"in\" type=\"s\" name=\"password\"/>\n"
146+" <arg direction=\"out\" type=\"o\" name=\"downloadPath\"/>\n"
147+" </method>\n"
148 " <method name=\"createDownloadGroup\">\n"
149 " <annotation value=\"StructList\" name=\"org.qtproject.QtDBus.QtTypeName.In0\"/>\n"
150 " <annotation value=\"QVariantMap\" name=\"org.qtproject.QtDBus.QtTypeName.In3\"/>\n"
151@@ -91,6 +99,7 @@
152 void allowGSMDownload(bool allowed);
153 QDBusObjectPath createDownload(DownloadStruct download);
154 QDBusObjectPath createDownloadGroup(StructList downloads, const QString &algorithm, bool allowed3G, const QVariantMap &metadata, StringMap headers);
155+ QDBusObjectPath createMmsDownload(const QString &url, const QString &hostname, int port, const QString &username, const QString &password);
156 qulonglong defaultThrottle();
157 void exit();
158 QList<QDBusObjectPath> getAllDownloads();
159
160=== modified file 'ubuntu-download-manager-priv/downloads/factory.cpp'
161--- ubuntu-download-manager-priv/downloads/factory.cpp 2014-01-28 16:03:24 +0000
162+++ ubuntu-download-manager-priv/downloads/factory.cpp 2014-01-29 12:16:44 +0000
163@@ -16,11 +16,13 @@
164 * Boston, MA 02110-1301, USA.
165 */
166
167+#include <QNetworkProxy>
168 #include <QPair>
169 #include "downloads/download_adaptor.h"
170 #include "downloads/group_download.h"
171 #include "downloads/group_download_adaptor.h"
172 #include "downloads/file_download.h"
173+#include "downloads/mms_file_download.h"
174 #include "downloads/factory.h"
175 #include "system/logger.h"
176
177@@ -133,6 +135,30 @@
178 }
179
180 Download*
181+Factory::createMmsDownload(const QString& dbusOwner,
182+ const QUrl& url,
183+ const QString& hostname,
184+ int port,
185+ const QString& username,
186+ const QString& password) {
187+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname,
188+ port, username, password);
189+ QString id;
190+ QString dbusPath;
191+ QString rootPath;
192+ bool isConfined = false;
193+ QVariantMap metadata;
194+ QMap<QString, QString> headers;
195+ getDownloadPath(dbusOwner, metadata, id, dbusPath, rootPath,
196+ isConfined);
197+ Download* down = new MmsFileDownload(id, dbusPath, isConfined,
198+ rootPath, url, metadata, headers, proxy);
199+ DownloadAdaptor* adaptor = new DownloadAdaptor(down);
200+ down->setAdaptor(adaptor);
201+ return down;
202+}
203+
204+Download*
205 Factory::createDownloadForGroup(bool isConfined,
206 const QString& rootPath,
207 const QUrl& url,
208
209=== modified file 'ubuntu-download-manager-priv/downloads/factory.h'
210--- ubuntu-download-manager-priv/downloads/factory.h 2014-01-10 16:38:56 +0000
211+++ ubuntu-download-manager-priv/downloads/factory.h 2014-01-29 12:16:44 +0000
212@@ -62,6 +62,13 @@
213 const QVariantMap& metadata,
214 StringMap headers);
215
216+ virtual Download* createMmsDownload(const QString& dbusOwner,
217+ const QUrl& url,
218+ const QString& hostname,
219+ int port,
220+ const QString& username,
221+ const QString& password);
222+
223 // create downloads from a group download
224
225 virtual Download* createDownloadForGroup(bool isConfined,
226
227=== modified file 'ubuntu-download-manager-priv/downloads/file_download.cpp'
228--- ubuntu-download-manager-priv/downloads/file_download.cpp 2014-01-29 10:02:08 +0000
229+++ ubuntu-download-manager-priv/downloads/file_download.cpp 2014-01-29 12:16:44 +0000
230@@ -526,10 +526,10 @@
231 QFile::FileError error = QFile::NoError;
232 if (_currentData != nullptr) {
233 success = _currentData->remove();
234-
235+
236 if (!success)
237 error = _currentData->error();
238-
239+
240 _currentData->deleteLater();
241 _currentData = nullptr;
242 } else {
243@@ -538,7 +538,7 @@
244 if (!success)
245 error = tempFile->error();
246 }
247-
248+
249 if (!success)
250 qWarning() << "Error " << error <<
251 "removing file with path" << _filePath;
252
253=== modified file 'ubuntu-download-manager-priv/downloads/file_download.h'
254--- ubuntu-download-manager-priv/downloads/file_download.h 2014-01-22 16:53:05 +0000
255+++ ubuntu-download-manager-priv/downloads/file_download.h 2014-01-29 12:16:44 +0000
256@@ -94,6 +94,9 @@
257 protected:
258 void emitError(const QString& error) override;
259
260+ protected:
261+ RequestFactory* _requestFactory;
262+
263 private:
264 QNetworkRequest buildRequest();
265 void cleanUpCurrentData();
266@@ -122,7 +125,6 @@
267 QCryptographicHash::Algorithm _algo;
268 NetworkReply* _reply = NULL;
269 File* _currentData = NULL;
270- RequestFactory* _requestFactory;
271 };
272
273 } // Daemon
274
275=== modified file 'ubuntu-download-manager-priv/downloads/manager.cpp'
276--- ubuntu-download-manager-priv/downloads/manager.cpp 2014-01-28 16:03:24 +0000
277+++ ubuntu-download-manager-priv/downloads/manager.cpp 2014-01-29 12:16:44 +0000
278@@ -175,6 +175,21 @@
279 }
280
281 QDBusObjectPath
282+Manager::createMmsDownload(const QString& url,
283+ const QString& hostname,
284+ int port,
285+ const QString& username,
286+ const QString& password) {
287+ DownloadCreationFunc createDownloadFunc =
288+ [this, url, hostname, port, username, password](QString owner) {
289+ auto download = _downloadFactory->createMmsDownload(owner, url,
290+ hostname, port, username, password);
291+ return download;
292+ };
293+ return createDownload(createDownloadFunc);
294+}
295+
296+QDBusObjectPath
297 Manager::createDownloadGroup(StructList downloads,
298 const QString& algo,
299 bool allowed3G,
300
301=== modified file 'ubuntu-download-manager-priv/downloads/manager.h'
302--- ubuntu-download-manager-priv/downloads/manager.h 2014-01-10 16:40:27 +0000
303+++ ubuntu-download-manager-priv/downloads/manager.h 2014-01-29 12:16:44 +0000
304@@ -61,6 +61,11 @@
305
306 public slots: // NOLINT(whitespace/indent)
307 virtual QDBusObjectPath createDownload(DownloadStruct download);
308+ virtual QDBusObjectPath createMmsDownload(const QString& url,
309+ const QString& hostname,
310+ int port,
311+ const QString& username,
312+ const QString& password);
313
314 virtual QDBusObjectPath createDownloadGroup(StructList downloads,
315 const QString& algorithm,
316
317=== added file 'ubuntu-download-manager-priv/downloads/mms_file_download.cpp'
318--- ubuntu-download-manager-priv/downloads/mms_file_download.cpp 1970-01-01 00:00:00 +0000
319+++ ubuntu-download-manager-priv/downloads/mms_file_download.cpp 2014-01-29 12:16:44 +0000
320@@ -0,0 +1,51 @@
321+/*
322+ * Copyright 2014 Canonical Ltd.
323+ *
324+ * This library is free software; you can redistribute it and/or
325+ * modify it under the terms of version 3 of the GNU Lesser General Public
326+ * License as published by the Free Software Foundation.
327+ *
328+ * This program is distributed in the hope that it will be useful,
329+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
330+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
331+ * General Public License for more details.
332+ *
333+ * You should have received a copy of the GNU Lesser General Public
334+ * License along with this library; if not, write to the
335+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
336+ * Boston, MA 02110-1301, USA.
337+ */
338+
339+#include "system/apn_request_factory.h"
340+#include "mms_file_download.h"
341+
342+namespace Ubuntu {
343+
344+namespace DownloadManager {
345+
346+namespace Daemon {
347+
348+MmsFileDownload::MmsFileDownload(const QString& id,
349+ const QString& path,
350+ bool isConfined,
351+ const QString& rootPath,
352+ const QUrl& url,
353+ const QVariantMap& metadata,
354+ const QMap<QString, QString>& headers,
355+ const QNetworkProxy& proxy,
356+ QObject* parent)
357+ : FileDownload(id, path, isConfined, rootPath, url,
358+ metadata, headers, parent){
359+ _requestFactory = new ApnRequestFactory(proxy);
360+ setAddToQueue(false);
361+}
362+
363+MmsFileDownload::~MmsFileDownload() {
364+ delete _requestFactory;
365+}
366+
367+} // Daemon
368+
369+} // DownloadManager
370+
371+} // Ubuntu
372
373=== added file 'ubuntu-download-manager-priv/downloads/mms_file_download.h'
374--- ubuntu-download-manager-priv/downloads/mms_file_download.h 1970-01-01 00:00:00 +0000
375+++ ubuntu-download-manager-priv/downloads/mms_file_download.h 2014-01-29 12:16:44 +0000
376@@ -0,0 +1,54 @@
377+/*
378+ * Copyright 2014 Canonical Ltd.
379+ *
380+ * This library is free software; you can redistribute it and/or
381+ * modify it under the terms of version 3 of the GNU Lesser General Public
382+ * License as published by the Free Software Foundation.
383+ *
384+ * This program is distributed in the hope that it will be useful,
385+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
386+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
387+ * General Public License for more details.
388+ *
389+ * You should have received a copy of the GNU Lesser General Public
390+ * License along with this library; if not, write to the
391+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
392+ * Boston, MA 02110-1301, USA.
393+ */
394+
395+#ifndef MMS_FILE_DOWNLOAD_H
396+#define MMS_FILE_DOWNLOAD_H
397+
398+#include <QNetworkProxy>
399+#include <QObject>
400+#include "file_download.h"
401+
402+namespace Ubuntu {
403+
404+namespace DownloadManager {
405+
406+namespace Daemon {
407+
408+class MmsFileDownload : public FileDownload {
409+ Q_OBJECT
410+
411+ public:
412+ MmsFileDownload(const QString& id,
413+ const QString& path,
414+ bool isConfined,
415+ const QString& rootPath,
416+ const QUrl& url,
417+ const QVariantMap& metadata,
418+ const QMap<QString, QString>& headers,
419+ const QNetworkProxy& proxy,
420+ QObject* parent = 0);
421+ ~MmsFileDownload();
422+};
423+
424+} // Daemon
425+
426+} // DownloadManager
427+
428+} // Ubunut
429+
430+#endif // MMS_FILE_DOWNLOAD_H
431
432=== modified file 'ubuntu-download-manager-priv/downloads/queue.cpp'
433--- ubuntu-download-manager-priv/downloads/queue.cpp 2014-01-28 16:03:24 +0000
434+++ ubuntu-download-manager-priv/downloads/queue.cpp 2014-01-29 12:16:44 +0000
435@@ -44,8 +44,14 @@
436 _sortedPaths.append(path);
437 _downloads[path] = download;
438
439- connect(download, &Download::stateChanged,
440- this, &Queue::onDownloadStateChanged);
441+ if (download->addToQueue()) {
442+ connect(download, &Download::stateChanged,
443+ this, &Queue::onManagedDownloadStateChanged);
444+ } else {
445+ connect(download, &Download::stateChanged,
446+ this, &Queue::onUnmanagedDownloadStateChanged);
447+ }
448+
449 emit downloadAdded(path);
450 }
451
452@@ -86,7 +92,7 @@
453 }
454
455 void
456-Queue::onDownloadStateChanged() {
457+Queue::onManagedDownloadStateChanged() {
458 TRACE;
459 // get the appdownload that emited the signal and
460 // decide what to do with it
461@@ -129,6 +135,25 @@
462 }
463
464 void
465+Queue::onUnmanagedDownloadStateChanged() {
466+ TRACE;
467+ // grab the download and clean it when needed
468+ Download* down = qobject_cast<Download*>(sender());
469+ switch (down->state()) {
470+ case Download::CANCEL:
471+ case Download::ERROR:
472+ case Download::FINISH:
473+ // remove the registered object in dbus, remove the download
474+ // and the adapter from the list
475+ remove(down->path());
476+ break;
477+ default:
478+ // do nothing
479+ break;
480+ }
481+}
482+
483+void
484 Queue::onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode) {
485 TRACE << mode;
486 if (mode != QNetworkInfo::UnknownMode) {
487
488=== modified file 'ubuntu-download-manager-priv/downloads/queue.h'
489--- ubuntu-download-manager-priv/downloads/queue.h 2014-01-22 16:53:05 +0000
490+++ ubuntu-download-manager-priv/downloads/queue.h 2014-01-29 12:16:44 +0000
491@@ -54,7 +54,8 @@
492 void downloadRemoved(QString path);
493
494 private:
495- void onDownloadStateChanged();
496+ void onManagedDownloadStateChanged();
497+ void onUnmanagedDownloadStateChanged();
498 void onCurrentNetworkModeChanged(QNetworkInfo::NetworkMode mode);
499 void remove(const QString& path);
500 void updateCurrentDownload();
501
502=== added file 'ubuntu-download-manager-priv/system/apn_proxy.cpp'
503--- ubuntu-download-manager-priv/system/apn_proxy.cpp 1970-01-01 00:00:00 +0000
504+++ ubuntu-download-manager-priv/system/apn_proxy.cpp 2014-01-29 12:16:44 +0000
505@@ -0,0 +1,41 @@
506+/*
507+ * Copyright 2014 Canonical Ltd.
508+ *
509+ * This library is free software; you can redistribute it and/or
510+ * modify it under the terms of version 3 of the GNU Lesser General Public
511+ * License as published by the Free Software Foundation.
512+ *
513+ * This program is distributed in the hope that it will be useful,
514+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
515+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
516+ * General Public License for more details.
517+ *
518+ * You should have received a copy of the GNU Lesser General Public
519+ * License along with this library; if not, write to the
520+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
521+ * Boston, MA 02110-1301, USA.
522+ */
523+
524+#include "apn_proxy.h"
525+
526+namespace Ubuntu {
527+
528+namespace DownloadManager {
529+
530+namespace System {
531+
532+ApnProxy::ApnProxy(QObject *parent)
533+ : QObject(parent) {
534+}
535+
536+QNetworkProxy
537+ApnProxy::getProxy() {
538+ QNetworkProxy proxy;
539+ return proxy;
540+}
541+
542+}
543+
544+}
545+
546+}
547
548=== added file 'ubuntu-download-manager-priv/system/apn_proxy.h'
549--- ubuntu-download-manager-priv/system/apn_proxy.h 1970-01-01 00:00:00 +0000
550+++ ubuntu-download-manager-priv/system/apn_proxy.h 2014-01-29 12:16:44 +0000
551@@ -0,0 +1,46 @@
552+/*
553+ * Copyright 2014 Canonical Ltd.
554+ *
555+ * This library is free software; you can redistribute it and/or
556+ * modify it under the terms of version 3 of the GNU Lesser General Public
557+ * License as published by the Free Software Foundation.
558+ *
559+ * This program is distributed in the hope that it will be useful,
560+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
561+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
562+ * General Public License for more details.
563+ *
564+ * You should have received a copy of the GNU Lesser General Public
565+ * License along with this library; if not, write to the
566+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
567+ * Boston, MA 02110-1301, USA.
568+ */
569+
570+#ifndef DOWNLOADER_LIB_APN_PROXY_H
571+#define DOWNLOADER_LIB_APN_PROXY_H
572+
573+#include <QNetworkProxy>
574+#include <QObject>
575+
576+namespace Ubuntu {
577+
578+namespace DownloadManager {
579+
580+namespace System {
581+
582+class ApnProxy : public QObject {
583+ Q_OBJECT
584+
585+ public:
586+ explicit ApnProxy(QObject *parent = 0);
587+
588+ virtual QNetworkProxy getProxy();
589+
590+};
591+
592+} // System
593+
594+} // DownloadManager
595+
596+} // Ubuntu
597+#endif // APN_PROXY_H
598
599=== added file 'ubuntu-download-manager-priv/system/apn_request_factory.cpp'
600--- ubuntu-download-manager-priv/system/apn_request_factory.cpp 1970-01-01 00:00:00 +0000
601+++ ubuntu-download-manager-priv/system/apn_request_factory.cpp 2014-01-29 12:16:44 +0000
602@@ -0,0 +1,39 @@
603+/*
604+ * Copyright 2014 Canonical Ltd.
605+ *
606+ * This library is free software; you can redistribute it and/or
607+ * modify it under the terms of version 3 of the GNU Lesser General Public
608+ * License as published by the Free Software Foundation.
609+ *
610+ * This program is distributed in the hope that it will be useful,
611+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
612+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
613+ * General Public License for more details.
614+ *
615+ * You should have received a copy of the GNU Lesser General Public
616+ * License along with this library; if not, write to the
617+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
618+ * Boston, MA 02110-1301, USA.
619+ */
620+
621+#include "apn_proxy.h"
622+#include "apn_request_factory.h"
623+
624+namespace Ubuntu {
625+
626+namespace DownloadManager {
627+
628+namespace System {
629+
630+ApnRequestFactory::ApnRequestFactory(const QNetworkProxy& proxy,
631+ bool stoppable,
632+ QObject* parent)
633+ : RequestFactory(stoppable, parent) {
634+ _nam->setProxy(proxy);
635+}
636+
637+} // System
638+
639+} // DownloadManager
640+
641+} // Ubuntu
642
643=== added file 'ubuntu-download-manager-priv/system/apn_request_factory.h'
644--- ubuntu-download-manager-priv/system/apn_request_factory.h 1970-01-01 00:00:00 +0000
645+++ ubuntu-download-manager-priv/system/apn_request_factory.h 2014-01-29 12:16:44 +0000
646@@ -0,0 +1,47 @@
647+/*
648+ * Copyright 2014 Canonical Ltd.
649+ *
650+ * This library is free software; you can redistribute it and/or
651+ * modify it under the terms of version 3 of the GNU Lesser General Public
652+ * License as published by the Free Software Foundation.
653+ *
654+ * This program is distributed in the hope that it will be useful,
655+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
656+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
657+ * General Public License for more details.
658+ *
659+ * You should have received a copy of the GNU Lesser General Public
660+ * License along with this library; if not, write to the
661+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
662+ * Boston, MA 02110-1301, USA.
663+ */
664+
665+#ifndef DOWNLOADER_LIB_APN_REQUEST_FACTORY_H
666+#define DOWNLOADER_LIB_APN_REQUEST_FACTORY_H
667+
668+#include <QNetworkProxy>
669+#include <QObject>
670+#include "request_factory.h"
671+
672+namespace Ubuntu {
673+
674+namespace DownloadManager {
675+
676+namespace System {
677+
678+class ApnRequestFactory : public RequestFactory {
679+ Q_OBJECT
680+
681+ public:
682+ ApnRequestFactory(const QNetworkProxy& proxy,
683+ bool stoppable = false,
684+ QObject* parent=0);
685+};
686+
687+} // System
688+
689+} // DownloadManager
690+
691+} // Ubuntu
692+
693+#endif // APN_REQUEST_FACTORY_H
694
695=== modified file 'ubuntu-download-manager-priv/system/request_factory.h'
696--- ubuntu-download-manager-priv/system/request_factory.h 2013-11-27 16:00:50 +0000
697+++ ubuntu-download-manager-priv/system/request_factory.h 2014-01-29 12:16:44 +0000
698@@ -62,6 +62,9 @@
699 void onFinished();
700 void onSslErrors(const QList<QSslError>&);
701
702+ protected:
703+ QNetworkAccessManager* _nam;
704+
705 private:
706 // used for the singleton
707 static RequestFactory* _instance;
708@@ -72,7 +75,6 @@
709 bool _stoppable = false;
710 QList<NetworkReply*> _replies;
711 QList<QSslCertificate> _certs;
712- QNetworkAccessManager* _nam;
713 };
714
715 } // System
716
717=== modified file 'ubuntu-download-manager-priv/ubuntu-download-manager-priv.pro'
718--- ubuntu-download-manager-priv/ubuntu-download-manager-priv.pro 2014-01-24 11:54:24 +0000
719+++ ubuntu-download-manager-priv/ubuntu-download-manager-priv.pro 2014-01-29 12:16:44 +0000
720@@ -38,7 +38,10 @@
721 system/network_reply.cpp \
722 system/dbus_proxy.cpp \
723 downloads/state_machines/state.cpp \
724- downloads/state_machines/final_state.cpp
725+ downloads/state_machines/final_state.cpp \
726+ system/apn_request_factory.cpp \
727+ downloads/mms_file_download.cpp \
728+ system/apn_proxy.cpp
729
730 HEADERS +=\
731 app-downloader-lib_global.h \
732@@ -69,7 +72,10 @@
733 system/network_reply.h \
734 system/dbus_proxy.h \
735 downloads/state_machines/state.h \
736- downloads/state_machines/final_state.h
737+ downloads/state_machines/final_state.h \
738+ system/apn_request_factory.h \
739+ downloads/mms_file_download.h \
740+ system/apn_proxy.h
741
742 OTHER_FILES += \
743 generate_adaptors.sh \
744
745=== modified file 'ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro'
746--- ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro 2014-01-22 10:30:56 +0000
747+++ ubuntu-download-manager-test-lib/ubuntu-download-manager-test-lib.pro 2014-01-29 12:16:44 +0000
748@@ -32,7 +32,8 @@
749 ubuntu/download_manager/tests/client/testing_daemon.cpp \
750 ubuntu/download_manager/tests/client/testing_manager.cpp \
751 ubuntu/download_manager/tests/client/testing_manager_adaptor.cpp \
752- ubuntu/download_manager/tests/client/testing_interface.cpp
753+ ubuntu/download_manager/tests/client/testing_interface.cpp \
754+ ubuntu/download_manager/tests/server/apn_request_factory.cpp
755
756 HEADERS += ubuntu/download_manager/tests/base_testcase.h \
757 ubuntu/download_manager/tests/fake.h\
758@@ -58,7 +59,8 @@
759 ubuntu/download_manager/tests/client/testing_daemon.h \
760 ubuntu/download_manager/tests/client/testing_manager.h \
761 ubuntu/download_manager/tests/client/testing_manager_adaptor.h \
762- ubuntu/download_manager/tests/client/testing_interface.h
763+ ubuntu/download_manager/tests/client/testing_interface.h \
764+ ubuntu/download_manager/tests/server/apn_request_factory.h
765
766 LIBS += -L$$OUT_PWD/../ubuntu-download-manager-common/ -lubuntu-download-manager-common
767
768
769=== added file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.cpp'
770--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.cpp 1970-01-01 00:00:00 +0000
771+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.cpp 2014-01-29 12:16:44 +0000
772@@ -0,0 +1,50 @@
773+/*
774+ * Copyright 2014 Canonical Ltd.
775+ *
776+ * This library is free software; you can redistribute it and/or
777+ * modify it under the terms of version 3 of the GNU Lesser General Public
778+ * License as published by the Free Software Foundation.
779+ *
780+ * This program is distributed in the hope that it will be useful,
781+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
782+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
783+ * General Public License for more details.
784+ *
785+ * You should have received a copy of the GNU Lesser General Public
786+ * License along with this library; if not, write to the
787+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
788+ * Boston, MA 02110-1301, USA.
789+ */
790+
791+#include "apn_request_factory.h"
792+
793+FakeApnRequestFactory::FakeApnRequestFactory(const QNetworkProxy& proxy,
794+ bool stoppable,
795+ QObject* parent)
796+ : ApnRequestFactory(proxy, stoppable, parent) {
797+}
798+
799+QString
800+FakeApnRequestFactory::proxyHost() {
801+ return _nam->proxy().hostName();
802+}
803+
804+int
805+FakeApnRequestFactory::proxyPort() {
806+ return _nam->proxy().port();
807+}
808+
809+QString
810+FakeApnRequestFactory::proxyUsername() {
811+ return _nam->proxy().user();
812+}
813+
814+QString
815+FakeApnRequestFactory::proxyPassword() {
816+ return _nam->proxy().password();
817+}
818+
819+QNetworkProxy::ProxyType
820+FakeApnRequestFactory::proxyType() {
821+ return _nam->proxy().type();
822+}
823
824=== added file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.h'
825--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.h 1970-01-01 00:00:00 +0000
826+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/apn_request_factory.h 2014-01-29 12:16:44 +0000
827@@ -0,0 +1,43 @@
828+/*
829+ * Copyright 2014 Canonical Ltd.
830+ *
831+ * This library is free software; you can redistribute it and/or
832+ * modify it under the terms of version 3 of the GNU Lesser General Public
833+ * License as published by the Free Software Foundation.
834+ *
835+ * This program is distributed in the hope that it will be useful,
836+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
837+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
838+ * General Public License for more details.
839+ *
840+ * You should have received a copy of the GNU Lesser General Public
841+ * License along with this library; if not, write to the
842+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
843+ * Boston, MA 02110-1301, USA.
844+ */
845+
846+#ifndef FAKE_APN_REQUEST_FACTORY_H
847+#define FAKE_APN_REQUEST_FACTORY_H
848+
849+#include <QObject>
850+#include <system/apn_request_factory.h>
851+#include "ubuntu/download_manager/tests/fake.h"
852+
853+using namespace Ubuntu::DownloadManager::System;
854+
855+class FakeApnRequestFactory : public ApnRequestFactory {
856+ Q_OBJECT
857+
858+ public:
859+ FakeApnRequestFactory(const QNetworkProxy& proxy,
860+ bool stoppable = false,
861+ QObject* parent=0);
862+
863+ QString proxyHost();
864+ int proxyPort();
865+ QString proxyUsername();
866+ QString proxyPassword();
867+ QNetworkProxy::ProxyType proxyType();
868+};
869+
870+#endif // FAKE_APN_REQUEST_FACTORY_H
871
872=== modified file 'ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h'
873--- ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h 2014-01-22 16:53:05 +0000
874+++ ubuntu-download-manager-test-lib/ubuntu/download_manager/tests/server/download.h 2014-01-29 12:16:44 +0000
875@@ -18,6 +18,7 @@
876
877 #ifndef FAKE_DOWNLOAD_H
878 #define FAKE_DOWNLOAD_H
879+
880 #include <QSharedPointer>
881 #include <downloads/file_download.h>
882 #include <system/system_network_info.h>
883@@ -62,6 +63,8 @@
884 void emitFinished(const QString& path);
885 void emitError(const QString& error);
886
887+ using Download::setAddToQueue;
888+
889 private:
890 bool _canDownload;
891 };
892
893=== added file 'ubuntu-download-manager-tests/downloads/test_base_download.cpp'
894--- ubuntu-download-manager-tests/downloads/test_base_download.cpp 1970-01-01 00:00:00 +0000
895+++ ubuntu-download-manager-tests/downloads/test_base_download.cpp 2014-01-29 12:16:44 +0000
896@@ -0,0 +1,130 @@
897+/*
898+ * Copyright 2014 Canonical Ltd.
899+ *
900+ * This library is free software; you can redistribute it and/or
901+ * modify it under the terms of version 3 of the GNU Lesser General Public
902+ * License as published by the Free Software Foundation.
903+ *
904+ * This program is distributed in the hope that it will be useful,
905+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
906+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
907+ * General Public License for more details.
908+ *
909+ * You should have received a copy of the GNU Lesser General Public
910+ * License along with this library; if not, write to the
911+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
912+ * Boston, MA 02110-1301, USA.
913+ */
914+
915+#include "test_base_download.h"
916+
917+TestBaseDownload::TestBaseDownload(QObject *parent)
918+ : BaseTestCase("TestBaseDownload", parent){
919+}
920+
921+void
922+TestBaseDownload::init() {
923+ BaseTestCase::init();
924+
925+ _id = "download-id";
926+ _path = "path-to-be-used";
927+ _isConfined = false;
928+ _rootPath = "/root/path/to/use";
929+ _url = QUrl("http://test.com");
930+}
931+
932+void
933+TestBaseDownload::testStartQueued() {
934+ QScopedPointer<FakeDownload> down(
935+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
936+ _metadata, _headers));
937+ down->record();
938+ down->start();
939+
940+ QCOMPARE(0, down->calledMethods().count());
941+}
942+
943+void
944+TestBaseDownload::testStartNotQueued() {
945+ QScopedPointer<FakeDownload> down(
946+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
947+ _metadata, _headers));
948+ down->record();
949+ down->setAddToQueue(false);
950+ down->start();
951+
952+ QCOMPARE(1, down->calledMethods().count());
953+ QCOMPARE(QString("startDownload"), down->calledMethods()[0].methodName());
954+}
955+
956+void
957+TestBaseDownload::testPauseQueued() {
958+ QScopedPointer<FakeDownload> down(
959+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
960+ _metadata, _headers));
961+ down->record();
962+ down->pause();
963+
964+ QCOMPARE(0, down->calledMethods().count());
965+}
966+
967+void
968+TestBaseDownload::testPauseNotQueued() {
969+ QScopedPointer<FakeDownload> down(
970+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
971+ _metadata, _headers));
972+ down->record();
973+ down->setAddToQueue(false);
974+ down->pause();
975+
976+ QCOMPARE(1, down->calledMethods().count());
977+ QCOMPARE(QString("pauseDownload"), down->calledMethods()[0].methodName());
978+}
979+
980+void
981+TestBaseDownload::testResumeQueued() {
982+ QScopedPointer<FakeDownload> down(
983+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
984+ _metadata, _headers));
985+ down->record();
986+ down->resume();
987+
988+ QCOMPARE(0, down->calledMethods().count());
989+}
990+
991+void
992+TestBaseDownload::testResumeNotQueued() {
993+ QScopedPointer<FakeDownload> down(
994+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
995+ _metadata, _headers));
996+ down->record();
997+ down->setAddToQueue(false);
998+ down->resume();
999+
1000+ QCOMPARE(1, down->calledMethods().count());
1001+ QCOMPARE(QString("resumeDownload"), down->calledMethods()[0].methodName());
1002+}
1003+
1004+void
1005+TestBaseDownload::testCancelQueued() {
1006+ QScopedPointer<FakeDownload> down(
1007+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
1008+ _metadata, _headers));
1009+ down->record();
1010+ down->cancel();
1011+
1012+ QCOMPARE(0, down->calledMethods().count());
1013+}
1014+
1015+void
1016+TestBaseDownload::testCancelNotQueued() {
1017+ QScopedPointer<FakeDownload> down(
1018+ new FakeDownload(_id, _path, _isConfined, _rootPath, _url,
1019+ _metadata, _headers));
1020+ down->record();
1021+ down->setAddToQueue(false);
1022+ down->cancel();
1023+
1024+ QCOMPARE(1, down->calledMethods().count());
1025+ QCOMPARE(QString("cancelDownload"), down->calledMethods()[0].methodName());
1026+}
1027
1028=== added file 'ubuntu-download-manager-tests/downloads/test_base_download.h'
1029--- ubuntu-download-manager-tests/downloads/test_base_download.h 1970-01-01 00:00:00 +0000
1030+++ ubuntu-download-manager-tests/downloads/test_base_download.h 2014-01-29 12:16:44 +0000
1031@@ -0,0 +1,58 @@
1032+/*
1033+ * Copyright 2014 Canonical Ltd.
1034+ *
1035+ * This library is free software; you can redistribute it and/or
1036+ * modify it under the terms of version 3 of the GNU Lesser General Public
1037+ * License as published by the Free Software Foundation.
1038+ *
1039+ * This program is distributed in the hope that it will be useful,
1040+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1041+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1042+ * General Public License for more details.
1043+ *
1044+ * You should have received a copy of the GNU Lesser General Public
1045+ * License along with this library; if not, write to the
1046+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1047+ * Boston, MA 02110-1301, USA.
1048+ */
1049+
1050+#ifndef TEST_BASE_DOWNLOAD_H
1051+#define TEST_BASE_DOWNLOAD_H
1052+
1053+#include <QObject>
1054+#include <ubuntu/download_manager/tests/server/download.h>
1055+#include <ubuntu/download_manager/tests/base_testcase.h>
1056+#include <ubuntu/download_manager/tests/test_runner.h>
1057+
1058+class TestBaseDownload : public BaseTestCase {
1059+ Q_OBJECT
1060+
1061+ public:
1062+ explicit TestBaseDownload(QObject *parent = 0);
1063+
1064+ private slots: // NOLINT(whitespace/indent)
1065+
1066+ void init() override;
1067+
1068+ void testStartQueued();
1069+ void testStartNotQueued();
1070+ void testPauseQueued();
1071+ void testPauseNotQueued();
1072+ void testResumeQueued();
1073+ void testResumeNotQueued();
1074+ void testCancelQueued();
1075+ void testCancelNotQueued();
1076+
1077+ private:
1078+ QString _id;
1079+ QString _path;
1080+ bool _isConfined;
1081+ QString _rootPath;
1082+ QUrl _url;
1083+ QVariantMap _metadata;
1084+ QMap<QString, QString> _headers;
1085+};
1086+
1087+DECLARE_TEST(TestBaseDownload)
1088+
1089+#endif // TEST_BASE_DOWNLOAD_H
1090
1091=== modified file 'ubuntu-download-manager-tests/downloads/test_download_factory.cpp'
1092--- ubuntu-download-manager-tests/downloads/test_download_factory.cpp 2013-12-02 12:17:35 +0000
1093+++ ubuntu-download-manager-tests/downloads/test_download_factory.cpp 2014-01-29 12:16:44 +0000
1094@@ -17,6 +17,7 @@
1095 */
1096
1097 #include <downloads/file_download.h>
1098+#include <downloads/mms_file_download.h>
1099 #include <ubuntu/download_manager/system/hash_algorithm.h>
1100 #include <system/file_manager.h>
1101 #include <system/uuid_utils.h>
1102@@ -93,6 +94,25 @@
1103 }
1104
1105 void
1106+TestDownloadFactory::testCreateMmsDownload() {
1107+ _apparmor->record();
1108+
1109+ QString hash = "my-hash";
1110+ QString algo = "Md5";
1111+ QString hostname = "http://hostname.com";
1112+ int port = 88;
1113+ QString username = "username";
1114+ QString password = "password";
1115+
1116+
1117+ // same as above but assert hash and hash algo
1118+ QScopedPointer<Download> download(_downFactory->createMmsDownload(
1119+ "", QUrl("http://example.com"), hostname, port, username, password));
1120+ auto mms = qobject_cast<MmsFileDownload*>(download.data());
1121+ QVERIFY(mms != nullptr);
1122+}
1123+
1124+void
1125 TestDownloadFactory::testCreateGroupDownload() {
1126 _apparmor->record();
1127
1128
1129=== modified file 'ubuntu-download-manager-tests/downloads/test_download_factory.h'
1130--- ubuntu-download-manager-tests/downloads/test_download_factory.h 2014-01-10 16:38:56 +0000
1131+++ ubuntu-download-manager-tests/downloads/test_download_factory.h 2014-01-29 12:16:44 +0000
1132@@ -45,6 +45,7 @@
1133
1134 void testCreateDownload();
1135 void testCreateDownloadWithHash();
1136+ void testCreateMmsDownload();
1137 void testCreateGroupDownload();
1138 void testCreateDownloadWithValidUuid();
1139 void testCreateDownloadWithNullUuid();
1140
1141=== modified file 'ubuntu-download-manager-tests/downloads/test_download_queue.cpp'
1142--- ubuntu-download-manager-tests/downloads/test_download_queue.cpp 2014-01-20 16:54:58 +0000
1143+++ ubuntu-download-manager-tests/downloads/test_download_queue.cpp 2014-01-29 12:16:44 +0000
1144@@ -505,3 +505,56 @@
1145 QCOMPARE(QString("canDownload"), calledMethods[0].methodName());
1146 QCOMPARE(QString("startDownload"), calledMethods[1].methodName());
1147 }
1148+
1149+void
1150+TestDownloadQueue::testNewUnmanagedIncreasesNumber() {
1151+ _q->add(_first);
1152+
1153+ QCOMPARE(1, _q->size());
1154+ _second->setAddToQueue(false);
1155+
1156+ _q->add(_second);
1157+ QCOMPARE(2, _q->size());
1158+}
1159+
1160+void
1161+TestDownloadQueue::testErrorUnmanagedDecreasesNumber() {
1162+ QSignalSpy spy(_q, SIGNAL(downloadRemoved(QString)));
1163+ _first->setAddToQueue(false);
1164+
1165+ _q->add(_first);
1166+
1167+ QCOMPARE(1, _q->size());
1168+ _first->emitError("Error");
1169+
1170+ QTRY_COMPARE(spy.count(), 1);
1171+ QCOMPARE(0, _q->size());
1172+}
1173+
1174+void
1175+TestDownloadQueue::testFinishUnmanagedDecreasesNumber() {
1176+ QSignalSpy spy(_q, SIGNAL(downloadRemoved(QString)));
1177+ _first->setAddToQueue(false);
1178+
1179+ _q->add(_first);
1180+
1181+ QCOMPARE(1, _q->size());
1182+ _first->emitFinished("path");
1183+
1184+ QTRY_COMPARE(spy.count(), 1);
1185+ QCOMPARE(0, _q->size());
1186+}
1187+
1188+void
1189+TestDownloadQueue::testCancelUnmanagedDecreasesNumber() {
1190+ QSignalSpy spy(_q, SIGNAL(downloadRemoved(QString)));
1191+ _first->setAddToQueue(false);
1192+
1193+ _q->add(_first);
1194+
1195+ QCOMPARE(1, _q->size());
1196+ _first->cancel();
1197+
1198+ QTRY_COMPARE(spy.count(), 1);
1199+ QCOMPARE(0, _q->size());
1200+}
1201
1202=== modified file 'ubuntu-download-manager-tests/downloads/test_download_queue.h'
1203--- ubuntu-download-manager-tests/downloads/test_download_queue.h 2014-01-22 16:53:05 +0000
1204+++ ubuntu-download-manager-tests/downloads/test_download_queue.h 2014-01-29 12:16:44 +0000
1205@@ -57,6 +57,12 @@
1206 void testDownloadFinishedOtherReady();
1207 void testDownloadErrorWithOtherReady();
1208
1209+ // unmanaged downloads tests
1210+ void testNewUnmanagedIncreasesNumber();
1211+ void testErrorUnmanagedDecreasesNumber();
1212+ void testFinishUnmanagedDecreasesNumber();
1213+ void testCancelUnmanagedDecreasesNumber();
1214+
1215 private:
1216 bool _isConfined;
1217 QString _rootPath;
1218
1219=== added file 'ubuntu-download-manager-tests/downloads/test_mms_download.cpp'
1220--- ubuntu-download-manager-tests/downloads/test_mms_download.cpp 1970-01-01 00:00:00 +0000
1221+++ ubuntu-download-manager-tests/downloads/test_mms_download.cpp 2014-01-29 12:16:44 +0000
1222@@ -0,0 +1,68 @@
1223+/*
1224+ * Copyright 2014 Canonical Ltd.
1225+ *
1226+ * This library is free software; you can redistribute it and/or
1227+ * modify it under the terms of version 3 of the GNU Lesser General Public
1228+ * License as published by the Free Software Foundation.
1229+ *
1230+ * This program is distributed in the hope that it will be useful,
1231+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1232+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1233+ * General Public License for more details.
1234+ *
1235+ * You should have received a copy of the GNU Lesser General Public
1236+ * License along with this library; if not, write to the
1237+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1238+ * Boston, MA 02110-1301, USA.
1239+ */
1240+
1241+#include "test_mms_download.h"
1242+
1243+TestMmsDownload::TestMmsDownload(QObject* parent)
1244+ : BaseTestCase("TestMmsDownload", parent) {
1245+}
1246+
1247+void
1248+TestMmsDownload::testNetworkAccessManager() {
1249+ QString id = "id of the download";
1250+ QString path = "my-file";
1251+ bool isConfined = false;
1252+ QString rootPath = "/root/path/to/use";
1253+ QUrl url("http://example.com");
1254+ QVariantMap metadata;
1255+ QMap<QString, QString> headers;
1256+ QString hostname = "http://example.com";
1257+ int port = 80;
1258+ QString username = "username";
1259+ QString password = "password";
1260+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname,
1261+ port, username, password);
1262+
1263+ QScopedPointer<PublicMmsFileDownload> down(
1264+ new PublicMmsFileDownload(id, path, isConfined, rootPath,
1265+ url, metadata, headers, proxy));
1266+ ApnRequestFactory* nam = qobject_cast<ApnRequestFactory*>(down->nam());
1267+ QVERIFY(nam != nullptr);
1268+}
1269+
1270+void
1271+TestMmsDownload::testAddToQueue() {
1272+ QString id = "id of the download";
1273+ QString path = "my-file";
1274+ bool isConfined = false;
1275+ QString rootPath = "/root/path/to/use";
1276+ QUrl url("http://example.com");
1277+ QVariantMap metadata;
1278+ QMap<QString, QString> headers;
1279+ QString hostname = "http://example.com";
1280+ int port = 80;
1281+ QString username = "username";
1282+ QString password = "password";
1283+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname,
1284+ port, username, password);
1285+
1286+ QScopedPointer<PublicMmsFileDownload> down(
1287+ new PublicMmsFileDownload(id, path, isConfined, rootPath,
1288+ url, metadata, headers, proxy));
1289+ QVERIFY(!down->addToQueue());
1290+}
1291
1292=== added file 'ubuntu-download-manager-tests/downloads/test_mms_download.h'
1293--- ubuntu-download-manager-tests/downloads/test_mms_download.h 1970-01-01 00:00:00 +0000
1294+++ ubuntu-download-manager-tests/downloads/test_mms_download.h 2014-01-29 12:16:44 +0000
1295@@ -0,0 +1,70 @@
1296+/*
1297+ * Copyright 2014 Canonical Ltd.
1298+ *
1299+ * This library is free software; you can redistribute it and/or
1300+ * modify it under the terms of version 3 of the GNU Lesser General Public
1301+ * License as published by the Free Software Foundation.
1302+ *
1303+ * This program is distributed in the hope that it will be useful,
1304+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1305+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1306+ * General Public License for more details.
1307+ *
1308+ * You should have received a copy of the GNU Lesser General Public
1309+ * License along with this library; if not, write to the
1310+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1311+ * Boston, MA 02110-1301, USA.
1312+ */
1313+
1314+#ifndef TEST_MMS_DOWNLOAD_H
1315+#define TEST_MMS_DOWNLOAD_H
1316+
1317+#include <QObject>
1318+#include <system/request_factory.h>
1319+#include <system/apn_request_factory.h>
1320+#include <downloads/mms_file_download.h>
1321+#include <ubuntu/download_manager/tests/base_testcase.h>
1322+#include <ubuntu/download_manager/tests/test_runner.h>
1323+
1324+
1325+using namespace Ubuntu::DownloadManager::Daemon;
1326+using namespace Ubuntu::DownloadManager::System;
1327+
1328+class PublicMmsFileDownload : public MmsFileDownload {
1329+ Q_OBJECT
1330+
1331+ public:
1332+ PublicMmsFileDownload(const QString& id,
1333+ const QString& path,
1334+ bool isConfined,
1335+ const QString& rootPath,
1336+ const QUrl& url,
1337+ const QVariantMap& metadata,
1338+ const QMap<QString, QString>& headers,
1339+ const QNetworkProxy& proxy,
1340+ QObject* parent = 0)
1341+ : MmsFileDownload(id, path, isConfined, rootPath, url, metadata,
1342+ headers, proxy, parent) {
1343+ }
1344+
1345+ RequestFactory* nam() {
1346+ return _requestFactory;
1347+ }
1348+};
1349+
1350+class TestMmsDownload : public BaseTestCase {
1351+ Q_OBJECT
1352+
1353+ public:
1354+ explicit TestMmsDownload(QObject *parent = 0);
1355+
1356+ private slots: // NOLINT(whitespace/indent)
1357+
1358+ void testNetworkAccessManager();
1359+ void testAddToQueue();
1360+
1361+};
1362+
1363+DECLARE_TEST(TestMmsDownload)
1364+
1365+#endif // TEST_MMS_DOWNLOAD_H
1366
1367=== added directory 'ubuntu-download-manager-tests/system'
1368=== added file 'ubuntu-download-manager-tests/system/test_apn_request_factory.cpp'
1369--- ubuntu-download-manager-tests/system/test_apn_request_factory.cpp 1970-01-01 00:00:00 +0000
1370+++ ubuntu-download-manager-tests/system/test_apn_request_factory.cpp 2014-01-29 12:16:44 +0000
1371@@ -0,0 +1,57 @@
1372+/*
1373+ * Copyright 2014 Canonical Ltd.
1374+ *
1375+ * This library is free software; you can redistribute it and/or
1376+ * modify it under the terms of version 3 of the GNU Lesser General Public
1377+ * License as published by the Free Software Foundation.
1378+ *
1379+ * This program is distributed in the hope that it will be useful,
1380+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1381+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1382+ * General Public License for more details.
1383+ *
1384+ * You should have received a copy of the GNU Lesser General Public
1385+ * License along with this library; if not, write to the
1386+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1387+ * Boston, MA 02110-1301, USA.
1388+ */
1389+
1390+#include <QScopedPointer>
1391+#include <ubuntu/download_manager/tests/server/apn_request_factory.h>
1392+#include "test_apn_request_factory.h"
1393+
1394+TestApnRequestFactory::TestApnRequestFactory(QObject* parent)
1395+ : BaseTestCase("TestApnRequestFactory", parent) {
1396+}
1397+
1398+void
1399+TestApnRequestFactory::testProxySet_data() {
1400+ QTest::addColumn<QString>("hostName");
1401+ QTest::addColumn<int>("port");
1402+ QTest::addColumn<QString>("username");
1403+ QTest::addColumn<QString>("password");
1404+
1405+ QTest::newRow("First row") << "http://proxy.com" << 88
1406+ << "mandel" << "Qwsxd";
1407+ QTest::newRow("Second row") << "http://ubuntu.com" << 99
1408+ << "mark" << "trusty";
1409+ QTest::newRow("Third row") << "http://one.ubuntu.com" << 200
1410+ << "one" << "drop";
1411+}
1412+
1413+void
1414+TestApnRequestFactory::testProxySet() {
1415+ QFETCH(QString, hostName);
1416+ QFETCH(int, port);
1417+ QFETCH(QString, username);
1418+ QFETCH(QString, password);
1419+
1420+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostName, port,
1421+ username, password);
1422+ QScopedPointer<FakeApnRequestFactory> nam(new FakeApnRequestFactory(proxy));
1423+
1424+ QCOMPARE(hostName, nam->proxyHost());
1425+ QCOMPARE(port, nam->proxyPort());
1426+ QCOMPARE(username, nam->proxyUsername());
1427+ QCOMPARE(password, nam->proxyPassword());
1428+}
1429
1430=== added file 'ubuntu-download-manager-tests/system/test_apn_request_factory.h'
1431--- ubuntu-download-manager-tests/system/test_apn_request_factory.h 1970-01-01 00:00:00 +0000
1432+++ ubuntu-download-manager-tests/system/test_apn_request_factory.h 2014-01-29 12:16:44 +0000
1433@@ -0,0 +1,41 @@
1434+/*
1435+ * Copyright 2014 Canonical Ltd.
1436+ *
1437+ * This library is free software; you can redistribute it and/or
1438+ * modify it under the terms of version 3 of the GNU Lesser General Public
1439+ * License as published by the Free Software Foundation.
1440+ *
1441+ * This program is distributed in the hope that it will be useful,
1442+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1443+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1444+ * General Public License for more details.
1445+ *
1446+ * You should have received a copy of the GNU Lesser General Public
1447+ * License along with this library; if not, write to the
1448+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1449+ * Boston, MA 02110-1301, USA.
1450+ */
1451+
1452+#ifndef TEST_APN_REQUEST_FACTORY_H
1453+#define TEST_APN_REQUEST_FACTORY_H
1454+
1455+#include <QObject>
1456+#include <ubuntu/download_manager/tests/base_testcase.h>
1457+#include <ubuntu/download_manager/tests/test_runner.h>
1458+
1459+class TestApnRequestFactory : public BaseTestCase {
1460+ Q_OBJECT
1461+
1462+public:
1463+ explicit TestApnRequestFactory(QObject *parent = 0);
1464+
1465+ private slots: // NOLINT(whitespace/indent)
1466+
1467+ void testProxySet_data();
1468+ void testProxySet();
1469+
1470+};
1471+
1472+DECLARE_TEST(TestApnRequestFactory)
1473+
1474+#endif // TEST_APN_REQUEST_FACTORY_H
1475
1476=== modified file 'ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro'
1477--- ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2013-12-13 08:30:46 +0000
1478+++ ubuntu-download-manager-tests/ubuntu-download-manager-tests.pro 2014-01-29 12:16:44 +0000
1479@@ -25,7 +25,10 @@
1480 downloads/state_machines/test_cancel_download_transition.cpp \
1481 downloads/state_machines/test_resume_download_transition.cpp \
1482 downloads/state_machines/test_final_state.cpp \
1483- downloads/state_machines/test_file_download_sm.cpp
1484+ downloads/state_machines/test_file_download_sm.cpp \
1485+ system/test_apn_request_factory.cpp \
1486+ downloads/test_mms_download.cpp \
1487+ downloads/test_base_download.cpp
1488
1489 HEADERS += \
1490 downloads/test_download.h \
1491@@ -42,7 +45,10 @@
1492 downloads/state_machines/test_cancel_download_transition.h \
1493 downloads/state_machines/test_resume_download_transition.h \
1494 downloads/state_machines/test_final_state.h \
1495- downloads/state_machines/test_file_download_sm.h
1496+ downloads/state_machines/test_file_download_sm.h \
1497+ system/test_apn_request_factory.h \
1498+ downloads/test_mms_download.h \
1499+ downloads/test_base_download.h
1500
1501 LIBS += -L$$OUT_PWD/../ubuntu-download-manager-priv/ -lubuntu-download-manager-priv
1502

Subscribers

People subscribed via source and target branches