Merge lp:~dobey/unity-scope-click/without-crashing into lp:unity-scope-click
- without-crashing
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~dobey/unity-scope-click/without-crashing |
Merge into: | lp:unity-scope-click |
Diff against target: |
557 lines (+142/-64) 19 files modified
libclickscope/click/download-manager.cpp (+23/-12) libclickscope/click/pay.cpp (+0/-3) libclickscope/click/preview.cpp (+0/-4) libclickscope/click/qtbridge.h (+16/-0) libclickscope/click/reviews.cpp (+2/-1) libclickscope/click/ubuntuone_credentials.cpp (+37/-1) libclickscope/click/ubuntuone_credentials.h (+3/-2) libclickscope/click/webclient.cpp (+15/-19) libclickscope/click/webclient.h (+1/-1) libclickscope/tests/mock_ubuntuone_credentials.h (+5/-5) libclickscope/tests/mock_webclient.h (+2/-3) libclickscope/tests/test_download_manager.cpp (+2/-4) libclickscope/tests/test_index.cpp (+13/-1) libclickscope/tests/test_reviews.cpp (+13/-0) libclickscope/tests/test_webclient.cpp (+4/-8) scope/clickapps/apps-scope.cpp (+2/-0) scope/clickapps/apps-scope.h (+1/-0) scope/clickstore/store-scope.cpp (+2/-0) scope/clickstore/store-scope.h (+1/-0) |
To merge this branch: | bzr merge lp:~dobey/unity-scope-click/without-crashing |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity API Team | Pending | ||
Review via email: mp+290773@code.launchpad.net |
Commit message
Refactor the code to process Qt events while waiting on future into a template.
Wait for Qt callbacks from downloadmanager before continuing.
Description of the change
- 443. By dobey
-
Use const references in the error callback args.
- 444. By dobey
-
Keep the cancellable around.
- 445. By dobey
-
Block in the preview on getting the progress object path.
- 446. By dobey
-
Call web::Client::call with full argument list.
- 447. By dobey
-
Revert the last change.
- 448. By dobey
-
Fix lambda arg declarations.
- 449. By dobey
-
Revert the addition of promise/future in preview.
- 450. By dobey
-
Oops, missed changing one callback to setting the promise.
- 451. By dobey
-
Use toStdString to convert from QString.
- 452. By dobey
-
Need to convert for qdebug now.
Unmerged revisions
- 452. By dobey
-
Need to convert for qdebug now.
- 451. By dobey
-
Use toStdString to convert from QString.
- 450. By dobey
-
Oops, missed changing one callback to setting the promise.
- 449. By dobey
-
Revert the addition of promise/future in preview.
- 448. By dobey
-
Fix lambda arg declarations.
- 447. By dobey
-
Revert the last change.
- 446. By dobey
-
Call web::Client::call with full argument list.
- 445. By dobey
-
Block in the preview on getting the progress object path.
- 444. By dobey
-
Keep the cancellable around.
- 443. By dobey
-
Use const references in the error callback args.
Preview Diff
1 | === modified file 'libclickscope/click/download-manager.cpp' |
2 | --- libclickscope/click/download-manager.cpp 2016-03-30 14:14:14 +0000 |
3 | +++ libclickscope/click/download-manager.cpp 2016-04-01 19:19:47 +0000 |
4 | @@ -28,6 +28,7 @@ |
5 | */ |
6 | |
7 | #include "download-manager.h" |
8 | +#include "qtbridge.h" |
9 | |
10 | #include <QDebug> |
11 | #include <QObject> |
12 | @@ -77,9 +78,12 @@ |
13 | void DownloadManager::get_progress(const std::string& package_name, |
14 | const std::function<void (std::string)>& callback) |
15 | { |
16 | + std::promise<std::string> promise; |
17 | + auto future = promise.get_future(); |
18 | + |
19 | dm->getAllDownloadsWithMetadata(DOWNLOAD_APP_ID_KEY, |
20 | QString::fromStdString(package_name), |
21 | - [callback, package_name](const QString& /*key*/, const QString& /*value*/, DownloadsList* downloads_list){ |
22 | + [callback, package_name, &promise](const QString& /*key*/, const QString& /*value*/, DownloadsList* downloads_list){ |
23 | // got downloads matching metadata |
24 | std::string object_path; |
25 | auto downloads = downloads_list->downloads(); |
26 | @@ -92,12 +96,15 @@ |
27 | if (downloads.size() > 1) { |
28 | qWarning() << "More than one download with the same object path"; |
29 | } |
30 | - callback(object_path); |
31 | - }, [callback, package_name](const QString& /*key*/, const QString& /*value*/, DownloadsList* /*downloads_list*/){ |
32 | + promise.set_value(object_path); |
33 | + }, [callback, package_name, &promise](const QString& /*key*/, const QString& /*value*/, DownloadsList* /*downloads_list*/){ |
34 | // no downloads found |
35 | qDebug() << "No object path found for package" << QString::fromStdString(package_name); |
36 | - callback(""); |
37 | + promise.set_value(""); |
38 | }); |
39 | + qt::core::world::wait_for_future_ready<std::string>(future); |
40 | + auto result = future.get(); |
41 | + callback(result); |
42 | } |
43 | |
44 | click::web::Cancellable DownloadManager::start(const std::string& url, |
45 | @@ -131,21 +138,26 @@ |
46 | metadata, |
47 | headers); |
48 | |
49 | + std::promise<std::pair<std::string, Error>> promise; |
50 | + auto future = promise.get_future(); |
51 | dm->createDownload(downloadStruct, |
52 | - [callback](Download* download) { |
53 | + [callback, &promise](Download* download) { |
54 | if (download->isError()) { |
55 | auto error = download->error()->errorString().toUtf8().data(); |
56 | qDebug() << "Received error from ubuntu-download-manager:" << error; |
57 | callback(error, Error::DownloadInstallError); |
58 | } else { |
59 | download->start(); |
60 | - callback(download->id().toUtf8().data(), Error::NoError); |
61 | + promise.set_value(std::pair<std::string, Error>{download->id().toUtf8().data(), Error::NoError}); |
62 | } |
63 | }, |
64 | - [callback](Download* download) { |
65 | - callback(download->error()->errorString().toUtf8().data(), |
66 | - Error::DownloadInstallError); |
67 | + [callback, &promise](Download* download) { |
68 | + promise.set_value(std::pair<std::string, Error>{download->error()->errorString().toUtf8().data(), |
69 | + Error::DownloadInstallError}); |
70 | }); |
71 | + qt::core::world::wait_for_future_ready<std::pair<std::string, Error>>(future); |
72 | + auto result = future.get(); |
73 | + callback(result.first, result.second); |
74 | } else { |
75 | std::string error{"Unhandled HTTP response code: "}; |
76 | error += status; |
77 | @@ -154,11 +166,11 @@ |
78 | }); |
79 | QObject::connect(response.data(), &click::web::Response::error, |
80 | [this, callback, package_name](QString error, int error_code) { |
81 | - qDebug() << QStringLiteral("Network error (%1) fetching click token for:").arg(error_code) << package_name.c_str(); |
82 | + qWarning() << QStringLiteral("Network error (%1) fetching click token for:").arg(error_code) << package_name.c_str(); |
83 | switch(error_code) { |
84 | case 401: |
85 | case 403: |
86 | - sso->invalidateCredentials(); |
87 | + client->invalidateCredentials(); |
88 | callback(error.toUtf8().data(), Error::CredentialsError); |
89 | break; |
90 | default: |
91 | @@ -172,7 +184,6 @@ |
92 | void DownloadManager::setCredentialsService(const QSharedPointer<click::CredentialsService>& credentialsService) |
93 | { |
94 | sso = credentialsService; |
95 | - client->setCredentialsService(sso); |
96 | } |
97 | |
98 | } // namespace click |
99 | |
100 | === modified file 'libclickscope/click/pay.cpp' |
101 | --- libclickscope/click/pay.cpp 2016-03-30 14:14:14 +0000 |
102 | +++ libclickscope/click/pay.cpp 2016-04-01 19:19:47 +0000 |
103 | @@ -228,9 +228,6 @@ |
104 | |
105 | click::web::Cancellable Package::get_purchases(std::function<void(const PurchaseSet&)> callback) |
106 | { |
107 | - QSharedPointer<click::CredentialsService> sso(new click::CredentialsService()); |
108 | - client->setCredentialsService(sso); |
109 | - |
110 | QSharedPointer<click::web::Response> response = client->call |
111 | (get_base_url() + pay::API_ROOT + pay::PURCHASES_API_PATH, "GET", true); |
112 | |
113 | |
114 | === modified file 'libclickscope/click/preview.cpp' |
115 | --- libclickscope/click/preview.cpp 2016-03-30 14:14:14 +0000 |
116 | +++ libclickscope/click/preview.cpp 2016-04-01 19:19:47 +0000 |
117 | @@ -734,8 +734,6 @@ |
118 | std::promise<bool> promise; |
119 | auto future = promise.get_future(); |
120 | run_under_qt([this, reply, &promise]() { |
121 | - QSharedPointer<click::CredentialsService> sso(new click::CredentialsService()); |
122 | - dm->setCredentialsService(sso); |
123 | dm->start(download_url, download_sha512, result["name"].get_string(), |
124 | [this, reply, &promise] (std::string msg, DownloadManager::Error dmerr){ |
125 | switch (dmerr) |
126 | @@ -888,8 +886,6 @@ |
127 | std::promise<bool> submit_promise; |
128 | std::future<bool> submit_future = submit_promise.get_future(); |
129 | qt::core::world::enter_with_task([this, review, &submit_promise, widget_id]() mutable { |
130 | - QSharedPointer<click::CredentialsService> sso(new click::CredentialsService()); |
131 | - client->setCredentialsService(sso); |
132 | if (widget_id == "rating") { |
133 | submit_operation = reviews->submit_review(review, |
134 | [&submit_promise](click::Reviews::Error){ |
135 | |
136 | === modified file 'libclickscope/click/qtbridge.h' |
137 | --- libclickscope/click/qtbridge.h 2014-05-26 14:02:45 +0000 |
138 | +++ libclickscope/click/qtbridge.h 2016-04-01 19:19:47 +0000 |
139 | @@ -20,6 +20,7 @@ |
140 | #ifndef QT_CORE_WORLD_BRIDGE_H_ |
141 | #define QT_CORE_WORLD_BRIDGE_H_ |
142 | |
143 | +#include<QCoreApplication> |
144 | #include <QObject> |
145 | |
146 | #include <functional> |
147 | @@ -80,6 +81,21 @@ |
148 | |
149 | return future; |
150 | } |
151 | + |
152 | +/** |
153 | + * @brief Waits for a promise to be fulfilled, without blocking Qt event loop; |
154 | + * @param future The future to wait on for ready state. |
155 | + */ |
156 | +template<typename T> |
157 | +inline void wait_for_future_ready(const std::future<T>& future) |
158 | +{ |
159 | + std::future_status status = future.wait_for(std::chrono::milliseconds(0)); |
160 | + while (status != std::future_status::ready) { |
161 | + QCoreApplication::processEvents(); |
162 | + status = future.wait_for(std::chrono::milliseconds(100)); |
163 | + } |
164 | +} |
165 | + |
166 | } |
167 | } |
168 | } |
169 | |
170 | === modified file 'libclickscope/click/reviews.cpp' |
171 | --- libclickscope/click/reviews.cpp 2016-03-30 14:14:14 +0000 |
172 | +++ libclickscope/click/reviews.cpp 2016-04-01 19:19:47 +0000 |
173 | @@ -131,7 +131,8 @@ |
174 | click::web::CallParams params; |
175 | params.add(click::REVIEWS_QUERY_ARGNAME, package_name.c_str()); |
176 | QSharedPointer<click::web::Response> response = client->call |
177 | - (get_base_url() + click::REVIEWS_API_PATH, params); |
178 | + (get_base_url() + click::REVIEWS_API_PATH, "GET", false, |
179 | + std::map<std::string, std::string>{}, "", params); |
180 | |
181 | QObject::connect(response.data(), &click::web::Response::finished, |
182 | [=](QString reply) { |
183 | |
184 | === modified file 'libclickscope/click/ubuntuone_credentials.cpp' |
185 | --- libclickscope/click/ubuntuone_credentials.cpp 2016-03-30 14:14:14 +0000 |
186 | +++ libclickscope/click/ubuntuone_credentials.cpp 2016-04-01 19:19:47 +0000 |
187 | @@ -1,5 +1,5 @@ |
188 | /* |
189 | - * Copyright (C) 2014 Canonical Ltd. |
190 | + * Copyright (C) 2014-2016 Canonical Ltd. |
191 | * |
192 | * This program is free software: you can redistribute it and/or modify it |
193 | * under the terms of the GNU General Public License version 3, as published |
194 | @@ -28,6 +28,10 @@ |
195 | */ |
196 | |
197 | #include "ubuntuone_credentials.h" |
198 | +#include "qtbridge.h" |
199 | + |
200 | +#include <future> |
201 | + |
202 | |
203 | namespace u1 = UbuntuOne; |
204 | |
205 | @@ -47,6 +51,38 @@ |
206 | { |
207 | } |
208 | |
209 | +UbuntuOne::Token click::CredentialsService::getToken() |
210 | +{ |
211 | + if (!_token.isValid()) { |
212 | + std::promise<UbuntuOne::Token> promise; |
213 | + auto future = promise.get_future(); |
214 | + |
215 | + auto success = QObject::connect(ssoService.data(), |
216 | + &u1::SSOService::credentialsFound, |
217 | + [this, &promise](const u1::Token& token) { |
218 | + emit credentialsFound(_token); |
219 | + promise.set_value(token); |
220 | + }); |
221 | + auto notfound = QObject::connect(ssoService.data(), |
222 | + &u1::SSOService::credentialsNotFound, |
223 | + [this, &promise]() { |
224 | + qWarning() << "No Ubuntu One token found."; |
225 | + emit credentialsNotFound(); |
226 | + promise.set_value(u1::Token()); |
227 | + }); |
228 | + |
229 | + getCredentials(); |
230 | + |
231 | + qt::core::world::wait_for_future_ready<UbuntuOne::Token>(future); |
232 | + |
233 | + _token = future.get(); |
234 | + QObject::disconnect(success); |
235 | + QObject::disconnect(notfound); |
236 | + } |
237 | + |
238 | + return _token; |
239 | +} |
240 | + |
241 | void click::CredentialsService::getCredentials() |
242 | { |
243 | ssoService->getCredentials(); |
244 | |
245 | === modified file 'libclickscope/click/ubuntuone_credentials.h' |
246 | --- libclickscope/click/ubuntuone_credentials.h 2016-03-30 14:14:14 +0000 |
247 | +++ libclickscope/click/ubuntuone_credentials.h 2016-04-01 19:19:47 +0000 |
248 | @@ -1,5 +1,5 @@ |
249 | /* |
250 | - * Copyright (C) 2014 Canonical Ltd. |
251 | + * Copyright (C) 2014-2016 Canonical Ltd. |
252 | * |
253 | * This program is free software: you can redistribute it and/or modify it |
254 | * under the terms of the GNU General Public License version 3, as published |
255 | @@ -47,6 +47,7 @@ |
256 | |
257 | CredentialsService& operator=(const CredentialsService&) = delete; |
258 | |
259 | + virtual UbuntuOne::Token getToken(); |
260 | virtual void getCredentials(); |
261 | virtual void invalidateCredentials(); |
262 | |
263 | @@ -57,7 +58,7 @@ |
264 | |
265 | private: |
266 | QScopedPointer<UbuntuOne::SSOService> ssoService; |
267 | - |
268 | + UbuntuOne::Token _token; |
269 | }; // CredentialsService |
270 | |
271 | } // namespace click |
272 | |
273 | === modified file 'libclickscope/click/webclient.cpp' |
274 | --- libclickscope/click/webclient.cpp 2016-03-30 14:14:14 +0000 |
275 | +++ libclickscope/click/webclient.cpp 2016-04-01 19:19:47 +0000 |
276 | @@ -82,7 +82,7 @@ |
277 | const std::string& iri, |
278 | const click::web::CallParams& params) |
279 | { |
280 | - return call(iri, "GET", false, |
281 | + return call(iri, "GET", true, |
282 | std::map<std::string, std::string>(), "", params); |
283 | } |
284 | |
285 | @@ -132,25 +132,21 @@ |
286 | request->setRawHeader(DEVICE_ID_HEADER.c_str(), deviceId.data()); |
287 | |
288 | if (sign && !impl->sso.isNull()) { |
289 | - click::utils::SmartConnect sc(responsePtr.data()); |
290 | - sc.connect(impl->sso.data(), &click::CredentialsService::credentialsFound, |
291 | - [=](const UbuntuOne::Token& token) { |
292 | - QString auth_header = token.signUrl(url.toString(), |
293 | - method.c_str()); |
294 | - qDebug() << "Signed URL:" << request->url().toString(); |
295 | - request->setRawHeader(AUTHORIZATION_HEADER.c_str(), auth_header.toUtf8()); |
296 | - impl->sso.clear(); |
297 | - doConnect(); |
298 | - }); |
299 | - sc.connect(impl->sso.data(), &click::CredentialsService::credentialsNotFound, |
300 | - [=]() { |
301 | - impl->sso.clear(); |
302 | - qWarning() << "Signing reuested but no credentials found. Using unsigned URL."; |
303 | - doConnect(); |
304 | - }); |
305 | - // TODO: Need to handle error signal once in CredentialsService. |
306 | - impl->sso->getCredentials(); |
307 | + auto token = impl->sso->getToken(); |
308 | + if (token.isValid()) { |
309 | + QString auth_header = token.signUrl(url.toString(), |
310 | + method.c_str()); |
311 | + qDebug() << "Signed URL:" << request->url().toString(); |
312 | + request->setRawHeader(AUTHORIZATION_HEADER.c_str(), auth_header.toUtf8()); |
313 | + } else { |
314 | + qWarning() << "Signing reuested but returned token is invalid."; |
315 | + } |
316 | + |
317 | + doConnect(); |
318 | } else { |
319 | + if (sign && impl->sso.isNull()) { |
320 | + qCritical() << "Unable to sign request without SSO object."; |
321 | + } |
322 | doConnect(); |
323 | } |
324 | |
325 | |
326 | === modified file 'libclickscope/click/webclient.h' |
327 | --- libclickscope/click/webclient.h 2016-03-30 14:14:14 +0000 |
328 | +++ libclickscope/click/webclient.h 2016-04-01 19:19:47 +0000 |
329 | @@ -121,7 +121,7 @@ |
330 | virtual QSharedPointer<Response> call( |
331 | const std::string& iri, |
332 | const std::string& method, |
333 | - bool sign = false, |
334 | + bool sign = true, |
335 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), |
336 | const std::string& data = "", |
337 | const CallParams& params = CallParams()); |
338 | |
339 | === modified file 'libclickscope/tests/mock_ubuntuone_credentials.h' |
340 | --- libclickscope/tests/mock_ubuntuone_credentials.h 2016-03-30 14:14:14 +0000 |
341 | +++ libclickscope/tests/mock_ubuntuone_credentials.h 2016-04-01 19:19:47 +0000 |
342 | @@ -1,5 +1,5 @@ |
343 | /* |
344 | - * Copyright (C) 2014 Canonical Ltd. |
345 | + * Copyright (C) 2014-2016 Canonical Ltd. |
346 | * |
347 | * This program is free software: you can redistribute it and/or modify it |
348 | * under the terms of the GNU General Public License version 3, as published |
349 | @@ -27,11 +27,11 @@ |
350 | * files in the program, then also delete it here. |
351 | */ |
352 | |
353 | +#include <token.h> |
354 | |
355 | class MockCredentialsService : public click::CredentialsService { |
356 | public: |
357 | - MOCK_METHOD0(getCredentials, |
358 | - void()); |
359 | - MOCK_METHOD0(invalidateCredentials, |
360 | - void()); |
361 | + MOCK_METHOD0(getToken, UbuntuOne::Token()); |
362 | + MOCK_METHOD0(getCredentials, void()); |
363 | + MOCK_METHOD0(invalidateCredentials, void()); |
364 | }; |
365 | |
366 | === modified file 'libclickscope/tests/mock_webclient.h' |
367 | --- libclickscope/tests/mock_webclient.h 2016-03-30 14:14:14 +0000 |
368 | +++ libclickscope/tests/mock_webclient.h 2016-04-01 19:19:47 +0000 |
369 | @@ -87,13 +87,13 @@ |
370 | QSharedPointer<click::web::Response> call( |
371 | const std::string& iri, |
372 | const click::web::CallParams& params=click::web::CallParams()) override { |
373 | - return callImpl(iri, "GET", false, |
374 | + return callImpl(iri, "GET", true, |
375 | std::map<std::string, std::string>(), "", params); |
376 | } |
377 | QSharedPointer<click::web::Response> call( |
378 | const std::string& iri, |
379 | const std::string& method, |
380 | - bool sign = false, |
381 | + bool sign = true, |
382 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), |
383 | const std::string& data = "", |
384 | const click::web::CallParams& params=click::web::CallParams()) override { |
385 | @@ -102,7 +102,6 @@ |
386 | |
387 | MOCK_METHOD1(has_header, bool(const std::string& header)); |
388 | MOCK_METHOD1(get_header, std::string(const std::string&header)); |
389 | - MOCK_METHOD0(invalidateCredentials, void()); |
390 | }; |
391 | |
392 | } |
393 | |
394 | === modified file 'libclickscope/tests/test_download_manager.cpp' |
395 | --- libclickscope/tests/test_download_manager.cpp 2016-03-30 14:14:14 +0000 |
396 | +++ libclickscope/tests/test_download_manager.cpp 2016-04-01 19:19:47 +0000 |
397 | @@ -63,6 +63,7 @@ |
398 | |
399 | virtual void SetUp() |
400 | { |
401 | + ssoPtr.reset(new MockCredentialsService()); |
402 | namPtr.reset(new MockNetworkAccessManager()); |
403 | clientPtr.reset(new NiceMock<MockClient>(namPtr)); |
404 | clientPtr->setCredentialsService(ssoPtr); |
405 | @@ -160,9 +161,6 @@ |
406 | LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
407 | auto response = responseForReply(reply.asSharedPtr()); |
408 | |
409 | - QSharedPointer<MockCredentialsService> sso(new MockCredentialsService()); |
410 | - dmPtr->setCredentialsService(sso); |
411 | - |
412 | EXPECT_CALL(reply.instance, errorString()) |
413 | .WillOnce(Return(QString("ERROR"))); |
414 | EXPECT_CALL(reply.instance, attribute(_)).WillOnce(Return(QVariant(401))); |
415 | @@ -172,7 +170,7 @@ |
416 | EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
417 | .Times(1) |
418 | .WillOnce(Return(response)); |
419 | - EXPECT_CALL(*(sso.data()), invalidateCredentials()); |
420 | + EXPECT_CALL(*ssoPtr, invalidateCredentials()); |
421 | EXPECT_CALL(*this, start_callback("ERROR (201)", |
422 | click::DownloadManager::Error::CredentialsError)).Times(1); |
423 | |
424 | |
425 | === modified file 'libclickscope/tests/test_index.cpp' |
426 | --- libclickscope/tests/test_index.cpp 2016-03-30 14:14:14 +0000 |
427 | +++ libclickscope/tests/test_index.cpp 2016-04-01 19:19:47 +0000 |
428 | @@ -1,5 +1,5 @@ |
429 | /* |
430 | - * Copyright (C) 2014 Canonical Ltd. |
431 | + * Copyright (C) 2014-2016 Canonical Ltd. |
432 | * |
433 | * This program is free software: you can redistribute it and/or modify it |
434 | * under the terms of the GNU General Public License version 3, as published |
435 | @@ -190,6 +190,18 @@ |
436 | indexPtr->departments("departments", [](const click::DepartmentList&, const click::HighlightList&, click::Index::Error, int) {}); |
437 | } |
438 | |
439 | +TEST_F(IndexTest, testDetailsSignsCall) |
440 | +{ |
441 | + LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
442 | + auto response = responseForReply(reply.asSharedPtr()); |
443 | + |
444 | + EXPECT_CALL(*clientPtr, callImpl(_, _, true, _, _, _)) |
445 | + .Times(1) |
446 | + .WillOnce(Return(response)); |
447 | + |
448 | + indexPtr->get_details("fake-app", [](const click::PackageDetails, click::Index::Error) {}); |
449 | +} |
450 | + |
451 | TEST_F(IndexTest, testSearchSendsRightPath) |
452 | { |
453 | LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
454 | |
455 | === modified file 'libclickscope/tests/test_reviews.cpp' |
456 | --- libclickscope/tests/test_reviews.cpp 2016-03-30 14:14:14 +0000 |
457 | +++ libclickscope/tests/test_reviews.cpp 2016-04-01 19:19:47 +0000 |
458 | @@ -150,6 +150,19 @@ |
459 | click::Reviews::Error) {}); |
460 | } |
461 | |
462 | +TEST_F(ReviewsTest, testFetchReviewsDoesNotSignCall) |
463 | +{ |
464 | + LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
465 | + auto response = responseForReply(reply.asSharedPtr()); |
466 | + |
467 | + EXPECT_CALL(*clientPtr, callImpl(_, _, false, _, _, _)) |
468 | + .Times(1) |
469 | + .WillOnce(Return(response)); |
470 | + |
471 | + reviewsPtr->fetch_reviews("", [](click::ReviewList, |
472 | + click::Reviews::Error) {}); |
473 | +} |
474 | + |
475 | TEST_F(ReviewsTest, testFetchReviewsSendsQueryAsParam) |
476 | { |
477 | LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
478 | |
479 | === modified file 'libclickscope/tests/test_webclient.cpp' |
480 | --- libclickscope/tests/test_webclient.cpp 2016-03-30 14:14:14 +0000 |
481 | +++ libclickscope/tests/test_webclient.cpp 2016-04-01 19:19:47 +0000 |
482 | @@ -221,11 +221,9 @@ |
483 | click::web::Client wc(namPtr); |
484 | wc.setCredentialsService(ssoPtr); |
485 | |
486 | - EXPECT_CALL(sso, getCredentials()).WillOnce(Invoke([&](){ |
487 | - UbuntuOne::Token token("token_key", "token_secret", |
488 | - "consumer_key", "consumer_secret"); |
489 | - sso.credentialsFound(token); |
490 | - })); |
491 | + EXPECT_CALL(sso, getToken()) |
492 | + .WillOnce(Return(UbuntuOne::Token("token_key", "token_secret", |
493 | + "consumer_key", "consumer_secret"))); |
494 | EXPECT_CALL(nam, sendCustomRequest(IsValidOAuthHeader(true), _, _)) |
495 | .Times(1) |
496 | .WillOnce(Return(replyPtr)); |
497 | @@ -271,9 +269,7 @@ |
498 | click::web::Client wc(namPtr); |
499 | wc.setCredentialsService(ssoPtr); |
500 | |
501 | - EXPECT_CALL(sso, getCredentials()).WillOnce(Invoke([&]() { |
502 | - sso.credentialsNotFound(); |
503 | - })); |
504 | + EXPECT_CALL(sso, getToken()).WillOnce(Return(UbuntuOne::Token())); |
505 | EXPECT_CALL(nam, sendCustomRequest(IsValidOAuthHeader(false), _, _)) |
506 | .Times(1) |
507 | .WillOnce(Return(replyPtr)); |
508 | |
509 | === modified file 'scope/clickapps/apps-scope.cpp' |
510 | --- scope/clickapps/apps-scope.cpp 2016-03-30 14:14:14 +0000 |
511 | +++ scope/clickapps/apps-scope.cpp 2016-04-01 19:19:47 +0000 |
512 | @@ -81,6 +81,8 @@ |
513 | static const int zero = 0; |
514 | auto emptyCb = [this]() |
515 | { |
516 | + sso.reset(new click::CredentialsService()); |
517 | + client->setCredentialsService(sso); |
518 | dm.reset(Ubuntu::DownloadManager::Manager::createSessionManager()); |
519 | }; |
520 | |
521 | |
522 | === modified file 'scope/clickapps/apps-scope.h' |
523 | --- scope/clickapps/apps-scope.h 2016-03-30 14:14:14 +0000 |
524 | +++ scope/clickapps/apps-scope.h 2016-04-01 19:19:47 +0000 |
525 | @@ -71,6 +71,7 @@ |
526 | QSharedPointer<click::Index> index; |
527 | QSharedPointer<pay::Package> pay_package; |
528 | QSharedPointer<Ubuntu::DownloadManager::Manager> dm; |
529 | + QSharedPointer<click::CredentialsService> sso; |
530 | std::shared_ptr<click::DepartmentsDb> depts_db; |
531 | |
532 | std::string installApplication(unity::scopes::Result const& result); |
533 | |
534 | === modified file 'scope/clickstore/store-scope.cpp' |
535 | --- scope/clickstore/store-scope.cpp 2016-03-30 14:14:14 +0000 |
536 | +++ scope/clickstore/store-scope.cpp 2016-04-01 19:19:47 +0000 |
537 | @@ -83,6 +83,8 @@ |
538 | static const int zero = 0; |
539 | auto emptyCb = [this]() |
540 | { |
541 | + sso.reset(new click::CredentialsService()); |
542 | + client->setCredentialsService(sso); |
543 | dm.reset(Ubuntu::DownloadManager::Manager::createSessionManager()); |
544 | }; |
545 | |
546 | |
547 | === modified file 'scope/clickstore/store-scope.h' |
548 | --- scope/clickstore/store-scope.h 2016-03-30 14:14:14 +0000 |
549 | +++ scope/clickstore/store-scope.h 2016-04-01 19:19:47 +0000 |
550 | @@ -74,6 +74,7 @@ |
551 | QSharedPointer<click::Index> index; |
552 | QSharedPointer<pay::Package> pay_package; |
553 | QSharedPointer<Ubuntu::DownloadManager::Manager> dm; |
554 | + QSharedPointer<click::CredentialsService> sso; |
555 | std::shared_ptr<click::DepartmentLookup> depts; |
556 | std::shared_ptr<click::HighlightList> highlights; |
557 | std::shared_ptr<click::DepartmentsDb> depts_db; |