Merge lp:~mandel/ubuntu-download-manager/test-mode into lp:ubuntu-download-manager
- test-mode
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Manuel de la Peña | ||||
Approved revision: | 125 | ||||
Merged at revision: | 125 | ||||
Proposed branch: | lp:~mandel/ubuntu-download-manager/test-mode | ||||
Merge into: | lp:ubuntu-download-manager | ||||
Diff against target: |
885 lines (+392/-150) 20 files modified
libubuntudownloadmanager/application.cpp (+19/-14) libubuntudownloadmanager/application.h (+2/-0) libubuntudownloadmanager/download_daemon.cpp (+123/-111) libubuntudownloadmanager/download_daemon.h (+5/-5) libubuntudownloadmanager/download_factory.cpp (+20/-0) libubuntudownloadmanager/download_factory.h (+5/-0) libubuntudownloadmanager/download_manager.cpp (+26/-4) libubuntudownloadmanager/download_manager.h (+6/-0) libubuntudownloadmanager/request_factory.cpp (+43/-13) libubuntudownloadmanager/request_factory.h (+5/-0) ubuntu-download-manager-tests/fake_application.cpp (+18/-1) ubuntu-download-manager-tests/fake_application.h (+5/-0) ubuntu-download-manager-tests/fake_download_manager.cpp (+24/-0) ubuntu-download-manager-tests/fake_download_manager.h (+2/-0) ubuntu-download-manager-tests/fake_request_factory.cpp (+25/-0) ubuntu-download-manager-tests/fake_request_factory.h (+2/-0) ubuntu-download-manager-tests/test_download_daemon.cpp (+41/-0) ubuntu-download-manager-tests/test_download_daemon.h (+3/-0) ubuntu-download-manager-tests/test_download_manager.cpp (+15/-2) ubuntu-download-manager-tests/test_download_manager.h (+3/-0) |
||||
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/test-mode | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Mike McCracken (community) | Approve | ||
Ying-Chun Liu (community) | Approve | ||
Review via email: mp+186015@code.launchpad.net |
Commit message
Provide two command line args to be used in tests.
Description of the change
Provide two command line args to be used in tests.
Ying-Chun Liu (paulliu) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:122
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Manuel de la Peña (mandel) wrote : | # |
> 853 + _man->setAccept
> 854 +/*
> 855 + QList<MethodData> calledMethods = _requestFactory
> 856 + qDebug() << calledMethods;
> 857 + QCOMPARE(1, calledMethods.
> 858 + QCOMPARE(
> calledMethods[
> 859 + */
> 860 +}
>
> If the QCOMPARE is commented out, this test looks like an empty test?
Indeed, I must have done that while debugging, I'll fix that!
- 123. By Manuel de la Peña
-
Uncomment QCOMPARE.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:123
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Barry Warsaw (barry) wrote : | # |
I tested the -self-signed-certs option locally against some of my system-image tests. It appears to work as intended for both the good-path (https downloads with a valid self-signed cert) and bad-paths (https download with self-signed cert not added, and with bad self-signed cert).
LGTM!
Mike McCracken (mikemc) wrote : | # |
Approved with minor comments:
the comments "// set the args so that we..." in TestDownloadDae
appear to be copy n' paste errors.
typo: #define DISABPLE_TIMEOUT typo in download_daemon.cpp
- 124. By Manuel de la Peña
-
Fixed typo and wrong comments.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 125. By Manuel de la Peña
-
Merged with trunk.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:125
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'libubuntudownloadmanager/application.cpp' | |||
2 | --- libubuntudownloadmanager/application.cpp 2013-08-21 12:08:43 +0000 | |||
3 | +++ libubuntudownloadmanager/application.cpp 2013-09-18 11:41:58 +0000 | |||
4 | @@ -28,25 +28,24 @@ | |||
5 | 28 | Q_DECLARE_PUBLIC(Application) | 28 | Q_DECLARE_PUBLIC(Application) |
6 | 29 | 29 | ||
7 | 30 | public: | 30 | public: |
11 | 31 | explicit ApplicationPrivate(Application* parent); | 31 | explicit ApplicationPrivate(Application* parent) |
12 | 32 | 32 | : q_ptr(parent) { | |
13 | 33 | virtual void exit(int returnCode); | 33 | } |
14 | 34 | |||
15 | 35 | void exit(int returnCode) { | ||
16 | 36 | // get the application instance and exit | ||
17 | 37 | QCoreApplication* app = QCoreApplication::instance(); | ||
18 | 38 | app->exit(returnCode); | ||
19 | 39 | } | ||
20 | 40 | |||
21 | 41 | QStringList arguments() { | ||
22 | 42 | return QCoreApplication::arguments(); | ||
23 | 43 | } | ||
24 | 34 | 44 | ||
25 | 35 | private: | 45 | private: |
26 | 36 | Application* q_ptr; | 46 | Application* q_ptr; |
27 | 37 | }; | 47 | }; |
28 | 38 | 48 | ||
29 | 39 | ApplicationPrivate::ApplicationPrivate(Application* parent) | ||
30 | 40 | : q_ptr(parent) { | ||
31 | 41 | } | ||
32 | 42 | |||
33 | 43 | void | ||
34 | 44 | ApplicationPrivate::exit(int returnCode) { | ||
35 | 45 | // get the application instance and exit | ||
36 | 46 | QCoreApplication* app = QCoreApplication::instance(); | ||
37 | 47 | app->exit(returnCode); | ||
38 | 48 | } | ||
39 | 49 | |||
40 | 50 | /* | 49 | /* |
41 | 51 | * PUBLIC IMPLEMENTATION | 50 | * PUBLIC IMPLEMENTATION |
42 | 52 | */ | 51 | */ |
43 | @@ -63,3 +62,9 @@ | |||
44 | 63 | qDebug() << "Exit app" << returnCode; | 62 | qDebug() << "Exit app" << returnCode; |
45 | 64 | d->exit(returnCode); | 63 | d->exit(returnCode); |
46 | 65 | } | 64 | } |
47 | 65 | |||
48 | 66 | QStringList | ||
49 | 67 | Application::arguments() { | ||
50 | 68 | Q_D(Application); | ||
51 | 69 | return d->arguments(); | ||
52 | 70 | } | ||
53 | 66 | 71 | ||
54 | === modified file 'libubuntudownloadmanager/application.h' | |||
55 | --- libubuntudownloadmanager/application.h 2013-08-21 11:08:29 +0000 | |||
56 | +++ libubuntudownloadmanager/application.h 2013-09-18 11:41:58 +0000 | |||
57 | @@ -19,6 +19,7 @@ | |||
58 | 19 | #ifndef DOWNLOADER_LIB_APPLICATION_H | 19 | #ifndef DOWNLOADER_LIB_APPLICATION_H |
59 | 20 | #define DOWNLOADER_LIB_APPLICATION_H | 20 | #define DOWNLOADER_LIB_APPLICATION_H |
60 | 21 | 21 | ||
61 | 22 | #include <QStringList> | ||
62 | 22 | #include <QObject> | 23 | #include <QObject> |
63 | 23 | 24 | ||
64 | 24 | class ApplicationPrivate; | 25 | class ApplicationPrivate; |
65 | @@ -30,6 +31,7 @@ | |||
66 | 30 | explicit Application(QObject *parent = 0); | 31 | explicit Application(QObject *parent = 0); |
67 | 31 | 32 | ||
68 | 32 | virtual void exit(int returnCode = 0); | 33 | virtual void exit(int returnCode = 0); |
69 | 34 | virtual QStringList arguments(); | ||
70 | 33 | 35 | ||
71 | 34 | private: | 36 | private: |
72 | 35 | // use pimpl so that we can mantains ABI compatibility | 37 | // use pimpl so that we can mantains ABI compatibility |
73 | 36 | 38 | ||
74 | === modified file 'libubuntudownloadmanager/download_daemon.cpp' | |||
75 | --- libubuntudownloadmanager/download_daemon.cpp 2013-08-22 20:49:57 +0000 | |||
76 | +++ libubuntudownloadmanager/download_daemon.cpp 2013-09-18 11:41:58 +0000 | |||
77 | @@ -19,12 +19,16 @@ | |||
78 | 19 | #include <QtDBus/QDBusConnection> | 19 | #include <QtDBus/QDBusConnection> |
79 | 20 | #include <QDebug> | 20 | #include <QDebug> |
80 | 21 | #include <QSharedPointer> | 21 | #include <QSharedPointer> |
81 | 22 | #include <QSslCertificate> | ||
82 | 22 | #include "./application.h" | 23 | #include "./application.h" |
83 | 23 | #include "./logger.h" | 24 | #include "./logger.h" |
84 | 24 | #include "./download_manager.h" | 25 | #include "./download_manager.h" |
85 | 25 | #include "./download_manager_adaptor.h" | 26 | #include "./download_manager_adaptor.h" |
86 | 26 | #include "./download_daemon.h" | 27 | #include "./download_daemon.h" |
87 | 27 | 28 | ||
88 | 29 | #define DISABLE_TIMEOUT "-disable-timeout" | ||
89 | 30 | #define SELFSIGNED_CERT "-self-signed-certs" | ||
90 | 31 | |||
91 | 28 | /** | 32 | /** |
92 | 29 | * PRIVATE IMPLEMENATION | 33 | * PRIVATE IMPLEMENATION |
93 | 30 | */ | 34 | */ |
94 | @@ -33,24 +37,131 @@ | |||
95 | 33 | Q_DECLARE_PUBLIC(DownloadDaemon) | 37 | Q_DECLARE_PUBLIC(DownloadDaemon) |
96 | 34 | 38 | ||
97 | 35 | public: | 39 | public: |
109 | 36 | explicit DownloadDaemonPrivate(DownloadDaemon* parent); | 40 | explicit DownloadDaemonPrivate(DownloadDaemon* parent) |
110 | 37 | explicit DownloadDaemonPrivate(Application* app, | 41 | : q_ptr(parent) { |
111 | 38 | DBusConnection* conn, | 42 | _app = new Application(); |
112 | 39 | Timer* timer, | 43 | _conn = QSharedPointer<DBusConnection>(new DBusConnection()); |
113 | 40 | DownloadManager* man, | 44 | _shutDownTimer = new Timer(); |
114 | 41 | DownloadDaemon* parent); | 45 | _downInterface = new DownloadManager(_conn, q_ptr); |
115 | 42 | ~DownloadDaemonPrivate(); | 46 | init(); |
116 | 43 | 47 | } | |
117 | 44 | void start(); | 48 | |
118 | 45 | void onTimeout(); | 49 | DownloadDaemonPrivate(Application* app, |
119 | 46 | void onDownloadManagerSizeChanged(int size); | 50 | DBusConnection* conn, |
120 | 51 | Timer* timer, | ||
121 | 52 | DownloadManager* man, | ||
122 | 53 | DownloadDaemon* parent) | ||
123 | 54 | : _app(app), | ||
124 | 55 | _shutDownTimer(timer), | ||
125 | 56 | _conn(conn), | ||
126 | 57 | _downInterface(man), | ||
127 | 58 | q_ptr(parent) { | ||
128 | 59 | init(); | ||
129 | 60 | } | ||
130 | 61 | |||
131 | 62 | ~DownloadDaemonPrivate() { | ||
132 | 63 | // no need to delete the adaptor because the interface is its parent | ||
133 | 64 | if (_downInterface) | ||
134 | 65 | delete _downInterface; | ||
135 | 66 | if (_app) | ||
136 | 67 | delete _app; | ||
137 | 68 | if (_shutDownTimer) | ||
138 | 69 | delete _shutDownTimer; | ||
139 | 70 | |||
140 | 71 | // stop logging | ||
141 | 72 | Logger::stopLogging(); | ||
142 | 73 | } | ||
143 | 74 | |||
144 | 75 | void start() { | ||
145 | 76 | qDebug() << "Starting daemon"; | ||
146 | 77 | _downAdaptor = new DownloadManagerAdaptor(_downInterface); | ||
147 | 78 | bool ret = _conn->registerService( | ||
148 | 79 | "com.canonical.applications.Downloader"); | ||
149 | 80 | if (ret) { | ||
150 | 81 | qDebug() << "Service registered to" | ||
151 | 82 | << "com.canonical.applications.Downloader"; | ||
152 | 83 | ret = _conn->registerObject("/", _downInterface); | ||
153 | 84 | qDebug() << ret; | ||
154 | 85 | if (!ret) { | ||
155 | 86 | qDebug() << "Could not register interface"; | ||
156 | 87 | _app->exit(-1); | ||
157 | 88 | } | ||
158 | 89 | return; | ||
159 | 90 | } | ||
160 | 91 | qDebug() << "Could not register service"; | ||
161 | 92 | _app->exit(-1); | ||
162 | 93 | } | ||
163 | 94 | |||
164 | 95 | void onTimeout() { | ||
165 | 96 | qDebug() << "Timeout reached, shutdown service."; | ||
166 | 97 | _app->exit(0); | ||
167 | 98 | } | ||
168 | 99 | |||
169 | 100 | void onDownloadManagerSizeChanged(int size) { | ||
170 | 101 | bool isActive = _shutDownTimer->isActive(); | ||
171 | 102 | qDebug() << "Timer is active:" << isActive << "size is:" << size; | ||
172 | 103 | |||
173 | 104 | if (isActive && size > 0) { | ||
174 | 105 | qDebug() << "Timer must be stopped because we have" << size | ||
175 | 106 | << "downloads."; | ||
176 | 107 | _shutDownTimer->stop(); | ||
177 | 108 | } | ||
178 | 109 | if (!isActive && size == 0) { | ||
179 | 110 | qDebug() << "Timer must be started because we have 0 downloads."; | ||
180 | 111 | _shutDownTimer->start(timeout); | ||
181 | 112 | } | ||
182 | 113 | } | ||
183 | 47 | 114 | ||
184 | 48 | static const int timeout = 30000; | 115 | static const int timeout = 30000; |
185 | 49 | 116 | ||
186 | 50 | private: | 117 | private: |
188 | 51 | void init(); | 118 | void parseCommandLine() { |
189 | 119 | QStringList args = _app->arguments(); | ||
190 | 120 | if (args.contains(SELFSIGNED_CERT)) { | ||
191 | 121 | int index = args.indexOf(SELFSIGNED_CERT); | ||
192 | 122 | if (args.count() > index + 1) { | ||
193 | 123 | QString certsRegex = args[index + 1]; | ||
194 | 124 | _certs = QSslCertificate::fromPath(certsRegex); | ||
195 | 125 | qDebug() << "Accepting self signed certs" << _certs; | ||
196 | 126 | } else { | ||
197 | 127 | qCritical() << "Missing certs path"; | ||
198 | 128 | } | ||
199 | 129 | } // certs | ||
200 | 130 | _isTimeoutEnabled = !args.contains(DISABLE_TIMEOUT); | ||
201 | 131 | qDebug() << "Timeout is enabled:" << _isTimeoutEnabled; | ||
202 | 132 | } | ||
203 | 133 | |||
204 | 134 | void init() { | ||
205 | 135 | Q_Q(DownloadDaemon); | ||
206 | 136 | |||
207 | 137 | // parse command line to decide if the timer is enabled and if | ||
208 | 138 | // we accept self signed certs | ||
209 | 139 | parseCommandLine(); | ||
210 | 140 | if (_isTimeoutEnabled) { | ||
211 | 141 | q->connect(_shutDownTimer, SIGNAL(timeout()), | ||
212 | 142 | q, SLOT(onTimeout())); | ||
213 | 143 | _shutDownTimer->start(timeout); | ||
214 | 144 | } | ||
215 | 145 | |||
216 | 146 | _downInterface->setAcceptedCertificates(_certs); | ||
217 | 147 | // connect to the download manager changes | ||
218 | 148 | q->connect(_downInterface, | ||
219 | 149 | SIGNAL(sizeChanged(int)), // NOLINT (readability/function) | ||
220 | 150 | q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function) | ||
221 | 151 | |||
222 | 152 | // set logging | ||
223 | 153 | Logger::setupLogging(); | ||
224 | 154 | #ifdef DEBUG | ||
225 | 155 | Logger::setLogLevel(QtDebugMsg); | ||
226 | 156 | #else | ||
227 | 157 | if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "") | ||
228 | 158 | Logger::setLogLevel(QtDebugMsg); | ||
229 | 159 | #endif | ||
230 | 160 | } | ||
231 | 52 | 161 | ||
232 | 53 | private: | 162 | private: |
233 | 163 | bool _isTimeoutEnabled; | ||
234 | 164 | QList<QSslCertificate> _certs; | ||
235 | 54 | Application* _app; | 165 | Application* _app; |
236 | 55 | Timer* _shutDownTimer; | 166 | Timer* _shutDownTimer; |
237 | 56 | QSharedPointer<DBusConnection> _conn; | 167 | QSharedPointer<DBusConnection> _conn; |
238 | @@ -59,105 +170,6 @@ | |||
239 | 59 | DownloadDaemon* q_ptr; | 170 | DownloadDaemon* q_ptr; |
240 | 60 | }; | 171 | }; |
241 | 61 | 172 | ||
242 | 62 | DownloadDaemonPrivate::DownloadDaemonPrivate(DownloadDaemon* parent) | ||
243 | 63 | : q_ptr(parent) { | ||
244 | 64 | _app = new Application(); | ||
245 | 65 | _conn = QSharedPointer<DBusConnection>(new DBusConnection()); | ||
246 | 66 | _shutDownTimer = new Timer(); | ||
247 | 67 | _downInterface = new DownloadManager(_conn, q_ptr); | ||
248 | 68 | init(); | ||
249 | 69 | } | ||
250 | 70 | |||
251 | 71 | DownloadDaemonPrivate::DownloadDaemonPrivate(Application* app, | ||
252 | 72 | DBusConnection* conn, | ||
253 | 73 | Timer* timer, | ||
254 | 74 | DownloadManager* man, | ||
255 | 75 | DownloadDaemon* parent) | ||
256 | 76 | : _app(app), | ||
257 | 77 | _shutDownTimer(timer), | ||
258 | 78 | _conn(conn), | ||
259 | 79 | _downInterface(man), | ||
260 | 80 | q_ptr(parent) { | ||
261 | 81 | init(); | ||
262 | 82 | } | ||
263 | 83 | |||
264 | 84 | void DownloadDaemonPrivate::init() { | ||
265 | 85 | Q_Q(DownloadDaemon); | ||
266 | 86 | |||
267 | 87 | q->connect(_shutDownTimer, SIGNAL(timeout()), | ||
268 | 88 | q, SLOT(onTimeout())); | ||
269 | 89 | _shutDownTimer->start(timeout); | ||
270 | 90 | |||
271 | 91 | // connect to the download manager changes | ||
272 | 92 | q->connect(_downInterface, | ||
273 | 93 | SIGNAL(sizeChanged(int)), // NOLINT (readability/function) | ||
274 | 94 | q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function) | ||
275 | 95 | |||
276 | 96 | // set logging | ||
277 | 97 | Logger::setupLogging(); | ||
278 | 98 | #ifdef DEBUG | ||
279 | 99 | Logger::setLogLevel(QtDebugMsg); | ||
280 | 100 | #else | ||
281 | 101 | if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "") | ||
282 | 102 | Logger::setLogLevel(QtDebugMsg); | ||
283 | 103 | #endif | ||
284 | 104 | } | ||
285 | 105 | |||
286 | 106 | DownloadDaemonPrivate::~DownloadDaemonPrivate() { | ||
287 | 107 | // no need to delete the adaptor because the interface is its parent | ||
288 | 108 | if (_downInterface) | ||
289 | 109 | delete _downInterface; | ||
290 | 110 | if (_app) | ||
291 | 111 | delete _app; | ||
292 | 112 | if (_shutDownTimer) | ||
293 | 113 | delete _shutDownTimer; | ||
294 | 114 | |||
295 | 115 | // stop logging | ||
296 | 116 | Logger::setupLogging(); | ||
297 | 117 | } | ||
298 | 118 | |||
299 | 119 | void | ||
300 | 120 | DownloadDaemonPrivate::start() { | ||
301 | 121 | qDebug() << "Starting daemon"; | ||
302 | 122 | _downAdaptor = new DownloadManagerAdaptor(_downInterface); | ||
303 | 123 | bool ret = _conn->registerService("com.canonical.applications.Downloader"); | ||
304 | 124 | if (ret) { | ||
305 | 125 | qDebug() << "Service registered to" | ||
306 | 126 | << "com.canonical.applications.Downloader"; | ||
307 | 127 | ret = _conn->registerObject("/", _downInterface); | ||
308 | 128 | qDebug() << ret; | ||
309 | 129 | if (!ret) { | ||
310 | 130 | qDebug() << "Could not register interface"; | ||
311 | 131 | _app->exit(-1); | ||
312 | 132 | } | ||
313 | 133 | return; | ||
314 | 134 | } | ||
315 | 135 | qDebug() << "Could not register service"; | ||
316 | 136 | _app->exit(-1); | ||
317 | 137 | } | ||
318 | 138 | |||
319 | 139 | void | ||
320 | 140 | DownloadDaemonPrivate::onTimeout() { | ||
321 | 141 | qDebug() << "Timeout reached, shutdown service."; | ||
322 | 142 | _app->exit(0); | ||
323 | 143 | } | ||
324 | 144 | |||
325 | 145 | void | ||
326 | 146 | DownloadDaemonPrivate::onDownloadManagerSizeChanged(int size) { | ||
327 | 147 | bool isActive = _shutDownTimer->isActive(); | ||
328 | 148 | qDebug() << "Timer is active:" << isActive << "size is:" << size; | ||
329 | 149 | |||
330 | 150 | if (isActive && size > 0) { | ||
331 | 151 | qDebug() << "Timer must be stopped because we have" << size | ||
332 | 152 | << "downloads."; | ||
333 | 153 | _shutDownTimer->stop(); | ||
334 | 154 | } | ||
335 | 155 | if (!isActive && size == 0) { | ||
336 | 156 | qDebug() << "Timer must be started because we have 0 downloads."; | ||
337 | 157 | _shutDownTimer->start(timeout); | ||
338 | 158 | } | ||
339 | 159 | } | ||
340 | 160 | |||
341 | 161 | /** | 173 | /** |
342 | 162 | * PUBLIC IMPLEMENTATION | 174 | * PUBLIC IMPLEMENTATION |
343 | 163 | */ | 175 | */ |
344 | 164 | 176 | ||
345 | === modified file 'libubuntudownloadmanager/download_daemon.h' | |||
346 | --- libubuntudownloadmanager/download_daemon.h 2013-08-22 20:49:57 +0000 | |||
347 | +++ libubuntudownloadmanager/download_daemon.h 2013-09-18 11:41:58 +0000 | |||
348 | @@ -33,11 +33,11 @@ | |||
349 | 33 | 33 | ||
350 | 34 | public: | 34 | public: |
351 | 35 | explicit DownloadDaemon(QObject *parent = 0); | 35 | explicit DownloadDaemon(QObject *parent = 0); |
357 | 36 | explicit DownloadDaemon(Application* app, | 36 | DownloadDaemon(Application* app, |
358 | 37 | DBusConnection* conn, | 37 | DBusConnection* conn, |
359 | 38 | Timer* timer, | 38 | Timer* timer, |
360 | 39 | DownloadManager* man, | 39 | DownloadManager* man, |
361 | 40 | QObject *parent = 0); | 40 | QObject *parent = 0); |
362 | 41 | 41 | ||
363 | 42 | public slots: // NOLINT (whitespace/indent) | 42 | public slots: // NOLINT (whitespace/indent) |
364 | 43 | void start(); | 43 | void start(); |
365 | 44 | 44 | ||
366 | === modified file 'libubuntudownloadmanager/download_factory.cpp' | |||
367 | --- libubuntudownloadmanager/download_factory.cpp 2013-09-18 10:18:24 +0000 | |||
368 | +++ libubuntudownloadmanager/download_factory.cpp 2013-09-18 11:41:58 +0000 | |||
369 | @@ -166,6 +166,14 @@ | |||
370 | 166 | return down; | 166 | return down; |
371 | 167 | } | 167 | } |
372 | 168 | 168 | ||
373 | 169 | QList<QSslCertificate> acceptedCertificates() { | ||
374 | 170 | return _nam->acceptedCertificates(); | ||
375 | 171 | } | ||
376 | 172 | |||
377 | 173 | void setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
378 | 174 | _nam->setAcceptedCertificates(certs); | ||
379 | 175 | } | ||
380 | 176 | |||
381 | 169 | private: | 177 | private: |
382 | 170 | QSharedPointer<AppArmor> _apparmor; | 178 | QSharedPointer<AppArmor> _apparmor; |
383 | 171 | QSharedPointer<SystemNetworkInfo> _networkInfo; | 179 | QSharedPointer<SystemNetworkInfo> _networkInfo; |
384 | @@ -245,3 +253,15 @@ | |||
385 | 245 | return d->createDownloadForGroup(isConfined, rootPath, url, hash, algo, | 253 | return d->createDownloadForGroup(isConfined, rootPath, url, hash, algo, |
386 | 246 | metadata, headers); | 254 | metadata, headers); |
387 | 247 | } | 255 | } |
388 | 256 | |||
389 | 257 | QList<QSslCertificate> | ||
390 | 258 | DownloadFactory::acceptedCertificates() { | ||
391 | 259 | Q_D(DownloadFactory); | ||
392 | 260 | return d->acceptedCertificates(); | ||
393 | 261 | } | ||
394 | 262 | |||
395 | 263 | void | ||
396 | 264 | DownloadFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
397 | 265 | Q_D(DownloadFactory); | ||
398 | 266 | d->setAcceptedCertificates(certs); | ||
399 | 267 | } | ||
400 | 248 | 268 | ||
401 | === modified file 'libubuntudownloadmanager/download_factory.h' | |||
402 | --- libubuntudownloadmanager/download_factory.h 2013-09-18 10:18:24 +0000 | |||
403 | +++ libubuntudownloadmanager/download_factory.h 2013-09-18 11:41:58 +0000 | |||
404 | @@ -77,6 +77,11 @@ | |||
405 | 77 | const QVariantMap& metadata, | 77 | const QVariantMap& metadata, |
406 | 78 | const QMap<QString, QString>& headers); | 78 | const QMap<QString, QString>& headers); |
407 | 79 | 79 | ||
408 | 80 | // mainly for testing purposes | ||
409 | 81 | |||
410 | 82 | virtual QList<QSslCertificate> acceptedCertificates(); | ||
411 | 83 | virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs); | ||
412 | 84 | |||
413 | 80 | private: | 85 | private: |
414 | 81 | // use pimpl so that we can mantains ABI compatibility | 86 | // use pimpl so that we can mantains ABI compatibility |
415 | 82 | DownloadFactoryPrivate* d_ptr; | 87 | DownloadFactoryPrivate* d_ptr; |
416 | 83 | 88 | ||
417 | === modified file 'libubuntudownloadmanager/download_manager.cpp' | |||
418 | --- libubuntudownloadmanager/download_manager.cpp 2013-09-10 12:18:34 +0000 | |||
419 | +++ libubuntudownloadmanager/download_manager.cpp 2013-09-18 11:41:58 +0000 | |||
420 | @@ -40,10 +40,11 @@ | |||
421 | 40 | _apparmor = QSharedPointer<AppArmor>(new AppArmor()); | 40 | _apparmor = QSharedPointer<AppArmor>(new AppArmor()); |
422 | 41 | _networkInfo = QSharedPointer<SystemNetworkInfo>( | 41 | _networkInfo = QSharedPointer<SystemNetworkInfo>( |
423 | 42 | new SystemNetworkInfo()); | 42 | new SystemNetworkInfo()); |
425 | 43 | _nam = QSharedPointer<RequestFactory>(new RequestFactory()); | 43 | QSharedPointer<RequestFactory> nam = QSharedPointer<RequestFactory>( |
426 | 44 | new RequestFactory()); | ||
427 | 44 | _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory()); | 45 | _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory()); |
428 | 45 | _downloadFactory = QSharedPointer<DownloadFactory>( | 46 | _downloadFactory = QSharedPointer<DownloadFactory>( |
430 | 46 | new DownloadFactory(_apparmor, _networkInfo, _nam, | 47 | new DownloadFactory(_apparmor, _networkInfo, nam, |
431 | 47 | _processFactory)); | 48 | _processFactory)); |
432 | 48 | _downloadsQueue = QSharedPointer<DownloadQueue>( | 49 | _downloadsQueue = QSharedPointer<DownloadQueue>( |
433 | 49 | new DownloadQueue(_networkInfo)); | 50 | new DownloadQueue(_networkInfo)); |
434 | @@ -91,8 +92,17 @@ | |||
435 | 91 | Q_UNUSED(path); | 92 | Q_UNUSED(path); |
436 | 92 | } | 93 | } |
437 | 93 | 94 | ||
438 | 95 | QList<QSslCertificate> acceptedCertificates() { | ||
439 | 96 | return _downloadFactory->acceptedCertificates(); | ||
440 | 97 | } | ||
441 | 98 | |||
442 | 99 | void setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
443 | 100 | qDebug() << __PRETTY_FUNCTION__ << certs; | ||
444 | 101 | _downloadFactory->setAcceptedCertificates(certs); | ||
445 | 102 | } | ||
446 | 103 | |||
447 | 94 | void onDownloadsChanged(QString path) { | 104 | void onDownloadsChanged(QString path) { |
449 | 95 | qDebug() << __FUNCTION__ << path; | 105 | qDebug() << __PRETTY_FUNCTION__ << path; |
450 | 96 | Q_Q(DownloadManager); | 106 | Q_Q(DownloadManager); |
451 | 97 | emit q->sizeChanged(_downloadsQueue->size()); | 107 | emit q->sizeChanged(_downloadsQueue->size()); |
452 | 98 | } | 108 | } |
453 | @@ -188,7 +198,6 @@ | |||
454 | 188 | qulonglong _throttle; | 198 | qulonglong _throttle; |
455 | 189 | QSharedPointer<AppArmor> _apparmor; | 199 | QSharedPointer<AppArmor> _apparmor; |
456 | 190 | QSharedPointer<SystemNetworkInfo> _networkInfo; | 200 | QSharedPointer<SystemNetworkInfo> _networkInfo; |
457 | 191 | QSharedPointer<RequestFactory> _nam; | ||
458 | 192 | QSharedPointer<ProcessFactory> _processFactory; | 201 | QSharedPointer<ProcessFactory> _processFactory; |
459 | 193 | QSharedPointer<DownloadFactory> _downloadFactory; | 202 | QSharedPointer<DownloadFactory> _downloadFactory; |
460 | 194 | QSharedPointer<DownloadQueue> _downloadsQueue; | 203 | QSharedPointer<DownloadQueue> _downloadsQueue; |
461 | @@ -226,6 +235,19 @@ | |||
462 | 226 | d->loadPreviewsDownloads(path); | 235 | d->loadPreviewsDownloads(path); |
463 | 227 | } | 236 | } |
464 | 228 | 237 | ||
465 | 238 | QList<QSslCertificate> | ||
466 | 239 | DownloadManager::acceptedCertificates() { | ||
467 | 240 | Q_D(DownloadManager); | ||
468 | 241 | return d->acceptedCertificates(); | ||
469 | 242 | } | ||
470 | 243 | |||
471 | 244 | |||
472 | 245 | void | ||
473 | 246 | DownloadManager::setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
474 | 247 | Q_D(DownloadManager); | ||
475 | 248 | return d->setAcceptedCertificates(certs); | ||
476 | 249 | } | ||
477 | 250 | |||
478 | 229 | qulonglong | 251 | qulonglong |
479 | 230 | DownloadManager::defaultThrottle() { | 252 | DownloadManager::defaultThrottle() { |
480 | 231 | Q_D(DownloadManager); | 253 | Q_D(DownloadManager); |
481 | 232 | 254 | ||
482 | === modified file 'libubuntudownloadmanager/download_manager.h' | |||
483 | --- libubuntudownloadmanager/download_manager.h 2013-09-09 10:30:18 +0000 | |||
484 | +++ libubuntudownloadmanager/download_manager.h 2013-09-18 11:41:58 +0000 | |||
485 | @@ -24,6 +24,7 @@ | |||
486 | 24 | #include <QtDBus/QDBusObjectPath> | 24 | #include <QtDBus/QDBusObjectPath> |
487 | 25 | #include <QtDBus/QDBusContext> | 25 | #include <QtDBus/QDBusContext> |
488 | 26 | #include <QSharedPointer> | 26 | #include <QSharedPointer> |
489 | 27 | #include <QSslCertificate> | ||
490 | 27 | #include "./dbus_connection.h" | 28 | #include "./dbus_connection.h" |
491 | 28 | #include "./download.h" | 29 | #include "./download.h" |
492 | 29 | #include "./download_queue.h" | 30 | #include "./download_queue.h" |
493 | @@ -44,8 +45,13 @@ | |||
494 | 44 | DownloadFactory* downloadFactory, | 45 | DownloadFactory* downloadFactory, |
495 | 45 | DownloadQueue* queue, | 46 | DownloadQueue* queue, |
496 | 46 | QObject *parent = 0); | 47 | QObject *parent = 0); |
497 | 48 | |||
498 | 47 | void loadPreviewsDownloads(const QString &path); | 49 | void loadPreviewsDownloads(const QString &path); |
499 | 48 | 50 | ||
500 | 51 | // mainly for testing purposes | ||
501 | 52 | virtual QList<QSslCertificate> acceptedCertificates(); | ||
502 | 53 | virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs); | ||
503 | 54 | |||
504 | 49 | public slots: // NOLINT(whitespace/indent) | 55 | public slots: // NOLINT(whitespace/indent) |
505 | 50 | QDBusObjectPath createDownload(DownloadStruct download); | 56 | QDBusObjectPath createDownload(DownloadStruct download); |
506 | 51 | 57 | ||
507 | 52 | 58 | ||
508 | === modified file 'libubuntudownloadmanager/request_factory.cpp' | |||
509 | --- libubuntudownloadmanager/request_factory.cpp 2013-07-23 16:03:10 +0000 | |||
510 | +++ libubuntudownloadmanager/request_factory.cpp 2013-09-18 11:41:58 +0000 | |||
511 | @@ -17,6 +17,7 @@ | |||
512 | 17 | */ | 17 | */ |
513 | 18 | 18 | ||
514 | 19 | #include <QNetworkAccessManager> | 19 | #include <QNetworkAccessManager> |
515 | 20 | #include <QSslError> | ||
516 | 20 | #include "./request_factory.h" | 21 | #include "./request_factory.h" |
517 | 21 | 22 | ||
518 | 22 | /* | 23 | /* |
519 | @@ -27,24 +28,41 @@ | |||
520 | 27 | Q_DECLARE_PUBLIC(RequestFactory) | 28 | Q_DECLARE_PUBLIC(RequestFactory) |
521 | 28 | 29 | ||
522 | 29 | public: | 30 | public: |
526 | 30 | explicit RequestFactoryPrivate(RequestFactory* parent); | 31 | explicit RequestFactoryPrivate(RequestFactory* parent) |
527 | 31 | 32 | : q_ptr(parent) { | |
528 | 32 | NetworkReply* get(const QNetworkRequest& request); | 33 | _nam = new QNetworkAccessManager(); |
529 | 34 | } | ||
530 | 35 | |||
531 | 36 | NetworkReply* get(const QNetworkRequest& request) { | ||
532 | 37 | QNetworkReply* reply = _nam->get(request); | ||
533 | 38 | |||
534 | 39 | if (_certs.count() > 0) { | ||
535 | 40 | // build the expected ssl errors | ||
536 | 41 | QList<QSslError> expectedSslErrors; | ||
537 | 42 | foreach(const QSslCertificate& certificate, _certs) { | ||
538 | 43 | QSslError error(QSslError::SelfSignedCertificate, certificate); | ||
539 | 44 | expectedSslErrors.append(error); | ||
540 | 45 | } | ||
541 | 46 | reply->ignoreSslErrors(expectedSslErrors); | ||
542 | 47 | } | ||
543 | 48 | |||
544 | 49 | return new NetworkReply(reply); | ||
545 | 50 | } | ||
546 | 51 | |||
547 | 52 | QList<QSslCertificate> acceptedCertificates() { | ||
548 | 53 | return _certs; | ||
549 | 54 | } | ||
550 | 55 | |||
551 | 56 | void setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
552 | 57 | _certs = certs; | ||
553 | 58 | } | ||
554 | 59 | |||
555 | 33 | private: | 60 | private: |
556 | 61 | QList<QSslCertificate> _certs; | ||
557 | 34 | QNetworkAccessManager* _nam; | 62 | QNetworkAccessManager* _nam; |
558 | 35 | RequestFactory* q_ptr; | 63 | RequestFactory* q_ptr; |
559 | 36 | }; | 64 | }; |
560 | 37 | 65 | ||
561 | 38 | RequestFactoryPrivate::RequestFactoryPrivate(RequestFactory* parent) | ||
562 | 39 | : q_ptr(parent) { | ||
563 | 40 | _nam = new QNetworkAccessManager(); | ||
564 | 41 | } | ||
565 | 42 | |||
566 | 43 | NetworkReply* | ||
567 | 44 | RequestFactoryPrivate::get(const QNetworkRequest& request) { | ||
568 | 45 | return new NetworkReply(_nam->get(request)); | ||
569 | 46 | } | ||
570 | 47 | |||
571 | 48 | /* | 66 | /* |
572 | 49 | * PUBLIC IMPLEMENTATION | 67 | * PUBLIC IMPLEMENTATION |
573 | 50 | */ | 68 | */ |
574 | @@ -59,3 +77,15 @@ | |||
575 | 59 | Q_D(RequestFactory); | 77 | Q_D(RequestFactory); |
576 | 60 | return d->get(request); | 78 | return d->get(request); |
577 | 61 | } | 79 | } |
578 | 80 | |||
579 | 81 | QList<QSslCertificate> | ||
580 | 82 | RequestFactory::acceptedCertificates() { | ||
581 | 83 | Q_D(RequestFactory); | ||
582 | 84 | return d->acceptedCertificates(); | ||
583 | 85 | } | ||
584 | 86 | |||
585 | 87 | void | ||
586 | 88 | RequestFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) { | ||
587 | 89 | Q_D(RequestFactory); | ||
588 | 90 | d->setAcceptedCertificates(certs); | ||
589 | 91 | } | ||
590 | 62 | 92 | ||
591 | === modified file 'libubuntudownloadmanager/request_factory.h' | |||
592 | --- libubuntudownloadmanager/request_factory.h 2013-07-23 16:03:57 +0000 | |||
593 | +++ libubuntudownloadmanager/request_factory.h 2013-09-18 11:41:58 +0000 | |||
594 | @@ -21,6 +21,7 @@ | |||
595 | 21 | 21 | ||
596 | 22 | #include <QNetworkRequest> | 22 | #include <QNetworkRequest> |
597 | 23 | #include <QObject> | 23 | #include <QObject> |
598 | 24 | #include <QSslCertificate> | ||
599 | 24 | #include "./app-downloader-lib_global.h" | 25 | #include "./app-downloader-lib_global.h" |
600 | 25 | #include "./network_reply.h" | 26 | #include "./network_reply.h" |
601 | 26 | 27 | ||
602 | @@ -34,6 +35,10 @@ | |||
603 | 34 | 35 | ||
604 | 35 | virtual NetworkReply* get(const QNetworkRequest& request); | 36 | virtual NetworkReply* get(const QNetworkRequest& request); |
605 | 36 | 37 | ||
606 | 38 | // mainly for testing purposes | ||
607 | 39 | virtual QList<QSslCertificate> acceptedCertificates(); | ||
608 | 40 | virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs); | ||
609 | 41 | |||
610 | 37 | private: | 42 | private: |
611 | 38 | // use pimpl so that we can mantains ABI compatibility | 43 | // use pimpl so that we can mantains ABI compatibility |
612 | 39 | RequestFactoryPrivate* d_ptr; | 44 | RequestFactoryPrivate* d_ptr; |
613 | 40 | 45 | ||
614 | === modified file 'ubuntu-download-manager-tests/fake_application.cpp' | |||
615 | --- ubuntu-download-manager-tests/fake_application.cpp 2013-08-21 11:40:25 +0000 | |||
616 | +++ ubuntu-download-manager-tests/fake_application.cpp 2013-09-18 11:41:58 +0000 | |||
617 | @@ -16,7 +16,7 @@ | |||
618 | 16 | * Boston, MA 02110-1301, USA. | 16 | * Boston, MA 02110-1301, USA. |
619 | 17 | */ | 17 | */ |
620 | 18 | 18 | ||
622 | 19 | #include "fake_application.h" | 19 | #include "./fake_application.h" |
623 | 20 | 20 | ||
624 | 21 | FakeApplication::FakeApplication(QObject *parent) | 21 | FakeApplication::FakeApplication(QObject *parent) |
625 | 22 | : Application(parent), | 22 | : Application(parent), |
626 | @@ -35,3 +35,20 @@ | |||
627 | 35 | _called.append(methodData); | 35 | _called.append(methodData); |
628 | 36 | } | 36 | } |
629 | 37 | } | 37 | } |
630 | 38 | |||
631 | 39 | QStringList | ||
632 | 40 | FakeApplication::arguments() { | ||
633 | 41 | if (_recording) { | ||
634 | 42 | QList<QObject*> inParams; | ||
635 | 43 | QList<QObject*> outParams; | ||
636 | 44 | MethodParams params(inParams, outParams); | ||
637 | 45 | MethodData methodData("arguments", params); | ||
638 | 46 | _called.append(methodData); | ||
639 | 47 | } | ||
640 | 48 | return _args; | ||
641 | 49 | } | ||
642 | 50 | |||
643 | 51 | void | ||
644 | 52 | FakeApplication::setArguments(QStringList args) { | ||
645 | 53 | _args = args; | ||
646 | 54 | } | ||
647 | 38 | 55 | ||
648 | === modified file 'ubuntu-download-manager-tests/fake_application.h' | |||
649 | --- ubuntu-download-manager-tests/fake_application.h 2013-08-21 12:21:49 +0000 | |||
650 | +++ ubuntu-download-manager-tests/fake_application.h 2013-09-18 11:41:58 +0000 | |||
651 | @@ -30,6 +30,11 @@ | |||
652 | 30 | explicit FakeApplication(QObject *parent = 0); | 30 | explicit FakeApplication(QObject *parent = 0); |
653 | 31 | 31 | ||
654 | 32 | void exit(int returnCode = 0) override; | 32 | void exit(int returnCode = 0) override; |
655 | 33 | |||
656 | 34 | QStringList arguments() override; | ||
657 | 35 | void setArguments(QStringList args); | ||
658 | 36 | private: | ||
659 | 37 | QStringList _args; | ||
660 | 33 | }; | 38 | }; |
661 | 34 | 39 | ||
662 | 35 | #endif // FAKE_APPLICATION_H | 40 | #endif // FAKE_APPLICATION_H |
663 | 36 | 41 | ||
664 | === modified file 'ubuntu-download-manager-tests/fake_download_manager.cpp' | |||
665 | --- ubuntu-download-manager-tests/fake_download_manager.cpp 2013-08-22 20:49:57 +0000 | |||
666 | +++ ubuntu-download-manager-tests/fake_download_manager.cpp 2013-09-18 11:41:58 +0000 | |||
667 | @@ -30,3 +30,27 @@ | |||
668 | 30 | emit sizeChanged(size); | 30 | emit sizeChanged(size); |
669 | 31 | } | 31 | } |
670 | 32 | 32 | ||
671 | 33 | QList<QSslCertificate> | ||
672 | 34 | FakeDownloadManager::acceptedCertificates() { | ||
673 | 35 | if (_recording) { | ||
674 | 36 | QList<QObject*> inParams; | ||
675 | 37 | QList<QObject*> outParams; | ||
676 | 38 | MethodParams params(inParams, outParams); | ||
677 | 39 | MethodData methodData("acceptedCertificates", params); | ||
678 | 40 | _called.append(methodData); | ||
679 | 41 | } | ||
680 | 42 | return DownloadManager::acceptedCertificates(); | ||
681 | 43 | } | ||
682 | 44 | |||
683 | 45 | void | ||
684 | 46 | FakeDownloadManager::setAcceptedCertificates( | ||
685 | 47 | const QList<QSslCertificate>& certs) { | ||
686 | 48 | if (_recording) { | ||
687 | 49 | QList<QObject*> inParams; | ||
688 | 50 | QList<QObject*> outParams; | ||
689 | 51 | MethodParams params(inParams, outParams); | ||
690 | 52 | MethodData methodData("setAcceptedCertificates", params); | ||
691 | 53 | _called.append(methodData); | ||
692 | 54 | } | ||
693 | 55 | DownloadManager::setAcceptedCertificates(certs); | ||
694 | 56 | } | ||
695 | 33 | 57 | ||
696 | === modified file 'ubuntu-download-manager-tests/fake_download_manager.h' | |||
697 | --- ubuntu-download-manager-tests/fake_download_manager.h 2013-08-22 20:49:57 +0000 | |||
698 | +++ ubuntu-download-manager-tests/fake_download_manager.h 2013-09-18 11:41:58 +0000 | |||
699 | @@ -32,6 +32,8 @@ | |||
700 | 32 | QObject *parent = 0); | 32 | QObject *parent = 0); |
701 | 33 | 33 | ||
702 | 34 | void emitSizeChaged(int size); | 34 | void emitSizeChaged(int size); |
703 | 35 | QList<QSslCertificate> acceptedCertificates() override; | ||
704 | 36 | void setAcceptedCertificates(const QList<QSslCertificate>& certs) override; | ||
705 | 35 | }; | 37 | }; |
706 | 36 | 38 | ||
707 | 37 | #endif // FAKE_DOWNLOAD_MANAGER_H | 39 | #endif // FAKE_DOWNLOAD_MANAGER_H |
708 | 38 | 40 | ||
709 | === modified file 'ubuntu-download-manager-tests/fake_request_factory.cpp' | |||
710 | --- ubuntu-download-manager-tests/fake_request_factory.cpp 2013-07-23 17:55:51 +0000 | |||
711 | +++ ubuntu-download-manager-tests/fake_request_factory.cpp 2013-09-18 11:41:58 +0000 | |||
712 | @@ -56,3 +56,28 @@ | |||
713 | 56 | } | 56 | } |
714 | 57 | return reply; | 57 | return reply; |
715 | 58 | } | 58 | } |
716 | 59 | |||
717 | 60 | QList<QSslCertificate> | ||
718 | 61 | FakeRequestFactory::acceptedCertificates() { | ||
719 | 62 | if (_recording) { | ||
720 | 63 | QList<QObject*> inParams; | ||
721 | 64 | QList<QObject*> outParams; | ||
722 | 65 | MethodParams params(inParams, outParams); | ||
723 | 66 | MethodData methodData("acceptedCertificates", params); | ||
724 | 67 | _called.append(methodData); | ||
725 | 68 | } | ||
726 | 69 | return RequestFactory::acceptedCertificates(); | ||
727 | 70 | } | ||
728 | 71 | |||
729 | 72 | void | ||
730 | 73 | FakeRequestFactory::setAcceptedCertificates( | ||
731 | 74 | const QList<QSslCertificate>& certs) { | ||
732 | 75 | if (_recording) { | ||
733 | 76 | QList<QObject*> inParams; | ||
734 | 77 | QList<QObject*> outParams; | ||
735 | 78 | MethodParams params(inParams, outParams); | ||
736 | 79 | MethodData methodData("setAcceptedCertificates", params); | ||
737 | 80 | _called.append(methodData); | ||
738 | 81 | } | ||
739 | 82 | RequestFactory::setAcceptedCertificates(certs); | ||
740 | 83 | } | ||
741 | 59 | 84 | ||
742 | === modified file 'ubuntu-download-manager-tests/fake_request_factory.h' | |||
743 | --- ubuntu-download-manager-tests/fake_request_factory.h 2013-07-23 17:57:12 +0000 | |||
744 | +++ ubuntu-download-manager-tests/fake_request_factory.h 2013-09-18 11:41:58 +0000 | |||
745 | @@ -46,6 +46,8 @@ | |||
746 | 46 | 46 | ||
747 | 47 | // overriden methods used to fake the nam | 47 | // overriden methods used to fake the nam |
748 | 48 | NetworkReply* get(const QNetworkRequest& request); | 48 | NetworkReply* get(const QNetworkRequest& request); |
749 | 49 | QList<QSslCertificate> acceptedCertificates() override; | ||
750 | 50 | void setAcceptedCertificates(const QList<QSslCertificate>& certs) override; | ||
751 | 49 | }; | 51 | }; |
752 | 50 | 52 | ||
753 | 51 | #endif // FAKE_QNETWORK_ACCESS_MANAGER_H | 53 | #endif // FAKE_QNETWORK_ACCESS_MANAGER_H |
754 | 52 | 54 | ||
755 | === modified file 'ubuntu-download-manager-tests/test_download_daemon.cpp' | |||
756 | --- ubuntu-download-manager-tests/test_download_daemon.cpp 2013-08-22 20:49:57 +0000 | |||
757 | +++ ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-18 11:41:58 +0000 | |||
758 | @@ -141,3 +141,44 @@ | |||
759 | 141 | QCOMPARE(QString("exit"), calledMethods[0].methodName()); | 141 | QCOMPARE(QString("exit"), calledMethods[0].methodName()); |
760 | 142 | } | 142 | } |
761 | 143 | 143 | ||
762 | 144 | void | ||
763 | 145 | TestDownloadDaemon::testDisableTimeout() { | ||
764 | 146 | _timer->record(); | ||
765 | 147 | |||
766 | 148 | // set the args so that we disable the timeout | ||
767 | 149 | QStringList args; | ||
768 | 150 | args << "-disable-timeout"; | ||
769 | 151 | _app->setArguments(args); | ||
770 | 152 | |||
771 | 153 | // assert that start is never called | ||
772 | 154 | _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this); | ||
773 | 155 | QList<MethodData> calledMethods = _timer->calledMethods(); | ||
774 | 156 | QCOMPARE(0, calledMethods.count()); | ||
775 | 157 | } | ||
776 | 158 | |||
777 | 159 | void | ||
778 | 160 | TestDownloadDaemon::testSelfSignedCerts() { | ||
779 | 161 | _man->record(); | ||
780 | 162 | QStringList args; | ||
781 | 163 | args << "-self-signed-certs" << "*.pem"; | ||
782 | 164 | _app->setArguments(args); | ||
783 | 165 | |||
784 | 166 | // assert that we set the certs | ||
785 | 167 | _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this); | ||
786 | 168 | QList<MethodData> calledMethods = _man->calledMethods(); | ||
787 | 169 | QCOMPARE(1, calledMethods.count()); | ||
788 | 170 | QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName()); | ||
789 | 171 | } | ||
790 | 172 | |||
791 | 173 | void | ||
792 | 174 | TestDownloadDaemon::testSelfSignedCertsMissingPath() { | ||
793 | 175 | _man->record(); | ||
794 | 176 | QStringList args; | ||
795 | 177 | args << "-self-signed-certs"; | ||
796 | 178 | _app->setArguments(args); | ||
797 | 179 | |||
798 | 180 | // assert that we do not crash | ||
799 | 181 | _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this); | ||
800 | 182 | QList<MethodData> calledMethods = _man->calledMethods(); | ||
801 | 183 | QCOMPARE(1, calledMethods.count()); | ||
802 | 184 | } | ||
803 | 144 | 185 | ||
804 | === modified file 'ubuntu-download-manager-tests/test_download_daemon.h' | |||
805 | --- ubuntu-download-manager-tests/test_download_daemon.h 2013-08-22 20:49:57 +0000 | |||
806 | +++ ubuntu-download-manager-tests/test_download_daemon.h 2013-09-18 11:41:58 +0000 | |||
807 | @@ -43,6 +43,9 @@ | |||
808 | 43 | void testTimerStop(); | 43 | void testTimerStop(); |
809 | 44 | void testTimerStart(); | 44 | void testTimerStart(); |
810 | 45 | void testTimeoutExit(); | 45 | void testTimeoutExit(); |
811 | 46 | void testDisableTimeout(); | ||
812 | 47 | void testSelfSignedCerts(); | ||
813 | 48 | void testSelfSignedCertsMissingPath(); | ||
814 | 46 | 49 | ||
815 | 47 | private: | 50 | private: |
816 | 48 | FakeTimer* _timer; | 51 | FakeTimer* _timer; |
817 | 49 | 52 | ||
818 | === modified file 'ubuntu-download-manager-tests/test_download_manager.cpp' | |||
819 | --- ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-10 12:18:34 +0000 | |||
820 | +++ ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-18 11:41:58 +0000 | |||
821 | @@ -20,7 +20,6 @@ | |||
822 | 20 | #include <download_factory.h> | 20 | #include <download_factory.h> |
823 | 21 | #include <download_struct.h> | 21 | #include <download_struct.h> |
824 | 22 | #include "./fake_process_factory.h" | 22 | #include "./fake_process_factory.h" |
825 | 23 | #include "./fake_request_factory.h" | ||
826 | 24 | #include "./fake_system_network_info.h" | 23 | #include "./fake_system_network_info.h" |
827 | 25 | #include "./test_download_manager.h" | 24 | #include "./test_download_manager.h" |
828 | 26 | 25 | ||
829 | @@ -35,10 +34,11 @@ | |||
830 | 35 | _q = new FakeDownloadQueue(QSharedPointer<SystemNetworkInfo>(_networkInfo)); | 34 | _q = new FakeDownloadQueue(QSharedPointer<SystemNetworkInfo>(_networkInfo)); |
831 | 36 | _uuidFactory = new FakeUuidFactory(); | 35 | _uuidFactory = new FakeUuidFactory(); |
832 | 37 | _apparmor = new FakeAppArmor(QSharedPointer<UuidFactory>(_uuidFactory)); | 36 | _apparmor = new FakeAppArmor(QSharedPointer<UuidFactory>(_uuidFactory)); |
833 | 37 | _requestFactory = new FakeRequestFactory(); | ||
834 | 38 | _downloadFactory = new FakeDownloadFactory( | 38 | _downloadFactory = new FakeDownloadFactory( |
835 | 39 | QSharedPointer<AppArmor>(_apparmor), | 39 | QSharedPointer<AppArmor>(_apparmor), |
836 | 40 | QSharedPointer<SystemNetworkInfo>(_networkInfo), | 40 | QSharedPointer<SystemNetworkInfo>(_networkInfo), |
838 | 41 | QSharedPointer<RequestFactory>(new FakeRequestFactory()), | 41 | QSharedPointer<RequestFactory>(_requestFactory), |
839 | 42 | QSharedPointer<ProcessFactory>(new FakeProcessFactory())); | 42 | QSharedPointer<ProcessFactory>(new FakeProcessFactory())); |
840 | 43 | _man = new DownloadManager(qSharedPointerCast<DBusConnection>(_conn), | 43 | _man = new DownloadManager(qSharedPointerCast<DBusConnection>(_conn), |
841 | 44 | _networkInfo, _downloadFactory, _q); | 44 | _networkInfo, _downloadFactory, _q); |
842 | @@ -471,3 +471,16 @@ | |||
843 | 471 | QList<QVariant> arguments = spy.takeFirst(); | 471 | QList<QVariant> arguments = spy.takeFirst(); |
844 | 472 | QCOMPARE(arguments.at(0).toInt(), size); | 472 | QCOMPARE(arguments.at(0).toInt(), size); |
845 | 473 | } | 473 | } |
846 | 474 | |||
847 | 475 | void | ||
848 | 476 | TestDownloadManager::testSetSelfSignedCerts() { | ||
849 | 477 | // assert that the factory does get the certs | ||
850 | 478 | _requestFactory->record(); | ||
851 | 479 | QList<QSslCertificate> certs; | ||
852 | 480 | _man->setAcceptedCertificates(certs); | ||
853 | 481 | |||
854 | 482 | QList<MethodData> calledMethods = _requestFactory->calledMethods(); | ||
855 | 483 | qDebug() << calledMethods; | ||
856 | 484 | QCOMPARE(1, calledMethods.count()); | ||
857 | 485 | QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName()); | ||
858 | 486 | } | ||
859 | 474 | 487 | ||
860 | === modified file 'ubuntu-download-manager-tests/test_download_manager.h' | |||
861 | --- ubuntu-download-manager-tests/test_download_manager.h 2013-09-10 12:18:34 +0000 | |||
862 | +++ ubuntu-download-manager-tests/test_download_manager.h 2013-09-18 11:41:58 +0000 | |||
863 | @@ -28,6 +28,7 @@ | |||
864 | 28 | #include "./fake_dbus_connection.h" | 28 | #include "./fake_dbus_connection.h" |
865 | 29 | #include "./fake_download_queue.h" | 29 | #include "./fake_download_queue.h" |
866 | 30 | #include "./fake_download_factory.h" | 30 | #include "./fake_download_factory.h" |
867 | 31 | #include "./fake_request_factory.h" | ||
868 | 31 | #include "./fake_uuid_factory.h" | 32 | #include "./fake_uuid_factory.h" |
869 | 32 | #include "./fake_system_network_info.h" | 33 | #include "./fake_system_network_info.h" |
870 | 33 | 34 | ||
871 | @@ -59,12 +60,14 @@ | |||
872 | 59 | void testSetThrottleWithDownloads(); | 60 | void testSetThrottleWithDownloads(); |
873 | 60 | void testSizeChangedEmittedOnAddition(); | 61 | void testSizeChangedEmittedOnAddition(); |
874 | 61 | void testSizeChangedEmittedOnRemoval(); | 62 | void testSizeChangedEmittedOnRemoval(); |
875 | 63 | void testSetSelfSignedCerts(); | ||
876 | 62 | 64 | ||
877 | 63 | private: | 65 | private: |
878 | 64 | QCryptographicHash::Algorithm algoFromString(const QString& data); | 66 | QCryptographicHash::Algorithm algoFromString(const QString& data); |
879 | 65 | 67 | ||
880 | 66 | private: | 68 | private: |
881 | 67 | FakeSystemNetworkInfo* _networkInfo; | 69 | FakeSystemNetworkInfo* _networkInfo; |
882 | 70 | FakeRequestFactory* _requestFactory; | ||
883 | 68 | FakeDownloadFactory* _downloadFactory; | 71 | FakeDownloadFactory* _downloadFactory; |
884 | 69 | QSharedPointer<FakeDBusConnection> _conn; | 72 | QSharedPointer<FakeDBusConnection> _conn; |
885 | 70 | FakeDownloadQueue* _q; | 73 | FakeDownloadQueue* _q; |
853 + _man->setAccept edCertificates( certs); ->calledMethods (); count() ); QString( "setAcceptedCer tificates" ), calledMethods[ 0].methodName( ));
854 +/*
855 + QList<MethodData> calledMethods = _requestFactory
856 + qDebug() << calledMethods;
857 + QCOMPARE(1, calledMethods.
858 + QCOMPARE(
859 + */
860 +}
If the QCOMPARE is commented out, this test looks like an empty test?