Merge lp:~dobey/unity-scope-click/rm-store-pay into lp:unity-scope-click
- rm-store-pay
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Charles Kerr |
Approved revision: | 496 |
Merged at revision: | 493 |
Proposed branch: | lp:~dobey/unity-scope-click/rm-store-pay |
Merge into: | lp:unity-scope-click |
Diff against target: |
4115 lines (+58/-3259) 34 files modified
CMakeLists.txt (+4/-8) bin/CMakeLists.txt (+1/-1) bin/enable-purchases (+0/-44) data/CMakeLists.txt (+0/-5) data/update_schema.sh (+0/-1) debian/control (+0/-2) debian/unity-scope-click.install (+0/-3) libclickscope/click/CMakeLists.txt (+0/-2) libclickscope/click/pay.cpp (+0/-317) libclickscope/click/pay.h (+0/-125) libclickscope/click/preview.cpp (+17/-207) libclickscope/click/preview.h (+2/-46) libclickscope/tests/CMakeLists.txt (+0/-5) libclickscope/tests/integration/CMakeLists.txt (+0/-32) libclickscope/tests/integration/departmentsdb_integration.cpp (+0/-137) libclickscope/tests/integration/webclient_integration.cpp (+0/-128) libclickscope/tests/mock_pay.h (+0/-106) libclickscope/tests/test_pay.cpp (+0/-266) libclickscope/tests/test_preview.cpp (+16/-167) scope/CMakeLists.txt (+0/-1) scope/clickapps/apps-scope.cpp (+1/-2) scope/clickapps/apps-scope.h (+0/-2) scope/clickstore/CMakeLists.txt (+0/-43) scope/clickstore/com.canonical.scopes.clickstore.ini.in.in (+0/-10) scope/clickstore/store-query.cpp (+0/-645) scope/clickstore/store-query.h (+0/-117) scope/clickstore/store-scope.cpp (+0/-237) scope/clickstore/store-scope.h (+0/-91) scope/tests/CMakeLists.txt (+0/-47) scope/tests/fake_launcher/CMakeLists.txt (+0/-14) scope/tests/fake_launcher/fake_launcher.cpp (+0/-118) scope/tests/fake_launcher/fake_launcher.h (+0/-116) scope/tests/test_query.cpp (+17/-36) scope/tests/test_store_scope.cpp (+0/-178) |
To merge this branch: | bzr merge lp:~dobey/unity-scope-click/rm-store-pay |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Charles Kerr (community) | Approve | ||
unity-api-1-bot | continuous-integration | Needs Fixing | |
Review via email: mp+309179@code.launchpad.net |
Commit message
Remove the store scope code and libpay usage.
Description of the change
unity-api-1-bot (unity-api-1-bot) wrote : | # |
unity-api-1-bot (unity-api-1-bot) wrote : | # |
PASSED: Continuous integration, rev:495
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
unity-api-1-bot (unity-api-1-bot) wrote : | # |
FAILED: Continuous integration, rev:496
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Charles Kerr (charlesk) wrote : | # |
LGTM. Goodbye libpay.
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-09-29 20:38:00 +0000 |
3 | +++ CMakeLists.txt 2016-10-25 13:13:28 +0000 |
4 | @@ -14,8 +14,6 @@ |
5 | |
6 | include(GNUInstallDirs) |
7 | |
8 | -set(STORE_LIB_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/unity-scopes/clickstore/) |
9 | -set(STORE_DATA_DIR ${CMAKE_INSTALL_FULL_DATADIR}/unity/scopes/clickstore/) |
10 | set(APPS_LIB_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/unity-scopes/clickapps/) |
11 | set(APPS_DATA_DIR ${CMAKE_INSTALL_FULL_DATADIR}/unity/scopes/clickapps/) |
12 | |
13 | @@ -24,7 +22,7 @@ |
14 | include(UseGSettings) |
15 | find_package (PkgConfig REQUIRED) |
16 | |
17 | -pkg_check_modules(UAL REQUIRED ubuntu-app-launch-2>=0.9) |
18 | +pkg_check_modules(UAL REQUIRED ubuntu-app-launch-2>=0.9 gobject-2.0) |
19 | add_definitions(${UAL_CFLAGS} ${UAL_CFLAGS_OTHER}) |
20 | |
21 | pkg_check_modules(CLICK REQUIRED click-0.4) |
22 | @@ -45,9 +43,7 @@ |
23 | SET (SCOPE_LIB_VERSION 0.2.0) |
24 | SET (SCOPE_LIB_SOVERSION 0) |
25 | SET (SCOPE_LIB_API_VERSION 2.0) |
26 | -SET (STORE_LIB_UNVERSIONED com.canonical.scopes.clickstore) |
27 | SET (SCOPE_LIB_NAME clickscope) |
28 | -SET (STORE_LIB_NAME ${STORE_LIB_UNVERSIONED}-${SCOPE_LIB_API_VERSION}) |
29 | SET (APPS_LIB_UNVERSIONED scope) |
30 | SET (APPS_LIB_NAME ${APPS_LIB_UNVERSIONED}-${SCOPE_LIB_API_VERSION}) |
31 | |
32 | @@ -68,14 +64,14 @@ |
33 | add_subdirectory(tools) |
34 | |
35 | include(EnableCoverageReport) |
36 | -ENABLE_COVERAGE_REPORT(TARGETS ${SCOPE_LIB_NAME} ${STORE_LIB_UNVERSIONED} ${APPS_LIB_UNVERSIONED} |
37 | - TESTS click_scope_integration_tests libclick-scope-tests fake_launcher click-scope-tests apps-scope-tests init-departments |
38 | +ENABLE_COVERAGE_REPORT(TARGETS ${SCOPE_LIB_NAME} ${APPS_LIB_UNVERSIONED} |
39 | + TESTS libclick-scope-tests apps-scope-tests init-departments |
40 | FILTER /usr/include ${CMAKE_BINARY_DIR}/* |
41 | ) |
42 | |
43 | # Custom targets for the tests |
44 | add_custom_target (test |
45 | - DEPENDS test-click-scope test-apps-scope test-libclickscope test-integration-harness |
46 | + DEPENDS test-apps-scope test-libclickscope test-integration-harness |
47 | ) |
48 | |
49 | add_custom_target (test-disabled |
50 | |
51 | === modified file 'bin/CMakeLists.txt' |
52 | --- bin/CMakeLists.txt 2014-08-14 14:59:57 +0000 |
53 | +++ bin/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
54 | @@ -1,1 +1,1 @@ |
55 | -install(PROGRAMS install-helper enable-purchases DESTINATION lib/unity-scope-click/) |
56 | +install(PROGRAMS install-helper DESTINATION lib/unity-scope-click/) |
57 | |
58 | === removed file 'bin/enable-purchases' |
59 | --- bin/enable-purchases 2014-08-14 14:59:57 +0000 |
60 | +++ bin/enable-purchases 1970-01-01 00:00:00 +0000 |
61 | @@ -1,44 +0,0 @@ |
62 | -#!/bin/sh |
63 | -# |
64 | -# Copyright (C) 2014 Canonical Ltd. |
65 | -# |
66 | -# This program is free software: you can redistribute it and/or modify it |
67 | -# under the terms of the GNU General Public License version 3, as published |
68 | -# by the Free Software Foundation. |
69 | -# |
70 | -# This program is distributed in the hope that it will be useful, but |
71 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
72 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
73 | -# PURPOSE. See the GNU General Public License for more details. |
74 | -# |
75 | -# You should have received a copy of the GNU General Public License along |
76 | -# with this program. If not, see <http://www.gnu.org/licenses/>. |
77 | -# |
78 | -# In addition, as a special exception, the copyright holders give |
79 | -# permission to link the code of portions of this program with the |
80 | -# OpenSSL library under certain conditions as described in each |
81 | -# individual source file, and distribute linked combinations |
82 | -# including the two. |
83 | -# You must obey the GNU General Public License in all respects |
84 | -# for all of the code used other than OpenSSL. If you modify |
85 | -# file(s) with this exception, you may extend this exception to your |
86 | -# version of the file(s), but you are not obligated to do so. If you |
87 | -# do not wish to do so, delete this exception statement from your |
88 | -# version. If you delete this exception statement from all source |
89 | -# files in the program, then also delete it here. |
90 | -# |
91 | -set -e |
92 | - |
93 | -CLICK_STORE_ENABLE_PURCHASES=1 |
94 | - |
95 | -/sbin/initctl set-env --global CLICK_STORE_ENABLE_PURCHASES=$CLICK_STORE_ENABLE_PURCHASES |
96 | - |
97 | -gdbus call --session \ |
98 | - --dest org.freedesktop.DBus \ |
99 | - --object-path / \ |
100 | - --method org.freedesktop.DBus.UpdateActivationEnvironment \ |
101 | - "[{'CLICK_STORE_ENABLE_PURCHASES', '$CLICK_STORE_ENABLE_PURCHASES'}]" |
102 | - |
103 | -/sbin/restart scope-registry |
104 | - |
105 | -echo "Purchases enabled and scope-registry restarted." |
106 | |
107 | === modified file 'data/CMakeLists.txt' |
108 | --- data/CMakeLists.txt 2015-03-31 16:11:35 +0000 |
109 | +++ data/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
110 | @@ -6,11 +6,6 @@ |
111 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DEPARTMENTS_UPSTART_JOB} DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions) |
112 | |
113 | install( |
114 | - FILES clickscope-screenshot.jpg ubuntu-store-scope.png store-scope-icon.svg |
115 | - DESTINATION "${STORE_DATA_DIR}" |
116 | -) |
117 | - |
118 | -install( |
119 | FILES clickscope-screenshot.jpg apps-scope.png ubuntu-logo.png |
120 | DESTINATION "${APPS_DATA_DIR}" |
121 | ) |
122 | |
123 | === modified file 'data/update_schema.sh' |
124 | --- data/update_schema.sh 2015-01-23 01:37:54 +0000 |
125 | +++ data/update_schema.sh 2016-10-25 13:13:28 +0000 |
126 | @@ -299,7 +299,6 @@ |
127 | INSERT INTO "pkgmap" VALUES('com.zeptolab.cuttherope.free','games'); |
128 | INSERT INTO "pkgmap" VALUES('com.ubuntu.weather','weather'); |
129 | INSERT INTO "pkgmap" VALUES('com.ubuntu.clock','accessories'); |
130 | - INSERT INTO "pkgmap" VALUES('com.canonical.payui','accessories'); |
131 | INSERT INTO "pkgmap" VALUES('com.ubuntu.music','music-audio'); |
132 | INSERT INTO "pkgmap" VALUES('com.ubuntu.developer.webapps.webapp-ebay','shopping'); |
133 | INSERT INTO "pkgmap" VALUES('com.ubuntu.developer.webapps.webapp-gmail','communication'); |
134 | |
135 | === modified file 'debian/control' |
136 | --- debian/control 2016-09-29 20:38:00 +0000 |
137 | +++ debian/control 2016-10-25 13:13:28 +0000 |
138 | @@ -15,7 +15,6 @@ |
139 | libclick-0.4-dev, |
140 | libglib2.0-dev (>= 2.32), |
141 | libjsoncpp-dev, |
142 | - libpay2-dev (>= 2.0.0+15.04.20150701), |
143 | libubuntu-app-launch2-dev (>= 0.9), |
144 | libubuntu-download-manager-client-dev (>= 0.3+14.10.20140430-0ubuntu1), |
145 | libubuntu-download-manager-common-dev (>= 0.3+14.10.20140430-0ubuntu1), |
146 | @@ -45,7 +44,6 @@ |
147 | libsqlite3-0 (>= 3.8.5), |
148 | packagekit, |
149 | packagekit-tools, |
150 | - pay-service, |
151 | ubuntu-app-launch-tools, |
152 | ubuntu-download-manager, |
153 | upstart, |
154 | |
155 | === modified file 'debian/unity-scope-click.install' |
156 | --- debian/unity-scope-click.install 2014-08-19 15:56:29 +0000 |
157 | +++ debian/unity-scope-click.install 2016-10-25 13:13:28 +0000 |
158 | @@ -1,8 +1,5 @@ |
159 | usr/lib/*/unity-scopes/* |
160 | usr/lib/unity-scope-click/* |
161 | -usr/share/unity/scopes/clickstore/*jpg |
162 | -usr/share/unity/scopes/clickstore/*png |
163 | -usr/share/unity/scopes/clickstore/*svg |
164 | usr/share/unity/scopes/clickapps/*jpg |
165 | usr/share/unity/scopes/clickapps/*png |
166 | usr/share/glib-2.0/schemas/* |
167 | |
168 | === modified file 'libclickscope/click/CMakeLists.txt' |
169 | --- libclickscope/click/CMakeLists.txt 2016-08-12 15:09:24 +0000 |
170 | +++ libclickscope/click/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
171 | @@ -4,7 +4,6 @@ |
172 | find_package (Qt5Sql REQUIRED) |
173 | pkg_check_modules(JSON_CPP REQUIRED jsoncpp) |
174 | pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt) |
175 | -pkg_check_modules(LIBPAY REQUIRED pay-2) |
176 | |
177 | add_definitions( |
178 | -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\" |
179 | @@ -25,7 +24,6 @@ |
180 | launcher.cpp |
181 | network_access_manager.cpp |
182 | package.cpp |
183 | - pay.cpp |
184 | preview.cpp |
185 | reviews.cpp |
186 | qtbridge.cpp |
187 | |
188 | === removed file 'libclickscope/click/pay.cpp' |
189 | --- libclickscope/click/pay.cpp 2016-05-10 13:42:12 +0000 |
190 | +++ libclickscope/click/pay.cpp 1970-01-01 00:00:00 +0000 |
191 | @@ -1,317 +0,0 @@ |
192 | -/* |
193 | - * Copyright (C) 2014 Canonical Ltd. |
194 | - * |
195 | - * This program is free software: you can redistribute it and/or modify it |
196 | - * under the terms of the GNU General Public License version 3, as published |
197 | - * by the Free Software Foundation. |
198 | - * |
199 | - * This program is distributed in the hope that it will be useful, but |
200 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
201 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
202 | - * PURPOSE. See the GNU General Public License for more details. |
203 | - * |
204 | - * You should have received a copy of the GNU General Public License along |
205 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
206 | - * |
207 | - * In addition, as a special exception, the copyright holders give |
208 | - * permission to link the code of portions of this program with the |
209 | - * OpenSSL library under certain conditions as described in each |
210 | - * individual source file, and distribute linked combinations |
211 | - * including the two. |
212 | - * You must obey the GNU General Public License in all respects |
213 | - * for all of the code used other than OpenSSL. If you modify |
214 | - * file(s) with this exception, you may extend this exception to your |
215 | - * version of the file(s), but you are not obligated to do so. If you |
216 | - * do not wish to do so, delete this exception statement from your |
217 | - * version. If you delete this exception statement from all source |
218 | - * files in the program, then also delete it here. |
219 | - */ |
220 | - |
221 | -#include "pay.h" |
222 | - |
223 | -#include <future> |
224 | - |
225 | -#include <json/reader.h> |
226 | -#include <json/value.h> |
227 | - |
228 | -#include <glib.h> |
229 | -#include <libpay/pay-package.h> |
230 | -#include <unistd.h> |
231 | - |
232 | -#include <QDebug> |
233 | - |
234 | -namespace json = Json; |
235 | - |
236 | - |
237 | -struct pay::Package::Private |
238 | -{ |
239 | - Private() |
240 | - { |
241 | - } |
242 | - |
243 | - virtual ~Private() |
244 | - { |
245 | - } |
246 | - |
247 | - PayPackage *pay_package; |
248 | -}; |
249 | - |
250 | - |
251 | -static void pay_verification_observer(PayPackage*, |
252 | - const char* item_id, |
253 | - PayPackageItemStatus status, |
254 | - void* user_data) |
255 | -{ |
256 | - pay::Package* p = static_cast<pay::Package*>(user_data); |
257 | - std::string callback_id = std::string{item_id} + pay::APPENDAGE_VERIFY; |
258 | - if (p->callbacks.count(callback_id) == 0) { |
259 | - qDebug() << "Verify observer called with no callback:" << item_id; |
260 | - return; |
261 | - } |
262 | - |
263 | - switch (status) { |
264 | - case PAY_PACKAGE_ITEM_STATUS_PURCHASED: |
265 | - p->callbacks[callback_id](item_id, true); |
266 | - break; |
267 | - case PAY_PACKAGE_ITEM_STATUS_NOT_PURCHASED: |
268 | - p->callbacks[callback_id](item_id, false); |
269 | - break; |
270 | - default: |
271 | - break; |
272 | - } |
273 | -} |
274 | - |
275 | -static void pay_refund_observer(PayPackage*, |
276 | - const char* item_id, |
277 | - PayPackageRefundStatus status, |
278 | - void* user_data) |
279 | -{ |
280 | - pay::Package* p = static_cast<pay::Package*>(user_data); |
281 | - std::string callback_id = std::string{item_id} + pay::APPENDAGE_REFUND; |
282 | - if (p->callbacks.count(callback_id) == 0) { |
283 | - qDebug() << "Refund observer called with no callback:" << item_id; |
284 | - return; |
285 | - } |
286 | - |
287 | - switch (status) { |
288 | - case PAY_PACKAGE_REFUND_STATUS_NOT_PURCHASED: |
289 | - p->callbacks[callback_id](item_id, true); |
290 | - break; |
291 | - case PAY_PACKAGE_REFUND_STATUS_NOT_REFUNDABLE: |
292 | - p->callbacks[callback_id](item_id, false); |
293 | - default: |
294 | - break; |
295 | - } |
296 | -} |
297 | - |
298 | - |
299 | -namespace pay { |
300 | - |
301 | -bool operator==(const Purchase& lhs, const Purchase& rhs) { |
302 | - return lhs.name == rhs.name; |
303 | -} |
304 | - |
305 | -Package::Package() : impl(new Private()) |
306 | -{ |
307 | -} |
308 | - |
309 | -Package::Package(const QSharedPointer<click::web::Client>& client) : |
310 | - impl(new Private()), |
311 | - client(client) |
312 | -{ |
313 | -} |
314 | - |
315 | -Package::~Package() |
316 | -{ |
317 | - if (running) { |
318 | - pay_package_item_observer_uninstall(impl->pay_package, |
319 | - pay_verification_observer, |
320 | - this); |
321 | - pay_package_delete(impl->pay_package); |
322 | - } |
323 | -} |
324 | - |
325 | -bool Package::refund(const std::string& pkg_name) |
326 | -{ |
327 | - std::promise<bool> result_promise; |
328 | - std::future<bool> result_future = result_promise.get_future(); |
329 | - bool result; |
330 | - |
331 | - std::string callback_id = pkg_name + pay::APPENDAGE_REFUND; |
332 | - if (callbacks.count(callback_id) == 0) { |
333 | - callbacks[callback_id] = [pkg_name, |
334 | - this, callback_id, |
335 | - &result_promise](const std::string& item_id, |
336 | - bool succeeded) { |
337 | - if (item_id == pkg_name) { |
338 | - try { |
339 | - result_promise.set_value(succeeded); |
340 | - callbacks.erase(callback_id); |
341 | - } catch (std::future_error) { |
342 | - // Just log this to avoid crashing, as it seems that |
343 | - // sometimes this callback may be called more than once. |
344 | - qDebug() << "Refund callback called again for:" << item_id.c_str(); |
345 | - } |
346 | - } |
347 | - }; |
348 | - qDebug() << "Attempting to cancel purchase of " << pkg_name.c_str(); |
349 | - pay_package_refund(pkg_name); |
350 | - |
351 | - result = result_future.get(); |
352 | - |
353 | - return result; |
354 | - } |
355 | - return false; |
356 | -} |
357 | - |
358 | -bool Package::verify(const std::string& pkg_name) |
359 | -{ |
360 | - std::promise<bool> result_promise; |
361 | - std::future<bool> result_future = result_promise.get_future(); |
362 | - bool result; |
363 | - |
364 | - std::string callback_id = pkg_name + pay::APPENDAGE_VERIFY; |
365 | - if (callbacks.count(callback_id) == 0) { |
366 | - callbacks[callback_id] = [pkg_name, |
367 | - &result_promise](const std::string& item_id, |
368 | - bool purchased) { |
369 | - if (item_id == pkg_name) { |
370 | - try { |
371 | - result_promise.set_value(purchased); |
372 | - } catch (std::future_error) { |
373 | - // Just log this to avoid crashing, as it seems that |
374 | - // sometimes this callback may be called more than once. |
375 | - qDebug() << "Callback called again for:" << item_id.c_str(); |
376 | - } |
377 | - } |
378 | - }; |
379 | - qDebug() << "Checking if " << pkg_name.c_str() << " was purchased."; |
380 | - pay_package_verify(pkg_name); |
381 | - |
382 | - result = result_future.get(); |
383 | - |
384 | - callbacks.erase(callback_id); |
385 | - |
386 | - return result; |
387 | - } |
388 | - return false; |
389 | -} |
390 | - |
391 | -bool Package::is_refundable(const std::string& pkg_name) |
392 | -{ |
393 | - if (!running) { |
394 | - setup_pay_service(); |
395 | - } |
396 | - |
397 | - if (verify(pkg_name)) { |
398 | - // No Hondas, why racing? Wait for it… |
399 | - usleep(10000); |
400 | - |
401 | - return pay_package_item_is_refundable(impl->pay_package, |
402 | - pkg_name.c_str()) == 0 ? false : true; |
403 | - } |
404 | - // If verify() returned false, then it's not purchased. |
405 | - return false; |
406 | -} |
407 | - |
408 | -time_t parse_timestamp(json::Value v) |
409 | -{ |
410 | - if (v.isNull()) { |
411 | - return 0; |
412 | - } |
413 | - |
414 | - QDateTime when = QDateTime::fromString(QString::fromStdString(v.asString()), Qt::ISODate); |
415 | - when.setTimeSpec(Qt::OffsetFromUTC); |
416 | - |
417 | - return when.toTime_t(); |
418 | -} |
419 | - |
420 | -click::web::Cancellable Package::get_purchases(std::function<void(const PurchaseSet&)> callback) |
421 | -{ |
422 | - QSharedPointer<click::web::Response> response = client->call |
423 | - (get_base_url() + pay::API_ROOT + pay::PURCHASES_API_PATH, "GET", true); |
424 | - |
425 | - QObject::connect(response.data(), &click::web::Response::finished, |
426 | - [=](QString reply) { |
427 | - PurchaseSet purchases; |
428 | - json::Reader reader; |
429 | - json::Value root; |
430 | - |
431 | - if (reader.parse(reply.toUtf8().constData(), root)) { |
432 | - for (uint i = 0; i < root.size(); i++) { |
433 | - const json::Value item = root[i]; |
434 | - if (item[JsonKeys::state].asString() == PURCHASE_STATE_COMPLETE) { |
435 | - auto package_name = item[JsonKeys::package_name].asString(); |
436 | - qDebug() << "parsing:" << package_name.c_str(); |
437 | - auto refundable_until_value = item[JsonKeys::refundable_until]; |
438 | - qDebug() << "refundable until:" << refundable_until_value.asString().c_str(); |
439 | - auto refundable_parsed = parse_timestamp(refundable_until_value); |
440 | - qDebug() << "parsed:" << refundable_parsed; |
441 | - Purchase p(package_name, refundable_parsed); |
442 | - purchases.insert(p); |
443 | - } |
444 | - } |
445 | - } |
446 | - callback(purchases); |
447 | - }); |
448 | - QObject::connect(response.data(), &click::web::Response::error, |
449 | - [=](QString) { |
450 | - qWarning() << "Network error getting purchases."; |
451 | - callback(PurchaseSet()); |
452 | - }); |
453 | - |
454 | - return click::web::Cancellable(response); |
455 | -} |
456 | - |
457 | -std::string Package::get_base_url() |
458 | -{ |
459 | - const char *env_url = getenv(pay::BASE_URL_ENVVAR); |
460 | - if (env_url != NULL) { |
461 | - return env_url; |
462 | - } |
463 | - return pay::BASE_URL; |
464 | -} |
465 | - |
466 | -void Package::setup_pay_service() |
467 | -{ |
468 | - PayPackage* newpkg = pay_package_new(Package::NAME); |
469 | - impl->pay_package = newpkg; |
470 | - |
471 | - qDebug() << "installing observers"; |
472 | - pay_package_item_observer_install(impl->pay_package, |
473 | - pay_verification_observer, |
474 | - this); |
475 | - pay_package_refund_observer_install(impl->pay_package, |
476 | - pay_refund_observer, |
477 | - this); |
478 | - |
479 | - running = true; |
480 | -} |
481 | - |
482 | -void Package::pay_package_refund(const std::string& pkg_name) |
483 | -{ |
484 | - if (!running) { |
485 | - setup_pay_service(); |
486 | - } |
487 | - |
488 | - if (callbacks.count(pkg_name + pay::APPENDAGE_REFUND) == 0) { |
489 | - return; |
490 | - } |
491 | - |
492 | - pay_package_item_start_refund(impl->pay_package, pkg_name.c_str()); |
493 | -} |
494 | - |
495 | -void Package::pay_package_verify(const std::string& pkg_name) |
496 | -{ |
497 | - if (!running) { |
498 | - setup_pay_service(); |
499 | - } |
500 | - |
501 | - if (callbacks.count(pkg_name + pay::APPENDAGE_VERIFY) == 0) { |
502 | - return; |
503 | - } |
504 | - |
505 | - pay_package_item_start_verification(impl->pay_package, pkg_name.c_str()); |
506 | -} |
507 | - |
508 | -} // namespace pay |
509 | |
510 | === removed file 'libclickscope/click/pay.h' |
511 | --- libclickscope/click/pay.h 2015-11-24 18:23:23 +0000 |
512 | +++ libclickscope/click/pay.h 1970-01-01 00:00:00 +0000 |
513 | @@ -1,125 +0,0 @@ |
514 | -/* |
515 | - * Copyright (C) 2014 Canonical Ltd. |
516 | - * |
517 | - * This program is free software: you can redistribute it and/or modify it |
518 | - * under the terms of the GNU General Public License version 3, as published |
519 | - * by the Free Software Foundation. |
520 | - * |
521 | - * This program is distributed in the hope that it will be useful, but |
522 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
523 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
524 | - * PURPOSE. See the GNU General Public License for more details. |
525 | - * |
526 | - * You should have received a copy of the GNU General Public License along |
527 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
528 | - * |
529 | - * In addition, as a special exception, the copyright holders give |
530 | - * permission to link the code of portions of this program with the |
531 | - * OpenSSL library under certain conditions as described in each |
532 | - * individual source file, and distribute linked combinations |
533 | - * including the two. |
534 | - * You must obey the GNU General Public License in all respects |
535 | - * for all of the code used other than OpenSSL. If you modify |
536 | - * file(s) with this exception, you may extend this exception to your |
537 | - * version of the file(s), but you are not obligated to do so. If you |
538 | - * do not wish to do so, delete this exception statement from your |
539 | - * version. If you delete this exception statement from all source |
540 | - * files in the program, then also delete it here. |
541 | - */ |
542 | - |
543 | -#ifndef _PAY_H_ |
544 | -#define _PAY_H_ |
545 | - |
546 | -#include <click/webclient.h> |
547 | - |
548 | -#include <ctime> |
549 | -#include <map> |
550 | -#include <memory> |
551 | -#include <unordered_set> |
552 | - |
553 | - |
554 | -namespace pay |
555 | -{ |
556 | - constexpr static const char* APPENDAGE_VERIFY{":verify"}; |
557 | - constexpr static const char* APPENDAGE_REFUND{":refund"}; |
558 | - |
559 | - |
560 | - struct Purchase |
561 | - { |
562 | - std::string name; |
563 | - time_t refundable_until; |
564 | - |
565 | - Purchase() = default; |
566 | - Purchase(const std::string &name) : name(name), refundable_until(0) |
567 | - { |
568 | - } |
569 | - |
570 | - Purchase(const std::string& name, time_t refundable_until) : |
571 | - name(name), refundable_until(refundable_until) |
572 | - { |
573 | - } |
574 | - |
575 | - struct hash_name { |
576 | - public : |
577 | - size_t operator()(const Purchase &purchase ) const |
578 | - { |
579 | - return std::hash<std::string>()(purchase.name); |
580 | - } |
581 | - }; |
582 | - |
583 | - }; |
584 | - |
585 | - bool operator==(const Purchase& lhs, const Purchase& rhs); |
586 | - |
587 | - typedef std::unordered_set<Purchase, Purchase::hash_name> PurchaseSet; |
588 | - |
589 | - typedef std::function<void(const std::string& item_id, |
590 | - bool status)> StatusFunction; |
591 | - |
592 | - constexpr static const char* BASE_URL_ENVVAR{"PAY_BASE_URL"}; |
593 | - constexpr static const char* BASE_URL{"https://software-center.ubuntu.com"}; |
594 | - constexpr static const char* API_ROOT{"/api/2.0/click/"}; |
595 | - constexpr static const char* PURCHASES_API_PATH{"purchases/"}; |
596 | - constexpr static const char* PURCHASE_STATE_COMPLETE{"Complete"}; |
597 | - |
598 | - struct JsonKeys |
599 | - { |
600 | - JsonKeys() = delete; |
601 | - |
602 | - constexpr static const char* package_name{"package_name"}; |
603 | - constexpr static const char* refundable_until{"refundable_until"}; |
604 | - constexpr static const char* state{"state"}; |
605 | - }; |
606 | - |
607 | - class Package |
608 | - { |
609 | - public: |
610 | - constexpr static const char* NAME{"click-scope"}; |
611 | - |
612 | - Package(); |
613 | - Package(const QSharedPointer<click::web::Client>& client); |
614 | - virtual ~Package(); |
615 | - |
616 | - virtual bool refund(const std::string& pkg_name); |
617 | - virtual bool verify(const std::string& pkg_name); |
618 | - virtual bool is_refundable(const std::string& pkg_name); |
619 | - virtual click::web::Cancellable get_purchases(std::function<void(const PurchaseSet& purchased_apps)> callback); |
620 | - static std::string get_base_url(); |
621 | - |
622 | - protected: |
623 | - virtual void setup_pay_service(); |
624 | - virtual void pay_package_refund(const std::string& pkg_name); |
625 | - virtual void pay_package_verify(const std::string& pkg_name); |
626 | - |
627 | - struct Private; |
628 | - QScopedPointer<pay::Package::Private> impl; |
629 | - |
630 | - bool running = false; |
631 | - QSharedPointer<click::web::Client> client; |
632 | - public: |
633 | - std::map<std::string, StatusFunction> callbacks; |
634 | - }; |
635 | - |
636 | -} //namespace pay |
637 | - |
638 | -#endif // _PAY_H_ |
639 | |
640 | === modified file 'libclickscope/click/preview.cpp' |
641 | --- libclickscope/click/preview.cpp 2016-08-15 13:34:03 +0000 |
642 | +++ libclickscope/click/preview.cpp 2016-10-25 13:13:28 +0000 |
643 | @@ -36,7 +36,6 @@ |
644 | #include <click/dbus_constants.h> |
645 | #include <click/departments-db.h> |
646 | #include <click/utils.h> |
647 | -#include <click/pay.h> |
648 | |
649 | #include <boost/algorithm/string/replace.hpp> |
650 | |
651 | @@ -173,11 +172,10 @@ |
652 | } |
653 | |
654 | void Preview::choose_strategy(const QSharedPointer<web::Client> &client, |
655 | - const QSharedPointer<pay::Package>& ppackage, |
656 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
657 | std::shared_ptr<click::DepartmentsDb> depts) |
658 | { |
659 | - strategy.reset(build_strategy(result, metadata, client, ppackage, manager, depts)); |
660 | + strategy.reset(build_strategy(result, metadata, client, manager, depts)); |
661 | } |
662 | |
663 | PreviewStrategy* Preview::build_installing(const std::string& download_url, |
664 | @@ -194,7 +192,6 @@ |
665 | PreviewStrategy* Preview::build_strategy(const unity::scopes::Result &result, |
666 | const unity::scopes::ActionMetadata &metadata, |
667 | const QSharedPointer<web::Client> &client, |
668 | - const QSharedPointer<pay::Package>& ppackage, |
669 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
670 | std::shared_ptr<click::DepartmentsDb> depts) |
671 | { |
672 | @@ -210,7 +207,7 @@ |
673 | << " and close_preview=" |
674 | << metadict.count(click::Preview::Actions::SHOW_INSTALLED); |
675 | |
676 | - return new InstalledPreview(result, metadata, client, ppackage, depts); |
677 | + return new InstalledPreview(result, metadata, client, depts); |
678 | } else if (metadict.count("action_id") != 0 && metadict.count("download_url") != 0) { |
679 | std::string action_id = metadict["action_id"].get_string(); |
680 | std::string download_url = metadict["download_url"].get_string(); |
681 | @@ -220,27 +217,19 @@ |
682 | } else { |
683 | qWarning() << "unexpected action id " << QString::fromStdString(action_id) |
684 | << " given with download_url" << QString::fromStdString(download_url); |
685 | - return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
686 | + return new UninstalledPreview(result, metadata, client, depts, manager); |
687 | } |
688 | - } else if (metadict.count(click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED) != 0) { |
689 | - return new CancelPurchasePreview(result, false); |
690 | - } else if (metadict.count(click::Preview::Actions::CANCEL_PURCHASE_INSTALLED) != 0) { |
691 | - return new CancelPurchasePreview(result, true); |
692 | } else if (metadict.count(click::Preview::Actions::UNINSTALL_CLICK) != 0) { |
693 | return new UninstallConfirmationPreview(result); |
694 | } else if (metadict.count(click::Preview::Actions::CONFIRM_UNINSTALL) != 0) { |
695 | - return new UninstallingPreview(result, metadata, client, manager, ppackage); |
696 | - } else if (metadict.count(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED) != 0) { |
697 | - return new CancellingPurchasePreview(result, metadata, client, ppackage, manager, false); |
698 | - } else if (metadict.count(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED) != 0) { |
699 | - return new CancellingPurchasePreview(result, metadata, client, ppackage, manager, true); |
700 | + return new UninstallingPreview(result, metadata, client, manager); |
701 | } else if (metadict.count(click::Preview::Actions::RATED) != 0) { |
702 | - return new InstalledPreview(result, metadata, client, ppackage, depts); |
703 | + return new InstalledPreview(result, metadata, client, depts); |
704 | } else if (metadict.count(click::Preview::Actions::SHOW_UNINSTALLED) != 0) { |
705 | - return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
706 | + return new UninstalledPreview(result, metadata, client, depts, manager); |
707 | } else { |
708 | qWarning() << "preview() called with unexpected metadata. returning uninstalled preview"; |
709 | - return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
710 | + return new UninstalledPreview(result, metadata, client, depts, manager); |
711 | } |
712 | } else { |
713 | // metadata.scope_data() is Null, so we return an appropriate "default" preview: |
714 | @@ -249,9 +238,9 @@ |
715 | return new InstalledScopePreview(result); |
716 | } |
717 | if (result["installed"].get_bool() == true) { |
718 | - return new InstalledPreview(result, metadata, client, ppackage, depts); |
719 | + return new InstalledPreview(result, metadata, client, depts); |
720 | } else { |
721 | - return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
722 | + return new UninstalledPreview(result, metadata, client, depts, manager); |
723 | } |
724 | } |
725 | |
726 | @@ -288,19 +277,6 @@ |
727 | { |
728 | } |
729 | |
730 | -PreviewStrategy::PreviewStrategy(const unity::scopes::Result& result, |
731 | - const QSharedPointer<click::web::Client>& client, |
732 | - const QSharedPointer<pay::Package>& ppackage) |
733 | - : result(result), |
734 | - client(client), |
735 | - index(new click::Index(client)), |
736 | - reviews(new click::Reviews(client)), |
737 | - oa_client("ubuntuone", "ubuntuone", "ubuntuone", |
738 | - scopes::OnlineAccountClient::MainLoopSelect::CreateInternalMainLoop), |
739 | - pay_package(ppackage) |
740 | -{ |
741 | -} |
742 | - |
743 | void PreviewStrategy::pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply, |
744 | const PackageDetails &details, |
745 | const scopes::PreviewWidgetList& button_area_widgets) |
746 | @@ -663,27 +639,6 @@ |
747 | return widgets; |
748 | } |
749 | |
750 | -bool PreviewStrategy::isRefundable() |
751 | -{ |
752 | - if (!result.contains("price")) |
753 | - { |
754 | - return false; |
755 | - } |
756 | - |
757 | - if (pay_package.isNull()) |
758 | - { |
759 | - return false; |
760 | - } |
761 | - |
762 | - std::string pkg_name = get_string_maybe_null(result["name"]); |
763 | - if (pkg_name.empty()) |
764 | - { |
765 | - return false; |
766 | - } |
767 | - |
768 | - return pay_package->is_refundable(pkg_name); |
769 | -} |
770 | - |
771 | void PreviewStrategy::invalidateScope(const std::string& scope_id) |
772 | { |
773 | run_under_qt([scope_id]() { |
774 | @@ -812,9 +767,8 @@ |
775 | InstalledPreview::InstalledPreview(const unity::scopes::Result& result, |
776 | const unity::scopes::ActionMetadata& metadata, |
777 | const QSharedPointer<click::web::Client>& client, |
778 | - const QSharedPointer<pay::Package>& ppackage, |
779 | const std::shared_ptr<click::DepartmentsDb>& depts) |
780 | - : PreviewStrategy(result, client, ppackage), |
781 | + : PreviewStrategy(result, client), |
782 | DepartmentUpdater(depts), |
783 | metadata(metadata) |
784 | { |
785 | @@ -1014,12 +968,7 @@ |
786 | if (manifest.removable) |
787 | { |
788 | auto price = result.contains("price") ? result["price"].get_double() : 0.00f; |
789 | - if (price > 0.00f && isRefundable()) { |
790 | - builder.add_tuple({ |
791 | - {"id", scopes::Variant(click::Preview::Actions::CANCEL_PURCHASE_INSTALLED)}, |
792 | - {"label", scopes::Variant(_("Cancel Purchase"))} |
793 | - }); |
794 | - } else { |
795 | + if (price == 0.00f) { |
796 | builder.add_tuple({ |
797 | {"id", scopes::Variant(click::Preview::Actions::UNINSTALL_CLICK)}, |
798 | {"label", scopes::Variant(_("Uninstall"))} |
799 | @@ -1111,73 +1060,6 @@ |
800 | return widgets; |
801 | } |
802 | |
803 | -// class CancelPurchasePreview |
804 | - |
805 | -CancelPurchasePreview::CancelPurchasePreview(const unity::scopes::Result& result, bool installed) |
806 | - : PreviewStrategy(result), installed(installed) |
807 | -{ |
808 | -} |
809 | - |
810 | -CancelPurchasePreview::~CancelPurchasePreview() |
811 | -{ |
812 | -} |
813 | - |
814 | -scopes::PreviewWidgetList CancelPurchasePreview::build_widgets() |
815 | -{ |
816 | - scopes::PreviewWidgetList widgets; |
817 | - |
818 | - scopes::PreviewWidget confirmation("confirmation", "text"); |
819 | - |
820 | - std::string title = result["title"].get_string(); |
821 | - // TRANSLATORS: Do NOT translate ${title} here. |
822 | - std::string message = |
823 | - _("Are you sure you want to cancel the purchase of '${title}'? The app will be uninstalled."); |
824 | - |
825 | - boost::replace_first(message, "${title}", title); |
826 | - confirmation.add_attribute_value("text", scopes::Variant(message)); |
827 | - widgets.push_back(confirmation); |
828 | - |
829 | - scopes::PreviewWidget buttons("buttons", "actions"); |
830 | - scopes::VariantBuilder builder; |
831 | - |
832 | - auto action_no = installed ? click::Preview::Actions::SHOW_INSTALLED |
833 | - : click::Preview::Actions::SHOW_UNINSTALLED; |
834 | - auto action_yes = installed |
835 | - ? click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED |
836 | - : click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED; |
837 | - |
838 | - builder.add_tuple({ |
839 | - {"id", scopes::Variant(action_no)}, |
840 | - {"label", scopes::Variant(_("Go Back"))} |
841 | - }); |
842 | - builder.add_tuple({ |
843 | - {"id", scopes::Variant(action_yes)}, |
844 | - {"label", scopes::Variant(_("Continue"))} |
845 | - }); |
846 | - |
847 | - buttons.add_attribute_value("actions", builder.end()); |
848 | - widgets.push_back(buttons); |
849 | - |
850 | - scopes::PreviewWidget policy("policy", "text"); |
851 | - policy.add_attribute_value("title", scopes::Variant{_("Returns and cancellation policy")}); |
852 | - policy.add_attribute_value("text", scopes::Variant{ |
853 | - _("When purchasing an app in the Ubuntu Store, you can cancel the charge within 15 minutes " |
854 | - "after installation. If the cancel period has passed, we recommend contacting the app " |
855 | - "developer directly for a refund.\n" |
856 | - "You can find the developer’s contact information listed on the app’s preview page in the " |
857 | - "Ubuntu Store.\n" |
858 | - "Keep in mind that you cannot cancel the purchasing process of an app more than once.")}); |
859 | - widgets.push_back(policy); |
860 | - |
861 | - return widgets; |
862 | -} |
863 | - |
864 | -void CancelPurchasePreview::run(unity::scopes::PreviewReplyProxy const& reply) |
865 | -{ |
866 | - // NOTE: no need to populateDetails() here. |
867 | - reply->push(build_widgets()); |
868 | -} |
869 | - |
870 | // class UninstallConfirmationPreview |
871 | |
872 | UninstallConfirmationPreview::UninstallConfirmationPreview(const unity::scopes::Result& result) |
873 | @@ -1225,9 +1107,8 @@ |
874 | const unity::scopes::ActionMetadata& metadata, |
875 | const QSharedPointer<click::web::Client>& client, |
876 | const std::shared_ptr<click::DepartmentsDb>& depts, |
877 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
878 | - const QSharedPointer<pay::Package>& ppackage) |
879 | - : PreviewStrategy(result, client, ppackage), |
880 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager) |
881 | + : PreviewStrategy(result, client), |
882 | DepartmentUpdater(depts), |
883 | metadata(metadata), |
884 | dm(new DownloadManager(client, manager)) |
885 | @@ -1285,18 +1166,8 @@ |
886 | scopes::PreviewWidgetList widgets; |
887 | auto price = result["price"].get_double(); |
888 | |
889 | - if (price > double(0.00) |
890 | - && result["purchased"].get_bool() == false) { |
891 | - scopes::PreviewWidget payments("purchase", "payments"); |
892 | - scopes::VariantMap tuple; |
893 | - tuple["currency"] = result["currency_symbol"].get_string(); |
894 | - tuple["price"] = scopes::Variant(price); |
895 | - tuple["store_item_id"] = details.package.name; |
896 | - tuple["download_url"] = details.download_url; |
897 | - tuple["download_sha512"] = details.download_sha512; |
898 | - payments.add_attribute_value("source", scopes::Variant(tuple)); |
899 | - widgets.push_back(payments); |
900 | - } else { |
901 | + if (price == double(0.00) |
902 | + || result["purchased"].get_bool() == false) { |
903 | scopes::PreviewWidget buttons("buttons", "actions"); |
904 | scopes::VariantBuilder builder; |
905 | builder.add_tuple( |
906 | @@ -1306,13 +1177,6 @@ |
907 | {"download_url", scopes::Variant(details.download_url)}, |
908 | {"download_sha512", scopes::Variant(details.download_sha512)}, |
909 | }); |
910 | - if (isRefundable()) { |
911 | - builder.add_tuple( |
912 | - { |
913 | - {"id", scopes::Variant(click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED)}, |
914 | - {"label", scopes::Variant(_("Cancel Purchase"))}, |
915 | - }); |
916 | - } |
917 | buttons.add_attribute_value("actions", builder.end()); |
918 | oa_client.register_account_login_item(buttons, |
919 | scopes::OnlineAccountClient::PostLoginAction::ContinueActivation, |
920 | @@ -1329,9 +1193,8 @@ |
921 | UninstallingPreview::UninstallingPreview(const unity::scopes::Result& result, |
922 | const unity::scopes::ActionMetadata& metadata, |
923 | const QSharedPointer<click::web::Client>& client, |
924 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
925 | - const QSharedPointer<pay::Package>& ppackage) |
926 | - : UninstalledPreview(result, metadata, client, nullptr, manager, ppackage) |
927 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager) |
928 | + : UninstalledPreview(result, metadata, client, nullptr, manager) |
929 | { |
930 | } |
931 | |
932 | @@ -1368,57 +1231,4 @@ |
933 | } |
934 | |
935 | |
936 | -// class CancellingPurchasePreview : public UninstallingPreview |
937 | - |
938 | -CancellingPurchasePreview::CancellingPurchasePreview(const unity::scopes::Result& result, |
939 | - const unity::scopes::ActionMetadata& metadata, |
940 | - const QSharedPointer<click::web::Client>& client, |
941 | - const QSharedPointer<pay::Package>& ppackage, |
942 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
943 | - bool installed) |
944 | - : UninstallingPreview(result, metadata, client, manager, ppackage), |
945 | - installed(installed) |
946 | -{ |
947 | -} |
948 | - |
949 | -CancellingPurchasePreview::~CancellingPurchasePreview() |
950 | -{ |
951 | -} |
952 | - |
953 | -void CancellingPurchasePreview::run(unity::scopes::PreviewReplyProxy const& reply) |
954 | -{ |
955 | - qDebug() << "in CancellingPurchasePreview::run, calling cancel_purchase"; |
956 | - cancel_purchase(); |
957 | - qDebug() << "in CancellingPurchasePreview::run, calling next ::run()"; |
958 | - if (installed) { |
959 | - UninstallingPreview::run(reply); |
960 | - } else { |
961 | - UninstalledPreview::run(reply); |
962 | - } |
963 | -} |
964 | - |
965 | -void CancellingPurchasePreview::cancel_purchase() |
966 | -{ |
967 | - auto package_name = result["name"].get_string(); |
968 | - qDebug() << "Will cancel the purchase of:" << package_name.c_str(); |
969 | - |
970 | - std::promise<bool> refund_promise; |
971 | - std::future<bool> refund_future = refund_promise.get_future(); |
972 | - |
973 | - run_under_qt([this, &refund_promise, package_name]() { |
974 | - qDebug() << "Calling refund for:" << package_name.c_str(); |
975 | - auto ret = pay_package->refund(package_name); |
976 | - qDebug() << "Refund returned:" << ret; |
977 | - refund_promise.set_value(ret); |
978 | - }); |
979 | - bool finished = refund_future.get(); |
980 | - qDebug() << "Finished refund:" << finished; |
981 | - if (finished) { |
982 | - // Reset the purchased flag. |
983 | - result["purchased"] = false; |
984 | - invalidateScope(STORE_SCOPE_ID.toUtf8().data()); |
985 | - } |
986 | -} |
987 | - |
988 | - |
989 | } // namespace click |
990 | |
991 | === modified file 'libclickscope/click/preview.h' |
992 | --- libclickscope/click/preview.h 2016-07-12 19:04:31 +0000 |
993 | +++ libclickscope/click/preview.h 2016-10-25 13:13:28 +0000 |
994 | @@ -32,7 +32,6 @@ |
995 | |
996 | #include <click/index.h> |
997 | #include <click/download-manager.h> |
998 | -#include <click/pay.h> |
999 | #include <click/qtbridge.h> |
1000 | #include "reviews.h" |
1001 | |
1002 | @@ -106,7 +105,6 @@ |
1003 | PreviewStrategy* build_strategy(const unity::scopes::Result& result, |
1004 | const unity::scopes::ActionMetadata& metadata, |
1005 | const QSharedPointer<web::Client> &client, |
1006 | - const QSharedPointer<pay::Package>& ppackage, |
1007 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1008 | std::shared_ptr<click::DepartmentsDb> depts); |
1009 | virtual PreviewStrategy* build_installing(const std::string& download_url, |
1010 | @@ -147,7 +145,6 @@ |
1011 | std::shared_future<void> const& qt_ready = std::future<void>()); |
1012 | virtual ~Preview(); |
1013 | void choose_strategy(const QSharedPointer<web::Client> &client, |
1014 | - const QSharedPointer<pay::Package>& ppackage, |
1015 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1016 | std::shared_ptr<click::DepartmentsDb> depts); |
1017 | // From unity::scopes::PreviewQuery |
1018 | @@ -162,9 +159,6 @@ |
1019 | PreviewStrategy(const unity::scopes::Result& result); |
1020 | PreviewStrategy(const unity::scopes::Result& result, |
1021 | const QSharedPointer<click::web::Client>& client); |
1022 | - PreviewStrategy(const unity::scopes::Result& result, |
1023 | - const QSharedPointer<click::web::Client>& client, |
1024 | - const QSharedPointer<pay::Package>& pay_package); |
1025 | virtual ~PreviewStrategy(); |
1026 | |
1027 | virtual void cancelled(); |
1028 | @@ -199,7 +193,6 @@ |
1029 | virtual scopes::PreviewWidget build_other_metadata(const PackageDetails& details); |
1030 | virtual scopes::PreviewWidget build_updates_table(const PackageDetails& details); |
1031 | virtual std::string build_whats_new(const PackageDetails& details); |
1032 | - virtual bool isRefundable(); |
1033 | |
1034 | scopes::Result result; |
1035 | |
1036 | @@ -210,7 +203,6 @@ |
1037 | click::web::Cancellable reviews_operation; |
1038 | click::web::Cancellable submit_operation; |
1039 | scopes::OnlineAccountClient oa_client; |
1040 | - QSharedPointer<pay::Package> pay_package; |
1041 | click::web::Cancellable purchase_operation; |
1042 | }; |
1043 | |
1044 | @@ -254,7 +246,6 @@ |
1045 | InstalledPreview(const unity::scopes::Result& result, |
1046 | const unity::scopes::ActionMetadata& metadata, |
1047 | const QSharedPointer<click::web::Client>& client, |
1048 | - const QSharedPointer<pay::Package>& ppackage, |
1049 | const std::shared_ptr<click::DepartmentsDb>& depts); |
1050 | |
1051 | virtual ~InstalledPreview(); |
1052 | @@ -292,20 +283,6 @@ |
1053 | virtual scopes::PreviewWidgetList purchasingWidgets(const PackageDetails &); |
1054 | }; |
1055 | |
1056 | -class CancelPurchasePreview : public PreviewStrategy |
1057 | -{ |
1058 | -public: |
1059 | - CancelPurchasePreview(const unity::scopes::Result& result, bool installed); |
1060 | - |
1061 | - virtual ~CancelPurchasePreview(); |
1062 | - |
1063 | - void run(unity::scopes::PreviewReplyProxy const& reply) override; |
1064 | - |
1065 | -protected: |
1066 | - scopes::PreviewWidgetList build_widgets(); |
1067 | - bool installed; |
1068 | -}; |
1069 | - |
1070 | class UninstallConfirmationPreview : public PreviewStrategy |
1071 | { |
1072 | public: |
1073 | @@ -323,8 +300,7 @@ |
1074 | const unity::scopes::ActionMetadata& metadata, |
1075 | const QSharedPointer<click::web::Client>& client, |
1076 | const std::shared_ptr<click::DepartmentsDb>& depts, |
1077 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1078 | - const QSharedPointer<pay::Package>& ppackage); |
1079 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager); |
1080 | |
1081 | virtual ~UninstalledPreview(); |
1082 | |
1083 | @@ -348,8 +324,7 @@ |
1084 | UninstallingPreview(const unity::scopes::Result& result, |
1085 | const unity::scopes::ActionMetadata& metadata, |
1086 | const QSharedPointer<click::web::Client>& client, |
1087 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1088 | - const QSharedPointer<pay::Package>& ppackage); |
1089 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager); |
1090 | |
1091 | virtual ~UninstallingPreview(); |
1092 | |
1093 | @@ -360,25 +335,6 @@ |
1094 | |
1095 | }; |
1096 | |
1097 | -class CancellingPurchasePreview : public UninstallingPreview |
1098 | -{ |
1099 | -public: |
1100 | - CancellingPurchasePreview(const unity::scopes::Result& result, |
1101 | - const unity::scopes::ActionMetadata& metadata, |
1102 | - const QSharedPointer<click::web::Client>& client, |
1103 | - const QSharedPointer<pay::Package>& ppackage, |
1104 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1105 | - bool installed); |
1106 | - |
1107 | - virtual ~CancellingPurchasePreview(); |
1108 | - |
1109 | - void run(unity::scopes::PreviewReplyProxy const& reply) override; |
1110 | - |
1111 | -protected: |
1112 | - void cancel_purchase(); |
1113 | - bool installed; |
1114 | -}; |
1115 | - |
1116 | } // namespace click |
1117 | |
1118 | #endif |
1119 | |
1120 | === modified file 'libclickscope/tests/CMakeLists.txt' |
1121 | --- libclickscope/tests/CMakeLists.txt 2016-08-09 21:43:16 +0000 |
1122 | +++ libclickscope/tests/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
1123 | @@ -19,7 +19,6 @@ |
1124 | |
1125 | add_executable (${LIBCLICKSCOPE_TESTS_TARGET} |
1126 | mock_network_access_manager.h |
1127 | - mock_pay.h |
1128 | mock_ual.h |
1129 | mock_ubuntu_download_manager.h |
1130 | mock_ubuntuone_credentials.h |
1131 | @@ -33,7 +32,6 @@ |
1132 | test_index.cpp |
1133 | test_interface.cpp |
1134 | test_package.cpp |
1135 | - test_pay.cpp |
1136 | test_preview.cpp |
1137 | test_reviews.cpp |
1138 | test_smartconnect.cpp |
1139 | @@ -72,6 +70,3 @@ |
1140 | COMMAND valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${LIBCLICKSCOPE_TESTS_TARGET} |
1141 | DEPENDS ${LIBCLICKSCOPE_TESTS_TARGET} |
1142 | ) |
1143 | - |
1144 | - |
1145 | -add_subdirectory(integration) |
1146 | |
1147 | === removed directory 'libclickscope/tests/integration' |
1148 | === removed file 'libclickscope/tests/integration/CMakeLists.txt' |
1149 | --- libclickscope/tests/integration/CMakeLists.txt 2015-05-20 19:58:45 +0000 |
1150 | +++ libclickscope/tests/integration/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1151 | @@ -1,32 +0,0 @@ |
1152 | -SET (INTEGRATION_TARGET click_scope_integration_tests) |
1153 | - |
1154 | -# Qt5 bits |
1155 | -SET (CMAKE_INCLUDE_CURRENT_DIR ON) |
1156 | -SET (CMAKE_AUTOMOC ON) |
1157 | -find_package(Qt5Core REQUIRED) |
1158 | - |
1159 | -include_directories (${CMAKE_SOURCE_DIR}/scope) |
1160 | - |
1161 | -FILE (GLOB TEST_SOURCES *.cpp) |
1162 | -FILE (GLOB TEST_HEADERS *.h) |
1163 | - |
1164 | -add_executable (${INTEGRATION_TARGET} |
1165 | - departmentsdb_integration.cpp |
1166 | - webclient_integration.cpp |
1167 | -) |
1168 | - |
1169 | -qt5_use_modules(${INTEGRATION_TARGET} Core DBus Network Test) |
1170 | - |
1171 | -target_link_libraries (${INTEGRATION_TARGET} |
1172 | - ${STORE_LIB_UNVERSIONED} |
1173 | - |
1174 | - gmock |
1175 | - gmock_main |
1176 | - |
1177 | - ${CMAKE_THREAD_LIBS_INIT} |
1178 | -) |
1179 | - |
1180 | -add_custom_target (test-integration-click-scope |
1181 | - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${INTEGRATION_TARGET} |
1182 | - DEPENDS ${INTEGRATION_TARGET} |
1183 | -) |
1184 | |
1185 | === removed file 'libclickscope/tests/integration/departmentsdb_integration.cpp' |
1186 | --- libclickscope/tests/integration/departmentsdb_integration.cpp 2014-07-22 17:15:14 +0000 |
1187 | +++ libclickscope/tests/integration/departmentsdb_integration.cpp 1970-01-01 00:00:00 +0000 |
1188 | @@ -1,137 +0,0 @@ |
1189 | -/* |
1190 | - * Copyright (C) 2014 Canonical Ltd. |
1191 | - * |
1192 | - * This program is free software: you can redistribute it and/or modify it |
1193 | - * under the terms of the GNU General Public License version 3, as published |
1194 | - * by the Free Software Foundation. |
1195 | - * |
1196 | - * This program is distributed in the hope that it will be useful, but |
1197 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
1198 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1199 | - * PURPOSE. See the GNU General Public License for more details. |
1200 | - * |
1201 | - * You should have received a copy of the GNU General Public License along |
1202 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
1203 | - * |
1204 | - * In addition, as a special exception, the copyright holders give |
1205 | - * permission to link the code of portions of this program with the |
1206 | - * OpenSSL library under certain conditions as described in each |
1207 | - * individual source file, and distribute linked combinations |
1208 | - * including the two. |
1209 | - * You must obey the GNU General Public License in all respects |
1210 | - * for all of the code used other than OpenSSL. If you modify |
1211 | - * file(s) with this exception, you may extend this exception to your |
1212 | - * version of the file(s), but you are not obligated to do so. If you |
1213 | - * do not wish to do so, delete this exception statement from your |
1214 | - * version. If you delete this exception statement from all source |
1215 | - * files in the program, then also delete it here. |
1216 | - */ |
1217 | - |
1218 | -#include <gtest/gtest.h> |
1219 | - |
1220 | -#include <click/departments-db.h> |
1221 | - |
1222 | -#include <memory> |
1223 | -#include <algorithm> |
1224 | -#include <unistd.h> |
1225 | - |
1226 | -using namespace click; |
1227 | - |
1228 | - |
1229 | -class DepartmentsDbConcurrencyTest: public ::testing::Test |
1230 | -{ |
1231 | -public: |
1232 | - const std::string db_path = TEST_DIR "/departments-db-test2.sqlite"; |
1233 | - |
1234 | - void TearDown() override |
1235 | - { |
1236 | - unlink(db_path.c_str()); |
1237 | - } |
1238 | -}; |
1239 | - |
1240 | -// Keep the numbers below at a reasonable level; it takes around 20 seconds |
1241 | -// to run this test on a i7-2620M with the default values. |
1242 | -const int NUM_OF_WRITE_OPS = 50; |
1243 | -const int NUM_OF_READ_OPS = 100; |
1244 | - |
1245 | -void populate_departments(DepartmentsDb *db, int repeat_count) |
1246 | -{ |
1247 | - click::DepartmentList depts; |
1248 | - // generate departments with one subdepartment |
1249 | - for (int i = 0; i < 20; i++) |
1250 | - { |
1251 | - auto const id = std::to_string(i); |
1252 | - auto parent = std::make_shared<click::Department>(id, "Department " + id, "href", true); |
1253 | - parent->set_subdepartments({std::make_shared<click::Department>(id + "sub", "Subdepartment of " + id, "href", false)}); |
1254 | - depts.push_back(parent); |
1255 | - } |
1256 | - |
1257 | - for (int i = 0; i < repeat_count; i++) |
1258 | - { |
1259 | - ASSERT_NO_THROW(db->store_departments(depts, "")); |
1260 | - |
1261 | - // generate apps |
1262 | - for (int j = 0; j < 50; j++) |
1263 | - { |
1264 | - auto const id = std::to_string(j); |
1265 | - ASSERT_NO_THROW(db->store_package_mapping("app" + id, id)); |
1266 | - } |
1267 | - } |
1268 | -} |
1269 | - |
1270 | -TEST_F(DepartmentsDbConcurrencyTest, ConcurrentReadWrite) |
1271 | -{ |
1272 | - // populate the db initially to make sure reader doesn't fail if it's faster than writer |
1273 | - { |
1274 | - DepartmentsDb db(db_path, true); |
1275 | - populate_departments(&db, 1); |
1276 | - } |
1277 | - |
1278 | - pid_t writer_pid = fork(); |
1279 | - if (writer_pid < 0) |
1280 | - { |
1281 | - FAIL(); |
1282 | - } |
1283 | - else if (writer_pid == 0) // writer child process |
1284 | - { |
1285 | - SCOPED_TRACE("writer"); |
1286 | - std::unique_ptr<DepartmentsDb> db; |
1287 | - ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, true))); |
1288 | - |
1289 | - populate_departments(db.get(), NUM_OF_WRITE_OPS); |
1290 | - |
1291 | - exit(0); |
1292 | - } |
1293 | - else // parent process |
1294 | - { |
1295 | - pid_t reader_pid = fork(); |
1296 | - if (reader_pid < 0) |
1297 | - { |
1298 | - FAIL(); |
1299 | - } |
1300 | - else if (reader_pid == 0) // reader child process |
1301 | - { |
1302 | - SCOPED_TRACE("reader"); |
1303 | - std::unique_ptr<DepartmentsDb> db; |
1304 | - ASSERT_NO_THROW(db.reset(new DepartmentsDb(db_path, false))); |
1305 | - |
1306 | - for (int i = 0; i < NUM_OF_READ_OPS; i++) |
1307 | - { |
1308 | - ASSERT_NO_THROW(db->get_department_name("1", {""})); |
1309 | - ASSERT_NO_THROW(db->get_parent_department_id("1")); |
1310 | - ASSERT_NO_THROW(db->get_packages_for_department("1", false)); |
1311 | - ASSERT_NO_THROW(db->get_packages_for_department("1", true)); |
1312 | - ASSERT_NO_THROW(db->get_children_departments("")); |
1313 | - ASSERT_NO_THROW(db->department_name_count()); |
1314 | - ASSERT_NO_THROW(db->department_mapping_count()); |
1315 | - ASSERT_NO_THROW(db->package_count()); |
1316 | - } |
1317 | - exit(0); |
1318 | - } |
1319 | - else // parent process |
1320 | - { |
1321 | - wait(nullptr); |
1322 | - wait(nullptr); |
1323 | - } |
1324 | - } |
1325 | -} |
1326 | |
1327 | === removed file 'libclickscope/tests/integration/webclient_integration.cpp' |
1328 | --- libclickscope/tests/integration/webclient_integration.cpp 2015-12-01 15:39:41 +0000 |
1329 | +++ libclickscope/tests/integration/webclient_integration.cpp 1970-01-01 00:00:00 +0000 |
1330 | @@ -1,128 +0,0 @@ |
1331 | -/* |
1332 | - * Copyright (C) 2014 Canonical Ltd. |
1333 | - * |
1334 | - * This program is free software: you can redistribute it and/or modify it |
1335 | - * under the terms of the GNU General Public License version 3, as published |
1336 | - * by the Free Software Foundation. |
1337 | - * |
1338 | - * This program is distributed in the hope that it will be useful, but |
1339 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
1340 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1341 | - * PURPOSE. See the GNU General Public License for more details. |
1342 | - * |
1343 | - * You should have received a copy of the GNU General Public License along |
1344 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
1345 | - * |
1346 | - * In addition, as a special exception, the copyright holders give |
1347 | - * permission to link the code of portions of this program with the |
1348 | - * OpenSSL library under certain conditions as described in each |
1349 | - * individual source file, and distribute linked combinations |
1350 | - * including the two. |
1351 | - * You must obey the GNU General Public License in all respects |
1352 | - * for all of the code used other than OpenSSL. If you modify |
1353 | - * file(s) with this exception, you may extend this exception to your |
1354 | - * version of the file(s), but you are not obligated to do so. If you |
1355 | - * do not wish to do so, delete this exception statement from your |
1356 | - * version. If you delete this exception statement from all source |
1357 | - * files in the program, then also delete it here. |
1358 | - */ |
1359 | - |
1360 | -#include <click/network_access_manager.h> |
1361 | -#include <click/webclient.h> |
1362 | -#include <click/index.h> |
1363 | -#include <click/departments.h> |
1364 | - |
1365 | -#include <QCoreApplication> |
1366 | -#include <QDebug> |
1367 | -#include <QThread> |
1368 | -#include <QTimer> |
1369 | - |
1370 | -#include <gtest/gtest.h> |
1371 | - |
1372 | -namespace |
1373 | -{ |
1374 | -struct IntegrationTest : public ::testing::Test |
1375 | -{ |
1376 | - IntegrationTest() : app(argc, argv) |
1377 | - { |
1378 | - QObject::connect( |
1379 | - &testTimeout, &QTimer::timeout, |
1380 | - [this]() { Quit(); FAIL() << "Operation timed out."; }); |
1381 | - } |
1382 | - |
1383 | - void SetUp() |
1384 | - { |
1385 | - const int tenSeconds = 10 * 1000; |
1386 | - testTimeout.start(tenSeconds); |
1387 | - } |
1388 | - |
1389 | - void TearDown() |
1390 | - { |
1391 | - testTimeout.stop(); |
1392 | - } |
1393 | - |
1394 | - void Quit() |
1395 | - { |
1396 | - app.quit(); |
1397 | - } |
1398 | - |
1399 | - int argc = 0; |
1400 | - char** argv = nullptr; |
1401 | - QCoreApplication app; |
1402 | - QTimer testTimeout; |
1403 | -}; |
1404 | - |
1405 | -} |
1406 | - |
1407 | -TEST_F(IntegrationTest, queryForArmhfPackagesReturnsCorrectResults) |
1408 | -{ |
1409 | - click::web::Client ws(QSharedPointer<click::network::AccessManager>( |
1410 | - new click::network::AccessManager())); |
1411 | - |
1412 | - click::web::CallParams params; |
1413 | - params.add("q", "qr,architecture:armhf"); |
1414 | - auto wr = ws.call(click::SEARCH_BASE_URL + click::SEARCH_PATH, params); |
1415 | - |
1416 | - QString content; |
1417 | - QObject::connect( |
1418 | - wr.data(), &click::web::Response::finished, |
1419 | - [&, this](QString found_content) { |
1420 | - content = found_content; |
1421 | - Quit(); |
1422 | - }); |
1423 | - |
1424 | - app.exec(); |
1425 | - EXPECT_TRUE(content.size() > 0); |
1426 | -} |
1427 | - |
1428 | -TEST_F(IntegrationTest, queryForArmhfPackagesCanBeParsed) |
1429 | -{ |
1430 | - QSharedPointer<click::network::AccessManager> namPtr( |
1431 | - new click::network::AccessManager()); |
1432 | - QSharedPointer<click::web::Client> clientPtr( |
1433 | - new click::web::Client(namPtr)); |
1434 | - click::Index index(clientPtr); |
1435 | - click::Packages packages; |
1436 | - index.search("qr", "", [&, this](click::Packages found_packages, |
1437 | - click::Packages){ |
1438 | - packages = found_packages; |
1439 | - Quit(); |
1440 | - }); |
1441 | - app.exec(); |
1442 | - EXPECT_TRUE(packages.size() > 0); |
1443 | -} |
1444 | - |
1445 | -TEST_F(IntegrationTest, detailsCanBeParsed) |
1446 | -{ |
1447 | - const std::string sample_name("com.ubuntu.developer.alecu.qr-code"); |
1448 | - QSharedPointer<click::network::AccessManager> namPtr( |
1449 | - new click::network::AccessManager()); |
1450 | - QSharedPointer<click::web::Client> clientPtr( |
1451 | - new click::web::Client(namPtr)); |
1452 | - click::Index index(clientPtr); |
1453 | - index.get_details(sample_name, [&](click::PackageDetails details, click::Index::Error){ |
1454 | - EXPECT_EQ(details.package.name, sample_name); |
1455 | - Quit(); |
1456 | - }); |
1457 | - app.exec(); |
1458 | -} |
1459 | |
1460 | === removed file 'libclickscope/tests/mock_pay.h' |
1461 | --- libclickscope/tests/mock_pay.h 2015-11-24 18:23:23 +0000 |
1462 | +++ libclickscope/tests/mock_pay.h 1970-01-01 00:00:00 +0000 |
1463 | @@ -1,106 +0,0 @@ |
1464 | -/* |
1465 | - * Copyright (C) 2014 Canonical Ltd. |
1466 | - * |
1467 | - * This program is free software: you can redistribute it and/or modify it |
1468 | - * under the terms of the GNU General Public License version 3, as published |
1469 | - * by the Free Software Foundation. |
1470 | - * |
1471 | - * This program is distributed in the hope that it will be useful, but |
1472 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
1473 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1474 | - * PURPOSE. See the GNU General Public License for more details. |
1475 | - * |
1476 | - * You should have received a copy of the GNU General Public License along |
1477 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
1478 | - * |
1479 | - * In addition, as a special exception, the copyright holders give |
1480 | - * permission to link the code of portions of this program with the |
1481 | - * OpenSSL library under certain conditions as described in each |
1482 | - * individual source file, and distribute linked combinations |
1483 | - * including the two. |
1484 | - * You must obey the GNU General Public License in all respects |
1485 | - * for all of the code used other than OpenSSL. If you modify |
1486 | - * file(s) with this exception, you may extend this exception to your |
1487 | - * version of the file(s), but you are not obligated to do so. If you |
1488 | - * do not wish to do so, delete this exception statement from your |
1489 | - * version. If you delete this exception statement from all source |
1490 | - * files in the program, then also delete it here. |
1491 | - */ |
1492 | - |
1493 | -#include <click/pay.h> |
1494 | - |
1495 | -#include <click/webclient.h> |
1496 | - |
1497 | -#include <gtest/gtest.h> |
1498 | -#include <gmock/gmock.h> |
1499 | - |
1500 | - |
1501 | -namespace |
1502 | -{ |
1503 | - |
1504 | - constexpr static const char* FAKE_PURCHASES_LIST_JSON{R"foo( |
1505 | - [ |
1506 | - { |
1507 | - "state": "Complete", |
1508 | - "package_name": "com.example.fake", |
1509 | - "refundable_until": "1970-01-01T00:01:23Z", |
1510 | - "open_id": "https:\/\/login.ubuntu.com/+openid/fakeuser" |
1511 | - } |
1512 | - ] |
1513 | - )foo"}; |
1514 | - |
1515 | - |
1516 | - constexpr static const char* FAKE_PURCHASES_LIST_JSON_NULL_TIMESTAMP{R"foo( |
1517 | - [ |
1518 | - { |
1519 | - "state": "Complete", |
1520 | - "package_name": "com.example.fake", |
1521 | - "refundable_until": null, |
1522 | - "open_id": "https:\/\/login.ubuntu.com/+openid/fakeuser" |
1523 | - } |
1524 | - ] |
1525 | - )foo"}; |
1526 | - |
1527 | - |
1528 | - |
1529 | - class MockPayPackage : public pay::Package { |
1530 | - public: |
1531 | - MockPayPackage() |
1532 | - : Package(QSharedPointer<click::web::Client>()) |
1533 | - { |
1534 | - } |
1535 | - |
1536 | - MockPayPackage(const QSharedPointer<click::web::Client>& client) |
1537 | - : Package(client) |
1538 | - { |
1539 | - } |
1540 | - |
1541 | - void pay_package_refund(const std::string& pkg_name) |
1542 | - { |
1543 | - callbacks[pkg_name + pay::APPENDAGE_REFUND](pkg_name, success); |
1544 | - do_pay_package_refund(pkg_name); |
1545 | - } |
1546 | - |
1547 | - void pay_package_verify(const std::string& pkg_name) |
1548 | - { |
1549 | - callbacks[pkg_name + pay::APPENDAGE_VERIFY](pkg_name, success); |
1550 | - do_pay_package_verify(pkg_name); |
1551 | - } |
1552 | - |
1553 | - bool is_refundable(const std::string& pkg_name) |
1554 | - { |
1555 | - do_is_refundable(pkg_name); |
1556 | - return refundable; |
1557 | - } |
1558 | - |
1559 | - MOCK_METHOD0(setup_pay_service, void()); |
1560 | - MOCK_METHOD1(do_pay_package_refund, void(const std::string&)); |
1561 | - MOCK_METHOD1(do_pay_package_verify, void(const std::string&)); |
1562 | - MOCK_METHOD1(do_is_refundable, void(const std::string&)); |
1563 | - |
1564 | - bool refundable = false; |
1565 | - bool success = false; |
1566 | - pay::PurchaseSet purchases; |
1567 | -}; |
1568 | - |
1569 | -} // namespace |
1570 | |
1571 | === removed file 'libclickscope/tests/test_pay.cpp' |
1572 | --- libclickscope/tests/test_pay.cpp 2016-06-30 20:42:56 +0000 |
1573 | +++ libclickscope/tests/test_pay.cpp 1970-01-01 00:00:00 +0000 |
1574 | @@ -1,266 +0,0 @@ |
1575 | -/* |
1576 | - * Copyright (C) 2014 Canonical Ltd. |
1577 | - * |
1578 | - * This program is free software: you can redistribute it and/or modify it |
1579 | - * under the terms of the GNU General Public License version 3, as published |
1580 | - * by the Free Software Foundation. |
1581 | - * |
1582 | - * This program is distributed in the hope that it will be useful, but |
1583 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
1584 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1585 | - * PURPOSE. See the GNU General Public License for more details. |
1586 | - * |
1587 | - * You should have received a copy of the GNU General Public License along |
1588 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
1589 | - * |
1590 | - * In addition, as a special exception, the copyright holders give |
1591 | - * permission to link the code of portions of this program with the |
1592 | - * OpenSSL library under certain conditions as described in each |
1593 | - * individual source file, and distribute linked combinations |
1594 | - * including the two. |
1595 | - * You must obey the GNU General Public License in all respects |
1596 | - * for all of the code used other than OpenSSL. If you modify |
1597 | - * file(s) with this exception, you may extend this exception to your |
1598 | - * version of the file(s), but you are not obligated to do so. If you |
1599 | - * do not wish to do so, delete this exception statement from your |
1600 | - * version. If you delete this exception statement from all source |
1601 | - * files in the program, then also delete it here. |
1602 | - */ |
1603 | - |
1604 | -#include "mock_pay.h" |
1605 | - |
1606 | -#include <click/webclient.h> |
1607 | - |
1608 | -#include <tests/mock_network_access_manager.h> |
1609 | -#include <tests/mock_ubuntuone_credentials.h> |
1610 | -#include <tests/mock_webclient.h> |
1611 | - |
1612 | -#include <gtest/gtest.h> |
1613 | -#include <gmock/gmock.h> |
1614 | - |
1615 | -#include <memory> |
1616 | - |
1617 | -using namespace ::testing; |
1618 | - |
1619 | - |
1620 | -namespace |
1621 | -{ |
1622 | - |
1623 | -class PayTest : public ::testing::Test |
1624 | -{ |
1625 | -protected: |
1626 | - QSharedPointer<MockNetworkAccessManager> namPtr; |
1627 | - QSharedPointer<MockClient> clientPtr; |
1628 | - std::shared_ptr<MockPayPackage> package; |
1629 | - |
1630 | - virtual void SetUp() |
1631 | - { |
1632 | - namPtr.reset(new MockNetworkAccessManager()); |
1633 | - clientPtr.reset(new NiceMock<MockClient>(namPtr)); |
1634 | - package.reset(new MockPayPackage(clientPtr)); |
1635 | - } |
1636 | -public: |
1637 | - MOCK_METHOD1(purchases_callback, void(pay::PurchaseSet)); |
1638 | -}; |
1639 | - |
1640 | -} |
1641 | - |
1642 | -TEST_F(PayTest, testPayPackageRefundCalled) |
1643 | -{ |
1644 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1645 | - auto response = responseForReply(reply.asSharedPtr()); |
1646 | - |
1647 | - EXPECT_CALL(*package, do_pay_package_refund("foo")).Times(1); |
1648 | - EXPECT_FALSE(package->refund("foo")); |
1649 | -} |
1650 | - |
1651 | -TEST_F(PayTest, testPayPackageRefundNotCalledIfCallbackExists) |
1652 | -{ |
1653 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1654 | - auto response = responseForReply(reply.asSharedPtr()); |
1655 | - |
1656 | - std::string callback_id = std::string{"foo"} + pay::APPENDAGE_REFUND; |
1657 | - package->callbacks[callback_id] = [](const std::string&, bool) {}; |
1658 | - EXPECT_CALL(*package, do_pay_package_refund("foo")).Times(0); |
1659 | - EXPECT_FALSE(package->refund("foo")); |
1660 | -} |
1661 | - |
1662 | -TEST_F(PayTest, testRefundReturnsTrueForPurchasedItem) |
1663 | -{ |
1664 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1665 | - auto response = responseForReply(reply.asSharedPtr()); |
1666 | - |
1667 | - package->success = true; |
1668 | - EXPECT_CALL(*package, do_pay_package_refund("foo")).Times(1); |
1669 | - EXPECT_TRUE(package->refund("foo")); |
1670 | -} |
1671 | - |
1672 | -TEST_F(PayTest, testPayPackageVerifyCalled) |
1673 | -{ |
1674 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1675 | - auto response = responseForReply(reply.asSharedPtr()); |
1676 | - |
1677 | - EXPECT_CALL(*package, do_pay_package_verify("foo")).Times(1); |
1678 | - EXPECT_FALSE(package->verify("foo")); |
1679 | -} |
1680 | - |
1681 | -TEST_F(PayTest, testPayPackageVerifyNotCalledIfCallbackExists) |
1682 | -{ |
1683 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1684 | - auto response = responseForReply(reply.asSharedPtr()); |
1685 | - |
1686 | - std::string callback_id = std::string{"foo"} + pay::APPENDAGE_VERIFY; |
1687 | - package->callbacks[callback_id] = [](const std::string&, bool) {}; |
1688 | - EXPECT_CALL(*package, do_pay_package_verify("foo")).Times(0); |
1689 | - EXPECT_FALSE(package->verify("foo")); |
1690 | -} |
1691 | - |
1692 | -TEST_F(PayTest, testVerifyReturnsTrueForPurchasedItem) |
1693 | -{ |
1694 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1695 | - auto response = responseForReply(reply.asSharedPtr()); |
1696 | - |
1697 | - package->success = true; |
1698 | - EXPECT_CALL(*package, do_pay_package_verify("foo")).Times(1); |
1699 | - EXPECT_TRUE(package->verify("foo")); |
1700 | -} |
1701 | - |
1702 | -TEST_F(PayTest, testGetPurchasesCallsWebservice) |
1703 | -{ |
1704 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1705 | - auto response = responseForReply(reply.asSharedPtr()); |
1706 | - |
1707 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1708 | - .Times(1) |
1709 | - .WillOnce(Return(response)); |
1710 | - |
1711 | - package->get_purchases([](pay::PurchaseSet) {}); |
1712 | -} |
1713 | - |
1714 | -TEST_F(PayTest, testGetPurchasesSendsCorrectPath) |
1715 | -{ |
1716 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1717 | - auto response = responseForReply(reply.asSharedPtr()); |
1718 | - |
1719 | - EXPECT_CALL(*clientPtr, callImpl(EndsWith(pay::PURCHASES_API_PATH), |
1720 | - _, _, _, _, _)) |
1721 | - .Times(1) |
1722 | - .WillOnce(Return(response)); |
1723 | - |
1724 | - package->get_purchases([](pay::PurchaseSet) {}); |
1725 | -} |
1726 | - |
1727 | -TEST_F(PayTest, testGetPurchasesCallbackCalled) |
1728 | -{ |
1729 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1730 | - auto response = responseForReply(reply.asSharedPtr()); |
1731 | - |
1732 | - QByteArray fake_json("[]"); |
1733 | - EXPECT_CALL(reply.instance, readAll()) |
1734 | - .Times(1) |
1735 | - .WillOnce(Return(fake_json)); |
1736 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1737 | - .Times(1) |
1738 | - .WillOnce(Return(response)); |
1739 | - EXPECT_CALL(*this, purchases_callback(_)).Times(1); |
1740 | - |
1741 | - package->get_purchases([this](pay::PurchaseSet purchases) { |
1742 | - purchases_callback(purchases); |
1743 | - }); |
1744 | - response->replyFinished(); |
1745 | -} |
1746 | - |
1747 | -TEST_F(PayTest, testGetPurchasesEmptyJsonIsParsed) |
1748 | -{ |
1749 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1750 | - auto response = responseForReply(reply.asSharedPtr()); |
1751 | - |
1752 | - QByteArray fake_json("[]"); |
1753 | - EXPECT_CALL(reply.instance, readAll()) |
1754 | - .Times(1) |
1755 | - .WillOnce(Return(fake_json)); |
1756 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1757 | - .Times(1) |
1758 | - .WillOnce(Return(response)); |
1759 | - pay::PurchaseSet empty_purchases_list; |
1760 | - EXPECT_CALL(*this, purchases_callback(empty_purchases_list)).Times(1); |
1761 | - |
1762 | - package->get_purchases([this](pay::PurchaseSet purchases) { |
1763 | - purchases_callback(purchases); |
1764 | - }); |
1765 | - response->replyFinished(); |
1766 | -} |
1767 | - |
1768 | -TEST_F(PayTest, testGetPurchasesSingleJsonIsParsedNullTimestamp) |
1769 | -{ |
1770 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1771 | - auto response = responseForReply(reply.asSharedPtr()); |
1772 | - |
1773 | - QByteArray fake_json(FAKE_PURCHASES_LIST_JSON_NULL_TIMESTAMP); |
1774 | - EXPECT_CALL(reply.instance, readAll()) |
1775 | - .Times(1) |
1776 | - .WillOnce(Return(fake_json)); |
1777 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1778 | - .Times(1) |
1779 | - .WillOnce(Return(response)); |
1780 | - pay::PurchaseSet single_purchase_list{{"com.example.fake", 0}}; |
1781 | - EXPECT_CALL(*this, purchases_callback(single_purchase_list)).Times(1); |
1782 | - |
1783 | - package->get_purchases([this](pay::PurchaseSet purchases) { |
1784 | - purchases_callback(purchases); |
1785 | - }); |
1786 | - response->replyFinished(); |
1787 | -} |
1788 | - |
1789 | -TEST_F(PayTest, testGetPurchasesTimestampIsParsed) |
1790 | -{ |
1791 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1792 | - auto response = responseForReply(reply.asSharedPtr()); |
1793 | - |
1794 | - QByteArray fake_json(FAKE_PURCHASES_LIST_JSON); |
1795 | - EXPECT_CALL(reply.instance, readAll()) |
1796 | - .Times(1) |
1797 | - .WillOnce(Return(fake_json)); |
1798 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1799 | - .Times(1) |
1800 | - .WillOnce(Return(response)); |
1801 | - const time_t EIGHTYTHREE_SECONDS_INTO_THE_SEVENTIES=83; |
1802 | - pay::PurchaseSet single_purchase_list{{"com.example.fake", EIGHTYTHREE_SECONDS_INTO_THE_SEVENTIES}}; |
1803 | - EXPECT_CALL(*this, purchases_callback(single_purchase_list)).Times(1); |
1804 | - |
1805 | - package->get_purchases([this](pay::PurchaseSet purchases) { |
1806 | - purchases_callback(purchases); |
1807 | - }); |
1808 | - response->replyFinished(); |
1809 | -} |
1810 | - |
1811 | -TEST_F(PayTest, testGetPurchasesIsCancellable) |
1812 | -{ |
1813 | - LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
1814 | - auto response = responseForReply(reply.asSharedPtr()); |
1815 | - |
1816 | - EXPECT_CALL(*clientPtr, callImpl(_, _, _, _, _, _)) |
1817 | - .Times(1) |
1818 | - .WillOnce(Return(response)); |
1819 | - |
1820 | - auto get_purchases_op = package->get_purchases([](pay::PurchaseSet) {}); |
1821 | - EXPECT_CALL(reply.instance, abort()).Times(1); |
1822 | - get_purchases_op.cancel(); |
1823 | -} |
1824 | - |
1825 | -TEST_F(PayTest, testGetBaseUrl) |
1826 | -{ |
1827 | - const char *value = getenv(pay::BASE_URL_ENVVAR); |
1828 | - if (value != NULL) { |
1829 | - ASSERT_TRUE(unsetenv(pay::BASE_URL_ENVVAR) == 0); |
1830 | - } |
1831 | - ASSERT_TRUE(pay::Package::get_base_url() == pay::BASE_URL); |
1832 | - |
1833 | -} |
1834 | - |
1835 | -TEST_F(PayTest, testGetBaseUrlFromEnv) |
1836 | -{ |
1837 | - ASSERT_TRUE(setenv(pay::BASE_URL_ENVVAR, FAKE_SERVER.c_str(), 1) == 0); |
1838 | - ASSERT_TRUE(pay::Package::get_base_url() == FAKE_SERVER); |
1839 | - ASSERT_TRUE(unsetenv(pay::BASE_URL_ENVVAR) == 0); |
1840 | -} |
1841 | |
1842 | === modified file 'libclickscope/tests/test_preview.cpp' |
1843 | --- libclickscope/tests/test_preview.cpp 2016-07-13 20:30:09 +0000 |
1844 | +++ libclickscope/tests/test_preview.cpp 2016-10-25 13:13:28 +0000 |
1845 | @@ -33,7 +33,6 @@ |
1846 | #include <click/interface.h> |
1847 | #include <click/reviews.h> |
1848 | #include <fake_json.h> |
1849 | -#include <mock_pay.h> |
1850 | #include <mock_ubuntu_download_manager.h> |
1851 | |
1852 | #include <QCoreApplication> |
1853 | @@ -109,7 +108,6 @@ |
1854 | using click::PreviewStrategy::build_updates_table; |
1855 | using click::PreviewStrategy::build_whats_new; |
1856 | using click::PreviewStrategy::populateDetails; |
1857 | - using click::PreviewStrategy::isRefundable; |
1858 | }; |
1859 | |
1860 | class PreviewsBaseTest : public Test |
1861 | @@ -350,7 +348,6 @@ |
1862 | unity::scopes::ActionMetadata metadata; |
1863 | unity::scopes::VariantMap metadict; |
1864 | QSharedPointer<click::web::Client> client; |
1865 | - QSharedPointer<MockPayPackage> pay_package; |
1866 | QSharedPointer<MockSystemDownloadManager> dm; |
1867 | std::shared_ptr<click::DepartmentsDb> depts; |
1868 | const std::string FAKE_SHA512 = "FAKE_SHA512"; |
1869 | @@ -384,7 +381,7 @@ |
1870 | metadata.set_scope_data(unity::scopes::Variant(metadict)); |
1871 | MockablePreview preview(result, metadata); |
1872 | EXPECT_CALL(preview, build_installing(_, FAKE_SHA512, _, _, _, _)); |
1873 | - preview.choose_strategy(client, pay_package, dm, depts); |
1874 | + preview.choose_strategy(client, dm, depts); |
1875 | } |
1876 | |
1877 | |
1878 | @@ -394,7 +391,6 @@ |
1879 | click::PackageDetails details; |
1880 | unity::scopes::PreviewWidgetList widgets; |
1881 | QSharedPointer<click::web::Client> client; |
1882 | - QSharedPointer<MockPayPackage> pay_package; |
1883 | QSharedPointer<MockSystemDownloadManager> sdm; |
1884 | std::shared_ptr<click::DepartmentsDb> depts; |
1885 | unity::scopes::testing::MockPreviewReply reply; |
1886 | @@ -409,9 +405,8 @@ |
1887 | const unity::scopes::ActionMetadata& metadata, |
1888 | const QSharedPointer<click::web::Client>& client, |
1889 | const std::shared_ptr<click::DepartmentsDb>& depts, |
1890 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1891 | - const QSharedPointer<pay::Package> pay_package) |
1892 | - : click::UninstalledPreview(result, metadata, client, depts, manager, pay_package), |
1893 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager) |
1894 | + : click::UninstalledPreview(result, metadata, client, depts, manager), |
1895 | object_path(object_path) |
1896 | { |
1897 | } |
1898 | @@ -433,9 +428,8 @@ |
1899 | const unity::scopes::ActionMetadata& metadata, |
1900 | const QSharedPointer<click::web::Client>& client, |
1901 | const std::shared_ptr<click::DepartmentsDb>& depts, |
1902 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1903 | - const QSharedPointer<pay::Package> pay_package) |
1904 | - : FakeBaseUninstalledPreview(object_path, result, metadata, client, depts, manager, pay_package) { |
1905 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager) |
1906 | + : FakeBaseUninstalledPreview(object_path, result, metadata, client, depts, manager) { |
1907 | } |
1908 | }; |
1909 | |
1910 | @@ -447,7 +441,7 @@ |
1911 | result["name"] = "fake_app_name"; |
1912 | scopes::PreviewWidgetList response; |
1913 | unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
1914 | - FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm, pay_package); |
1915 | + FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm); |
1916 | EXPECT_CALL(preview, progressBarWidget(_)) |
1917 | .Times(1) |
1918 | .WillOnce(Return(response)); |
1919 | @@ -462,7 +456,7 @@ |
1920 | result["name"] = "fake_app_name"; |
1921 | scopes::PreviewWidgetList response; |
1922 | unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
1923 | - FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm, pay_package); |
1924 | + FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm); |
1925 | EXPECT_CALL(preview, uninstalledActionButtonWidgets(_)) |
1926 | .Times(1) |
1927 | .WillOnce(Return(response)); |
1928 | @@ -475,12 +469,10 @@ |
1929 | const unity::scopes::ActionMetadata& metadata, |
1930 | const QSharedPointer<click::web::Client>& client, |
1931 | const std::shared_ptr<click::DepartmentsDb>& depts, |
1932 | - const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
1933 | - const QSharedPointer<pay::Package> pay_package) |
1934 | - : FakeBaseUninstalledPreview(std::string{""}, result, metadata, client, depts, manager, pay_package){ |
1935 | + const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager) |
1936 | + : FakeBaseUninstalledPreview(std::string{""}, result, metadata, client, depts, manager){ |
1937 | } |
1938 | using click::UninstalledPreview::uninstalledActionButtonWidgets; |
1939 | - MOCK_METHOD0(isRefundable, bool()); |
1940 | }; |
1941 | |
1942 | unity::scopes::VariantArray get_actions_from_widgets(const unity::scopes::PreviewWidgetList& widgets, int widget_number) { |
1943 | @@ -494,58 +486,12 @@ |
1944 | return selected_action["id"].get_string(); |
1945 | } |
1946 | |
1947 | -TEST_F(UninstalledPreviewTest, testPaymentsButtonNoAccountsData) { |
1948 | - result["name"] = "fake_app_name"; |
1949 | - result["price"] = 2.99; |
1950 | - result["purchased"] = false; |
1951 | - result["currency_symbol"] = "USD"; |
1952 | - unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
1953 | - FakeBaseUninstalledPreview preview("", result, metadata, client, depts, sdm, pay_package); |
1954 | - click::PackageDetails pkgdetails; |
1955 | - pkgdetails.package = click::Package(result["name"].get_string(), "0.1"); |
1956 | - pkgdetails.download_url = "https://localhost/example/fake_app_name.click"; |
1957 | - pkgdetails.download_sha512 = "download_sha512"; |
1958 | - auto widgets = preview.uninstalledActionButtonWidgets(pkgdetails); |
1959 | - auto button = *std::next(widgets.begin(), 0); |
1960 | - std::cerr << button.data() << std::endl; |
1961 | - ASSERT_EQ(button.attribute_values().count("online_account_details"), 0); |
1962 | -} |
1963 | - |
1964 | -TEST_F(UninstalledPreviewTest, testIsRefundableButtonShown) { |
1965 | - result["name"] = "fake_app_name"; |
1966 | - result["price"] = 2.99; |
1967 | - result["purchased"] = true; |
1968 | - unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
1969 | - FakeUninstalledRefundablePreview preview(result, metadata, client, depts, sdm, pay_package); |
1970 | - |
1971 | - click::PackageDetails pkgdetails; |
1972 | - EXPECT_CALL(preview, isRefundable()).Times(1) |
1973 | - .WillOnce(Return(true)); |
1974 | - auto widgets = preview.uninstalledActionButtonWidgets(pkgdetails); |
1975 | - ASSERT_EQ(get_action_from_widgets(widgets, 0, 1), "cancel_purchase_uninstalled"); |
1976 | -} |
1977 | - |
1978 | -TEST_F(UninstalledPreviewTest, testIsRefundableButtonNotShown) { |
1979 | - result["name"] = "fake_app_name"; |
1980 | - result["price"] = 2.99; |
1981 | - result["purchased"] = true; |
1982 | - unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
1983 | - FakeUninstalledRefundablePreview preview(result, metadata, client, depts, sdm, pay_package); |
1984 | - |
1985 | - click::PackageDetails pkgdetails; |
1986 | - EXPECT_CALL(preview, isRefundable()).Times(1) |
1987 | - .WillOnce(Return(false)); |
1988 | - auto widgets = preview.uninstalledActionButtonWidgets(pkgdetails); |
1989 | - ASSERT_EQ(get_actions_from_widgets(widgets, 0).size(), 1); |
1990 | -} |
1991 | - |
1992 | class InstalledPreviewTest : public Test { |
1993 | protected: |
1994 | unity::scopes::testing::Result result; |
1995 | unity::scopes::ActionMetadata metadata; |
1996 | unity::scopes::VariantMap metadict; |
1997 | QSharedPointer<click::web::Client> client; |
1998 | - QSharedPointer<MockPayPackage> pay_package; |
1999 | std::shared_ptr<click::DepartmentsDb> depts; |
2000 | |
2001 | public: |
2002 | @@ -553,62 +499,8 @@ |
2003 | } |
2004 | }; |
2005 | |
2006 | -class FakeInstalledRefundablePreview : public click::InstalledPreview { |
2007 | -public: |
2008 | - FakeInstalledRefundablePreview(const unity::scopes::Result& result, |
2009 | - const unity::scopes::ActionMetadata& metadata, |
2010 | - const QSharedPointer<click::web::Client> client, |
2011 | - const QSharedPointer<pay::Package> pay_package, |
2012 | - const std::shared_ptr<click::DepartmentsDb> depts) |
2013 | - : click::InstalledPreview(result, metadata, client, pay_package, depts) { |
2014 | - |
2015 | - } |
2016 | - |
2017 | - using click::InstalledPreview::createButtons; |
2018 | - MOCK_METHOD0(isRefundable, bool()); |
2019 | -}; |
2020 | - |
2021 | -TEST_F(InstalledPreviewTest, testIsRefundableButtonShownFromStore) { |
2022 | - result["price"] = 3.99f; |
2023 | - FakeInstalledRefundablePreview preview(result, metadata, client, pay_package, depts); |
2024 | - EXPECT_CALL(preview, isRefundable()).Times(1) |
2025 | - .WillOnce(Return(true)); |
2026 | - click::Manifest manifest; |
2027 | - manifest.removable = true; |
2028 | - manifest.name = "fake"; |
2029 | - manifest.first_app_name = "fake"; |
2030 | - auto widgets = preview.createButtons(manifest); |
2031 | - ASSERT_EQ(get_actions_from_widgets(widgets, 0).size(), 2); |
2032 | - ASSERT_EQ(get_action_from_widgets(widgets, 0, 1), "cancel_purchase_installed"); |
2033 | -} |
2034 | - |
2035 | -TEST_F(InstalledPreviewTest, testIsRefundableButtonNotShownFromApps) { |
2036 | - FakeInstalledRefundablePreview preview(result, metadata, client, pay_package, depts); |
2037 | - EXPECT_CALL(preview, isRefundable()).Times(0); |
2038 | - click::Manifest manifest; |
2039 | - manifest.removable = true; |
2040 | - manifest.name = "fake"; |
2041 | - manifest.first_app_name = "fake"; |
2042 | - auto widgets = preview.createButtons(manifest); |
2043 | - ASSERT_EQ(get_actions_from_widgets(widgets, 0).size(), 2); |
2044 | - ASSERT_EQ(get_action_from_widgets(widgets, 0, 1), "uninstall_click"); |
2045 | -} |
2046 | - |
2047 | -TEST_F(InstalledPreviewTest, testIsRefundableButtonNotShown) { |
2048 | - FakeInstalledRefundablePreview preview(result, metadata, client, pay_package, depts); |
2049 | - EXPECT_CALL(preview, isRefundable()).Times(0); |
2050 | - click::Manifest manifest; |
2051 | - manifest.removable = true; |
2052 | - manifest.name = "fake"; |
2053 | - manifest.first_app_name = "fake"; |
2054 | - click::PackageDetails details; |
2055 | - auto widgets = preview.createButtons(manifest); |
2056 | - ASSERT_EQ(get_actions_from_widgets(widgets, 0).size(), 2); |
2057 | - ASSERT_EQ(get_action_from_widgets(widgets, 0, 1), "uninstall_click"); |
2058 | -} |
2059 | - |
2060 | TEST_F(InstalledPreviewTest, testReviewWidgetIsNew) { |
2061 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2062 | + click::InstalledPreview preview(result, metadata, client, depts); |
2063 | click::Review existing_review; |
2064 | existing_review.id = 0; |
2065 | auto widget = preview.createRatingWidget(existing_review); |
2066 | @@ -616,7 +508,7 @@ |
2067 | } |
2068 | |
2069 | TEST_F(InstalledPreviewTest, testReviewWidgetIsEdit) { |
2070 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2071 | + click::InstalledPreview preview(result, metadata, client, depts); |
2072 | click::Review existing_review; |
2073 | existing_review.id = 123456789; |
2074 | existing_review.rating = 2.625f; |
2075 | @@ -627,7 +519,7 @@ |
2076 | } |
2077 | |
2078 | TEST_F(InstalledPreviewTest, testGetApplicationURIClick) { |
2079 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2080 | + click::InstalledPreview preview(result, metadata, client, depts); |
2081 | click::Manifest manifest; |
2082 | manifest.name = "com.ubuntu.clock"; |
2083 | manifest.first_app_name = "clock"; |
2084 | @@ -637,7 +529,7 @@ |
2085 | TEST_F(InstalledPreviewTest, testGetApplicationURIClickInResult) { |
2086 | std::string uri{"appid://com.ubuntu.clock/clock/current-user-version"}; |
2087 | result.set_uri(uri); |
2088 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2089 | + click::InstalledPreview preview(result, metadata, client, depts); |
2090 | click::Manifest manifest; |
2091 | ASSERT_EQ(preview.getApplicationUri(manifest), uri); |
2092 | } |
2093 | @@ -645,13 +537,13 @@ |
2094 | TEST_F(InstalledPreviewTest, testGetApplicationURINonClick) { |
2095 | std::string uri{"application:///web-browser.desktop"}; |
2096 | result.set_uri(uri); |
2097 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2098 | + click::InstalledPreview preview(result, metadata, client, depts); |
2099 | click::Manifest manifest; |
2100 | ASSERT_EQ(preview.getApplicationUri(manifest), uri); |
2101 | } |
2102 | |
2103 | TEST_F(InstalledPreviewTest, testGetApplicationURIScope) { |
2104 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2105 | + click::InstalledPreview preview(result, metadata, client, depts); |
2106 | click::Manifest manifest; |
2107 | manifest.name = "com.ubuntu.nearby"; |
2108 | manifest.first_scope_id = "nearby"; |
2109 | @@ -660,50 +552,7 @@ |
2110 | |
2111 | TEST_F(InstalledPreviewTest, testGetApplicationURINotAppOrScope) { |
2112 | result.set_uri("https://foo.com"); |
2113 | - click::InstalledPreview preview(result, metadata, client, pay_package, depts); |
2114 | + click::InstalledPreview preview(result, metadata, client, depts); |
2115 | click::Manifest manifest; |
2116 | ASSERT_EQ(preview.getApplicationUri(manifest), ""); |
2117 | } |
2118 | - |
2119 | -class FakeCancelPurchasePreview : public click::CancelPurchasePreview { |
2120 | -public: |
2121 | - FakeCancelPurchasePreview(const unity::scopes::Result& result, bool installed) |
2122 | - : click::CancelPurchasePreview(result, installed) { |
2123 | - |
2124 | - } |
2125 | - using click::CancelPurchasePreview::build_widgets; |
2126 | -}; |
2127 | - |
2128 | -class CancelPurchasePreviewTest : public PreviewsBaseTest { |
2129 | - |
2130 | -}; |
2131 | - |
2132 | -TEST_F(CancelPurchasePreviewTest, testNoShowsInstalled) |
2133 | -{ |
2134 | - FakeResult result{vm}; |
2135 | - result["title"] = "fake app"; |
2136 | - FakeCancelPurchasePreview preview(result, true); |
2137 | - auto widgets = preview.build_widgets(); |
2138 | - auto action = get_action_from_widgets(widgets, 1, 0); |
2139 | - ASSERT_EQ(action, "show_installed"); |
2140 | -} |
2141 | - |
2142 | -TEST_F(CancelPurchasePreviewTest, testNoShowsUninstalled) |
2143 | -{ |
2144 | - FakeResult result{vm}; |
2145 | - result["title"] = "fake app"; |
2146 | - FakeCancelPurchasePreview preview(result, false); |
2147 | - auto widgets = preview.build_widgets(); |
2148 | - auto action = get_action_from_widgets(widgets, 1, 0); |
2149 | - ASSERT_EQ(action, "show_uninstalled"); |
2150 | -} |
2151 | - |
2152 | -TEST_F(CancelPurchasePreviewTest, testYesCancelsPurchase) |
2153 | -{ |
2154 | - FakeResult result{vm}; |
2155 | - result["title"] = "fake app"; |
2156 | - FakeCancelPurchasePreview preview(result, false); |
2157 | - auto widgets = preview.build_widgets(); |
2158 | - auto action = get_action_from_widgets(widgets, 1, 1); |
2159 | - ASSERT_EQ(action, "confirm_cancel_purchase_uninstalled"); |
2160 | -} |
2161 | |
2162 | === modified file 'scope/CMakeLists.txt' |
2163 | --- scope/CMakeLists.txt 2014-05-27 06:57:52 +0000 |
2164 | +++ scope/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
2165 | @@ -1,3 +1,2 @@ |
2166 | -add_subdirectory(clickstore) |
2167 | add_subdirectory(clickapps) |
2168 | add_subdirectory(tests) |
2169 | |
2170 | === modified file 'scope/clickapps/apps-scope.cpp' |
2171 | --- scope/clickapps/apps-scope.cpp 2016-07-26 19:25:20 +0000 |
2172 | +++ scope/clickapps/apps-scope.cpp 2016-10-25 13:13:28 +0000 |
2173 | @@ -53,7 +53,6 @@ |
2174 | nam.reset(new click::network::AccessManager()); |
2175 | client.reset(new click::web::Client(nam)); |
2176 | index.reset(new click::Index(client)); |
2177 | - pay_package.reset(new pay::Package(client)); |
2178 | |
2179 | try |
2180 | { |
2181 | @@ -108,7 +107,7 @@ |
2182 | const unity::scopes::ActionMetadata& metadata) { |
2183 | qDebug() << "Scope::preview() called."; |
2184 | auto preview = new click::Preview(result, metadata, qt_ready_for_preview_f.share()); |
2185 | - preview->choose_strategy(client, pay_package, dm, depts_db); |
2186 | + preview->choose_strategy(client, dm, depts_db); |
2187 | return unity::scopes::PreviewQueryBase::UPtr{preview}; |
2188 | } |
2189 | |
2190 | |
2191 | === modified file 'scope/clickapps/apps-scope.h' |
2192 | --- scope/clickapps/apps-scope.h 2016-05-10 14:56:11 +0000 |
2193 | +++ scope/clickapps/apps-scope.h 2016-10-25 13:13:28 +0000 |
2194 | @@ -32,7 +32,6 @@ |
2195 | |
2196 | #include <click/index.h> |
2197 | #include <click/network_access_manager.h> |
2198 | -#include <click/pay.h> |
2199 | #include <click/webclient.h> |
2200 | |
2201 | #include <ubuntu/download_manager/manager.h> |
2202 | @@ -74,7 +73,6 @@ |
2203 | QSharedPointer<click::network::AccessManager> nam; |
2204 | QSharedPointer<click::web::Client> client; |
2205 | QSharedPointer<click::Index> index; |
2206 | - QSharedPointer<pay::Package> pay_package; |
2207 | QSharedPointer<Ubuntu::DownloadManager::Manager> dm; |
2208 | QSharedPointer<click::CredentialsService> sso; |
2209 | std::shared_ptr<click::DepartmentsDb> depts_db; |
2210 | |
2211 | === removed directory 'scope/clickstore' |
2212 | === removed file 'scope/clickstore/CMakeLists.txt' |
2213 | --- scope/clickstore/CMakeLists.txt 2016-09-21 21:27:01 +0000 |
2214 | +++ scope/clickstore/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
2215 | @@ -1,43 +0,0 @@ |
2216 | -SET (CMAKE_INCLUDE_CURRENT_DIR ON) |
2217 | -SET (CMAKE_AUTOMOC ON) |
2218 | -find_package (Qt5Core REQUIRED) |
2219 | -find_package (Qt5Sql REQUIRED) |
2220 | -pkg_check_modules(JSON_CPP REQUIRED jsoncpp) |
2221 | - |
2222 | -add_definitions( |
2223 | - -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\" |
2224 | - -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}\" |
2225 | -) |
2226 | - |
2227 | -add_library(${STORE_LIB_UNVERSIONED} SHARED |
2228 | - store-query.cpp |
2229 | - store-scope.cpp |
2230 | -) |
2231 | -set_target_properties(${STORE_LIB_UNVERSIONED} PROPERTIES PREFIX "") |
2232 | - |
2233 | -include_directories( |
2234 | - ${CMAKE_SOURCE_DIR}/libclickscope |
2235 | - ${JSON_CPP_INCLUDE_DIRS} |
2236 | -) |
2237 | - |
2238 | -qt5_use_modules (${STORE_LIB_UNVERSIONED} Network Sql) |
2239 | - |
2240 | -target_link_libraries (${STORE_LIB_UNVERSIONED} |
2241 | - ${SCOPE_LIB_NAME} |
2242 | - ${JSON_CPP_LDFLAGS} |
2243 | - ${UNITY_SCOPES_LDFLAGS} |
2244 | - ${UBUNTUONE_LDFLAGS} |
2245 | - ${UBUNTU_DOWNLOAD_MANAGER_CLIENT_LDFLAGS} |
2246 | - ${UBUNTU_DOWNLOAD_MANAGER_COMMON_LDFLAGS} |
2247 | -) |
2248 | - |
2249 | -set(STORE_INI_TARGET com.canonical.scopes.clickstore.ini) |
2250 | -configure_file( |
2251 | - ${STORE_INI_TARGET}.in.in |
2252 | - ${STORE_INI_TARGET}.in |
2253 | -) |
2254 | - |
2255 | -add_custom_target(${STORE_INI_TARGET} ALL |
2256 | - COMMENT "Merging translations into ${STORE_INI_TARGET}" |
2257 | - COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po ${STORE_INI_TARGET}.in ${STORE_INI_TARGET} >/dev/null |
2258 | -) |
2259 | |
2260 | === removed file 'scope/clickstore/com.canonical.scopes.clickstore.ini.in.in' |
2261 | --- scope/clickstore/com.canonical.scopes.clickstore.ini.in.in 2016-09-08 08:56:21 +0000 |
2262 | +++ scope/clickstore/com.canonical.scopes.clickstore.ini.in.in 1970-01-01 00:00:00 +0000 |
2263 | @@ -1,10 +0,0 @@ |
2264 | -[ScopeConfig] |
2265 | -_DisplayName=Ubuntu Store |
2266 | -_Description=Scope for searching the Ubuntu app store |
2267 | -Author=Canonical Ltd. |
2268 | -Art=@STORE_DATA_DIR@/clickscope-screenshot.jpg |
2269 | -Icon=@STORE_DATA_DIR@/ubuntu-store-scope.png |
2270 | -_SearchHint=Search store |
2271 | - |
2272 | -[Appearance] |
2273 | -LogoOverlayColor=#26000000 |
2274 | |
2275 | === removed file 'scope/clickstore/store-query.cpp' |
2276 | --- scope/clickstore/store-query.cpp 2016-07-26 19:25:20 +0000 |
2277 | +++ scope/clickstore/store-query.cpp 1970-01-01 00:00:00 +0000 |
2278 | @@ -1,645 +0,0 @@ |
2279 | -/* |
2280 | - * Copyright (C) 2014-2016 Canonical Ltd. |
2281 | - * |
2282 | - * This program is free software: you can redistribute it and/or modify it |
2283 | - * under the terms of the GNU General Public License version 3, as published |
2284 | - * by the Free Software Foundation. |
2285 | - * |
2286 | - * This program is distributed in the hope that it will be useful, but |
2287 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
2288 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2289 | - * PURPOSE. See the GNU General Public License for more details. |
2290 | - * |
2291 | - * You should have received a copy of the GNU General Public License along |
2292 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
2293 | - * |
2294 | - * In addition, as a special exception, the copyright holders give |
2295 | - * permission to link the code of portions of this program with the |
2296 | - * OpenSSL library under certain conditions as described in each |
2297 | - * individual source file, and distribute linked combinations |
2298 | - * including the two. |
2299 | - * You must obey the GNU General Public License in all respects |
2300 | - * for all of the code used other than OpenSSL. If you modify |
2301 | - * file(s) with this exception, you may extend this exception to your |
2302 | - * version of the file(s), but you are not obligated to do so. If you |
2303 | - * do not wish to do so, delete this exception statement from your |
2304 | - * version. If you delete this exception statement from all source |
2305 | - * files in the program, then also delete it here. |
2306 | - */ |
2307 | - |
2308 | -#include "store-query.h" |
2309 | -#include "store-scope.h" |
2310 | - |
2311 | -#include <click/application.h> |
2312 | -#include <click/interface.h> |
2313 | -#include <click/qtbridge.h> |
2314 | -#include <click/departments-db.h> |
2315 | -#include <click/utils.h> |
2316 | - |
2317 | -#include <unity/scopes/Annotation.h> |
2318 | -#include <unity/scopes/CategoryRenderer.h> |
2319 | -#include <unity/scopes/CategorisedResult.h> |
2320 | -#include <unity/scopes/Department.h> |
2321 | -#include <unity/scopes/CannedQuery.h> |
2322 | -#include <unity/scopes/SearchReply.h> |
2323 | -#include <unity/scopes/SearchMetadata.h> |
2324 | -#include <unity/scopes/Variant.h> |
2325 | -#include <unity/scopes/VariantBuilder.h> |
2326 | - |
2327 | -#include <cassert> |
2328 | -#include <iomanip> |
2329 | -#include <locale> |
2330 | -#include <memory> |
2331 | -#include <set> |
2332 | -#include <sstream> |
2333 | -#include <vector> |
2334 | - |
2335 | -#include <QLocale> |
2336 | - |
2337 | -#include <click/click-i18n.h> |
2338 | - |
2339 | -using namespace click; |
2340 | - |
2341 | -namespace |
2342 | -{ |
2343 | - |
2344 | -static const std::string CATEGORY_APPS_DISPLAY = R"( |
2345 | - { |
2346 | - "schema-version" : 1, |
2347 | - "template" : { |
2348 | - "category-layout" : "grid", |
2349 | - "card-size": "small" |
2350 | - }, |
2351 | - "components" : { |
2352 | - "title" : "title", |
2353 | - "subtitle": "subtitle", |
2354 | - "attributes": { "field": "attributes", "max-count": 4 }, |
2355 | - "art" : { |
2356 | - "field": "art", |
2357 | - "aspect-ratio": 1.13, |
2358 | - "fallback": "image://theme/placeholder-app-icon" |
2359 | - } |
2360 | - } |
2361 | - } |
2362 | -)"; |
2363 | - |
2364 | -static const std::string CATEGORY_SCOPES_DISPLAY = R"( |
2365 | - { |
2366 | - "schema-version" : 1, |
2367 | - "template" : { |
2368 | - "overlay": true, |
2369 | - "category-layout" : "grid", |
2370 | - "card-size": "small" |
2371 | - }, |
2372 | - "components" : { |
2373 | - "title" : "title", |
2374 | - "attributes": { "field": "attributes", "max-count": 1 }, |
2375 | - "art" : { |
2376 | - "field": "art", |
2377 | - "aspect-ratio": 0.55, |
2378 | - "fallback": "image://theme/placeholder-app-icon" |
2379 | - } |
2380 | - } |
2381 | - } |
2382 | -)"; |
2383 | - |
2384 | -static const std::string CATEGORY_APP_OF_THE_WEEK = R"( |
2385 | -{ |
2386 | - "schema-version" : 1, |
2387 | - "template": { |
2388 | - "category-layout": "grid", |
2389 | - "card-size": "large" |
2390 | - }, |
2391 | - "components": { |
2392 | - "title": "title", |
2393 | - "subtitle": "subtitle", |
2394 | - "attributes": { "field": "attributes", "max-count": 4 }, |
2395 | - "art": { |
2396 | - "aspect-ratio": 2.5, |
2397 | - "field": "art", |
2398 | - "fallback": "image://theme/placeholder-app-icon" |
2399 | - } |
2400 | - } |
2401 | -})"; |
2402 | - |
2403 | -static const std::string CATEGORY_APPS_SEARCH = R"( |
2404 | - { |
2405 | - "schema-version" : 1, |
2406 | - "template" : { |
2407 | - "category-layout" : "grid", |
2408 | - "card-layout" : "horizontal", |
2409 | - "collapsed-rows": 0, |
2410 | - "card-size": "large" |
2411 | - }, |
2412 | - "components" : { |
2413 | - "title" : "title", |
2414 | - "art" : { |
2415 | - "field": "art", |
2416 | - "aspect-ratio": 1.13, |
2417 | - "fallback": "image://theme/placeholder-app-icon" |
2418 | - }, |
2419 | - "subtitle": "subtitle", |
2420 | - "attributes": { "field": "attributes", "max-count": 3 } |
2421 | - } |
2422 | - } |
2423 | -)"; |
2424 | - |
2425 | -} |
2426 | - |
2427 | -struct click::Query::Private |
2428 | -{ |
2429 | - Private(click::Index& index, click::DepartmentLookup& depts, |
2430 | - std::shared_ptr<click::DepartmentsDb> depts_db, |
2431 | - click::HighlightList& highlights, |
2432 | - const scopes::SearchMetadata& metadata, |
2433 | - pay::Package& in_package, |
2434 | - std::shared_future<void> const& qt_ready) |
2435 | - : index(index), |
2436 | - department_lookup(depts), |
2437 | - depts_db(depts_db), |
2438 | - highlights(highlights), |
2439 | - meta(metadata), |
2440 | - pay_package(in_package), |
2441 | - qt_ready_(qt_ready) |
2442 | - { |
2443 | - } |
2444 | - click::Index& index; |
2445 | - click::DepartmentLookup& department_lookup; |
2446 | - std::shared_ptr<click::DepartmentsDb> depts_db; |
2447 | - click::HighlightList& highlights; |
2448 | - scopes::SearchMetadata meta; |
2449 | - click::web::Cancellable search_operation; |
2450 | - click::web::Cancellable purchases_operation; |
2451 | - pay::Package& pay_package; |
2452 | - std::shared_future<void> qt_ready_; |
2453 | -}; |
2454 | - |
2455 | -click::Query::Query(unity::scopes::CannedQuery const& query, |
2456 | - click::Index& index, |
2457 | - click::DepartmentLookup& depts, |
2458 | - std::shared_ptr<click::DepartmentsDb> depts_db, |
2459 | - click::HighlightList& highlights, |
2460 | - scopes::SearchMetadata const& metadata, |
2461 | - pay::Package& in_package, |
2462 | - std::shared_future<void> const& qt_ready) |
2463 | - : unity::scopes::SearchQueryBase(query, metadata), |
2464 | - impl(new Private(index, depts, depts_db, highlights, metadata, in_package, qt_ready)) |
2465 | -{ |
2466 | -} |
2467 | - |
2468 | -click::Query::~Query() |
2469 | -{ |
2470 | - qDebug() << "destroying search"; |
2471 | -} |
2472 | - |
2473 | -void click::Query::cancelled() |
2474 | -{ |
2475 | - qDebug() << "cancelling search of" << QString::fromStdString(query().query_string()); |
2476 | - impl->search_operation.cancel(); |
2477 | -} |
2478 | - |
2479 | -click::Interface& click::Query::clickInterfaceInstance() |
2480 | -{ |
2481 | - static click::Interface iface; |
2482 | - |
2483 | - return iface; |
2484 | -} |
2485 | - |
2486 | -bool click::Query::push_result(scopes::SearchReplyProxy const& searchReply, const scopes::CategorisedResult &res) |
2487 | -{ |
2488 | - return searchReply->push(res); |
2489 | -} |
2490 | - |
2491 | -void click::Query::finished(const scopes::SearchReplyProxy &searchReply) |
2492 | -{ |
2493 | - searchReply->finished(); |
2494 | -} |
2495 | - |
2496 | -scopes::Category::SCPtr click::Query::register_category(const scopes::SearchReplyProxy &searchReply, |
2497 | - const std::string &id, |
2498 | - const std::string &title, |
2499 | - const std::string &icon, |
2500 | - const scopes::CategoryRenderer &renderer_template) |
2501 | -{ |
2502 | - return searchReply->register_category(id, title, icon, renderer_template); |
2503 | -} |
2504 | - |
2505 | -void click::Query::run_under_qt(const std::function<void ()> &task) |
2506 | -{ |
2507 | - qt::core::world::enter_with_task([task]() { |
2508 | - task(); |
2509 | - }); |
2510 | -} |
2511 | - |
2512 | -unity::scopes::Department::SPtr click::Query::fromClickDepartment(const click::Department::SCPtr click_dept, const std::string& current_dept_id, const click::DepartmentList& subdepts) |
2513 | -{ |
2514 | - const std::locale loc(""); |
2515 | - unity::scopes::Department::SPtr dep = unity::scopes::Department::create(click_dept->id(), query(), click_dept->name()); |
2516 | - if (click_dept->has_children_flag()) |
2517 | - { |
2518 | - dep->set_has_subdepartments(); |
2519 | - } |
2520 | - unity::scopes::DepartmentList departments; |
2521 | - |
2522 | - // subdepts is a list of subdepartments of current department fetched from the Store for current search; if we encountered current department in the tree, |
2523 | - // insert the list from the server rather than the one from internal cache. |
2524 | - for (auto click_subdep: (click_dept->id() == current_dept_id ? subdepts : click_dept->sub_departments())) |
2525 | - { |
2526 | - departments.push_back(fromClickDepartment(click_subdep, current_dept_id, subdepts)); |
2527 | - } |
2528 | - departments.sort([&loc](const unity::scopes::Department::SCPtr &d1, const unity::scopes::Department::SCPtr &d2) -> bool { |
2529 | - return loc(d1->label(), d2->label()) > 0; |
2530 | - }); |
2531 | - dep->set_subdepartments(departments); |
2532 | - |
2533 | - return dep; |
2534 | -} |
2535 | - |
2536 | -// |
2537 | -// creates department menu with narrowed-down list of subdepartments of current department, as |
2538 | -// returned by server call |
2539 | -unity::scopes::Department::SPtr click::Query::populate_departments(const click::DepartmentList& subdepts, const std::string& current_dep_id) |
2540 | -{ |
2541 | - // Return complete departments tree (starting from 'All') every time, rather than only parent - current - children; this is the only |
2542 | - // way we can display siblings corrctly when navigating from Apps scope straight into a subdepartment of Store - see LP #1343242. |
2543 | - // For currently visible department include its subdepartments as returned for current search by the server (subdepts) - |
2544 | - // all others are constructed from the department lookup. |
2545 | - return fromClickDepartment(impl->department_lookup.get_department_info(""), current_dep_id, subdepts); |
2546 | -} |
2547 | - |
2548 | -// recursively store all departments in the departments database |
2549 | -void click::Query::store_departments(const click::DepartmentList& depts) |
2550 | -{ |
2551 | - assert(impl->depts_db); |
2552 | - |
2553 | - try |
2554 | - { |
2555 | - impl->depts_db->store_departments(depts, search_metadata().locale()); |
2556 | - } |
2557 | - catch (const std::exception &e) |
2558 | - { |
2559 | - qWarning() << "Failed to update database: " << QString::fromStdString(e.what()); |
2560 | - } |
2561 | -} |
2562 | - |
2563 | -void click::Query::push_package(const scopes::SearchReplyProxy& searchReply, scopes::Category::SCPtr category, const PackageSet &installedPackages, const Package& pkg) |
2564 | -{ |
2565 | - qDebug() << "pushing result" << QString::fromStdString(pkg.name); |
2566 | - try { |
2567 | - scopes::CategorisedResult res(category); |
2568 | - res.set_title(pkg.title); |
2569 | - res.set_art(pkg.icon_url); |
2570 | - res.set_uri(pkg.url); |
2571 | - res[click::Query::ResultKeys::NAME] = pkg.name; |
2572 | - res["subtitle"] = pkg.publisher; |
2573 | - auto installed = installedPackages.find(pkg); |
2574 | - |
2575 | - std::string price = _("FREE"); |
2576 | - std::stringstream ss; |
2577 | - ss << std::fixed << std::setprecision(1); |
2578 | - ss << click::Formatter::render_rating_stars(pkg.rating); |
2579 | - ss << " " << pkg.rating; |
2580 | - std::string rating{ss.str()}; |
2581 | - |
2582 | - bool was_purchased = false; |
2583 | - time_t refundable_until = 0; |
2584 | - double cur_price{0.00}; |
2585 | - auto suggested = impl->index.get_suggested_currency(); |
2586 | - std::string currency = Configuration::get_currency(suggested); |
2587 | - if (pkg.prices.count(currency) == 1) { |
2588 | - cur_price = pkg.prices.at(currency); |
2589 | - } else { |
2590 | - // NOTE: This is decprecated. Here for compatibility. |
2591 | - currency = Configuration::CURRENCY_DEFAULT; |
2592 | - cur_price = pkg.price; |
2593 | - } |
2594 | - res["price"] = scopes::Variant(cur_price); |
2595 | - res[click::Query::ResultKeys::VERSION] = pkg.version; |
2596 | - |
2597 | - |
2598 | - qDebug() << "App:" << pkg.name.c_str() << ", price:" << cur_price; |
2599 | - std::string formatted_price; |
2600 | - if (cur_price > 0.00f) { |
2601 | - if (!Configuration::get_purchases_enabled()) { |
2602 | - // Don't show priced apps if flag not set |
2603 | - return; |
2604 | - } |
2605 | - // Check if the priced app was already purchased. |
2606 | - auto purchased = purchased_apps.find({pkg.name}); |
2607 | - was_purchased = purchased != purchased_apps.end(); |
2608 | - if (was_purchased) { |
2609 | - refundable_until = purchased->refundable_until; |
2610 | - } |
2611 | - qDebug() << "was purchased?" << was_purchased << ", refundable_until:" << refundable_until; |
2612 | - |
2613 | - // Get the currency symbol to use. |
2614 | - QLocale locale; |
2615 | - auto symbol = Configuration::CURRENCY_MAP.at(currency); |
2616 | - formatted_price = locale.toCurrencyString(cur_price, |
2617 | - symbol.c_str()).toUtf8().data(); |
2618 | - res["currency_symbol"] = symbol; |
2619 | - } |
2620 | - if (installed != installedPackages.end()) { |
2621 | - res[click::Query::ResultKeys::INSTALLED] = true; |
2622 | - res[click::Query::ResultKeys::PURCHASED] = was_purchased; |
2623 | - price = _("✔ INSTALLED"); |
2624 | - res[click::Query::ResultKeys::VERSION] = installed->version; |
2625 | - } else if (was_purchased) { |
2626 | - res[click::Query::ResultKeys::PURCHASED] = true; |
2627 | - res[click::Query::ResultKeys::INSTALLED] = false; |
2628 | - price = _("✔ PURCHASED"); |
2629 | - } else { |
2630 | - res[click::Query::ResultKeys::INSTALLED] = false; |
2631 | - res[click::Query::ResultKeys::PURCHASED] = false; |
2632 | - if (cur_price > 0.00f) { |
2633 | - price = formatted_price; |
2634 | - } |
2635 | - } |
2636 | - |
2637 | - res[click::Query::ResultKeys::REFUNDABLE_UNTIL] = unity::scopes::Variant((int64_t)refundable_until); |
2638 | - res["formatted_price"] = formatted_price; |
2639 | - res["price_area"] = price; |
2640 | - res["rating"] = rating; |
2641 | - |
2642 | - // Add the price and rating as attributes. |
2643 | - scopes::VariantBuilder builder; |
2644 | - builder.add_tuple({ |
2645 | - {"value", scopes::Variant(price)}, |
2646 | - }); |
2647 | - builder.add_tuple({ |
2648 | - {"value", scopes::Variant("")}, |
2649 | - }); |
2650 | - builder.add_tuple({ |
2651 | - {"value", scopes::Variant(rating)}, |
2652 | - }); |
2653 | - builder.add_tuple({ |
2654 | - {"value", scopes::Variant("")}, |
2655 | - }); |
2656 | - res["attributes"] = builder.end(); |
2657 | - |
2658 | - this->push_result(searchReply, res); |
2659 | - } catch(const std::exception& e){ |
2660 | - qCritical() << "push_package: Exception: " << e.what() ; |
2661 | - } catch(...){ |
2662 | - qDebug() << "no reason to catch"; |
2663 | - } |
2664 | -} |
2665 | - |
2666 | -void click::Query::push_highlights(const scopes::SearchReplyProxy& searchReply, const HighlightList& highlights, const PackageSet &locallyInstalledApps) |
2667 | -{ |
2668 | - const scopes::CategoryRenderer renderer(CATEGORY_APPS_DISPLAY); |
2669 | - const scopes::CategoryRenderer scopes_renderer(CATEGORY_SCOPES_DISPLAY); |
2670 | - const scopes::CategoryRenderer aotw_renderer(CATEGORY_APP_OF_THE_WEEK); |
2671 | - |
2672 | - for (auto const& hl: highlights) |
2673 | - { |
2674 | - scopes::CategoryRenderer const* rdr = &renderer; |
2675 | - if (hl.slug() == "app-of-the-week" || hl.packages().size() == 1) |
2676 | - { |
2677 | - rdr = &aotw_renderer; |
2678 | - } |
2679 | - if (hl.contains_scopes()) |
2680 | - { |
2681 | - rdr = &scopes_renderer; |
2682 | - } |
2683 | - auto category = register_category(searchReply, hl.slug(), hl.name(), "", *rdr); |
2684 | - for (auto const& pkg: hl.packages()) |
2685 | - { |
2686 | - push_package(searchReply, category, locallyInstalledApps, pkg); |
2687 | - } |
2688 | - } |
2689 | - qDebug() << "Highlights pushed"; |
2690 | -} |
2691 | - |
2692 | -void click::Query::push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root) |
2693 | -{ |
2694 | - if (root != nullptr) |
2695 | - { |
2696 | - try |
2697 | - { |
2698 | - qDebug() << "pushing departments"; |
2699 | - searchReply->register_departments(root); |
2700 | - } |
2701 | - catch (const std::exception& e) |
2702 | - { |
2703 | - qWarning() << "Failed to register departments for query " << QString::fromStdString(query().query_string()) << |
2704 | - ", current department " << QString::fromStdString(query().department_id()) << ": " << e.what(); |
2705 | - } |
2706 | - } |
2707 | - else |
2708 | - { |
2709 | - qWarning() << "No departments data for query " << QString::fromStdString(query().query_string()) << |
2710 | - "', current department " << QString::fromStdString(query().department_id()); |
2711 | - } |
2712 | -} |
2713 | - |
2714 | -void click::Query::push_departments(scopes::SearchReplyProxy const& searchReply) |
2715 | -{ |
2716 | - auto rootdep = impl->department_lookup.get_department_info(""); |
2717 | - if (!rootdep) |
2718 | - { |
2719 | - qWarning() << "No department information available"; |
2720 | - return; |
2721 | - } |
2722 | - |
2723 | - auto subdepts = rootdep->sub_departments(); |
2724 | - auto root = populate_departments(subdepts, ""); |
2725 | - push_departments(searchReply, root); |
2726 | -} |
2727 | - |
2728 | -// |
2729 | -// push highlights and departments |
2730 | -// use cached highlights for root department, otherwise run an async job for highlights of current department. |
2731 | -void click::Query::add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& locallyInstalledApps) |
2732 | -{ |
2733 | - auto curdep = impl->department_lookup.get_department_info(query().department_id()); |
2734 | - if (!curdep) |
2735 | - { |
2736 | - qWarning() << "No department information for current department" << QString::fromStdString(query().department_id()); |
2737 | - return; |
2738 | - } |
2739 | - |
2740 | - if (query().department_id() == "") // top-level departments |
2741 | - { |
2742 | - auto subdepts = curdep->sub_departments(); |
2743 | - auto root = populate_departments(subdepts, query().department_id()); |
2744 | - push_departments(searchReply, root); |
2745 | - |
2746 | - qDebug() << "pushing cached highlights"; |
2747 | - push_highlights(searchReply, impl->highlights, locallyInstalledApps); |
2748 | - this->finished(searchReply); //FIXME: this shouldn't be needed |
2749 | - } |
2750 | - else |
2751 | - { |
2752 | - qDebug() << "starting departments call for department" << QString::fromStdString(curdep->id()) << ", href" << QString::fromStdString(curdep->href()); |
2753 | - impl->search_operation = impl->index.departments(curdep->href(), [this, locallyInstalledApps, searchReply](const DepartmentList& depts, |
2754 | - const HighlightList& highlights, Index::Error error, int) |
2755 | - { |
2756 | - if (error == click::Index::Error::NoError) |
2757 | - { |
2758 | - qDebug() << "departments call completed"; |
2759 | - auto root = populate_departments(depts, query().department_id()); |
2760 | - push_departments(searchReply, root); |
2761 | - push_highlights(searchReply, highlights, locallyInstalledApps); |
2762 | - } |
2763 | - else |
2764 | - { |
2765 | - qWarning() << "departments call failed"; |
2766 | - } |
2767 | - this->finished(searchReply); //FIXME: this shouldn't be needed |
2768 | - }); |
2769 | - } |
2770 | -} |
2771 | - |
2772 | -void click::Query::add_available_apps(scopes::SearchReplyProxy const& searchReply, |
2773 | - const PackageSet& installedPackages, |
2774 | - const std::string& categoryTemplate) |
2775 | -{ |
2776 | - // this assertion is here to ensure unit tests are properly implemented. |
2777 | - // this pointer is never null during normal execution. |
2778 | - assert(searchReply); |
2779 | - |
2780 | - run_under_qt([=]() |
2781 | - { |
2782 | - auto search_cb = [this, searchReply, categoryTemplate, installedPackages](Packages packages, Packages recommends) { |
2783 | - qDebug("search callback"); |
2784 | - |
2785 | - const scopes::CategoryRenderer categoryRenderer(categoryTemplate); |
2786 | - |
2787 | - std::string cat_title(_("Available")); |
2788 | - { |
2789 | - char tmp[512]; |
2790 | - unsigned int num_results = static_cast<unsigned int>(packages.size()); |
2791 | - if (snprintf(tmp, sizeof(tmp), |
2792 | - dngettext(GETTEXT_PACKAGE, |
2793 | - "%u result in Ubuntu Store", |
2794 | - "%u results in Ubuntu Store", |
2795 | - num_results), num_results) > 0) { |
2796 | - cat_title = tmp; |
2797 | - } |
2798 | - } |
2799 | - auto category = register_category(searchReply, "appstore", cat_title, "", categoryRenderer); |
2800 | - |
2801 | - const scopes::CategoryRenderer recommendsCatRenderer(categoryTemplate); |
2802 | - auto recommendsCategory = register_category(searchReply, "recommends", |
2803 | - _("Recommended"), "", |
2804 | - recommendsCatRenderer); |
2805 | - |
2806 | - // handle packages data |
2807 | - foreach (auto p, packages) { |
2808 | - push_package(searchReply, category, installedPackages, p); |
2809 | - } |
2810 | - foreach (auto r, recommends) { |
2811 | - push_package(searchReply, recommendsCategory, |
2812 | - installedPackages, r); |
2813 | - } |
2814 | - qDebug() << "search completed"; |
2815 | - this->finished(searchReply); //FIXME: this shouldn't be needed |
2816 | - }; |
2817 | - |
2818 | - const bool force_cache = (search_metadata().internet_connectivity() == scopes::QueryMetadata::ConnectivityStatus::Disconnected); |
2819 | - qDebug() << "search, force_cache=" << force_cache << ", conn status=" << (int)search_metadata().internet_connectivity(); |
2820 | - |
2821 | - // this is the case when we do bootstrap for the first time, or it failed last time |
2822 | - if (impl->department_lookup.size() == 0) |
2823 | - { |
2824 | - qDebug() << "performing bootstrap request"; |
2825 | - impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages, force_cache](const DepartmentList& deps, const |
2826 | - HighlightList& highlights, click::Index::Error error, int) { |
2827 | - if (error == click::Index::Error::NoError) |
2828 | - { |
2829 | - qDebug() << "bootstrap request completed"; |
2830 | - auto root = std::make_shared<click::Department>("", _("All"), "", true); |
2831 | - root->set_subdepartments(deps); |
2832 | - DepartmentList rdeps { root }; |
2833 | - impl->department_lookup.rebuild(rdeps); |
2834 | - impl->highlights = highlights; |
2835 | - qDebug() << "Total number of departments:" << impl->department_lookup.size() << ", highlights:" << highlights.size(); |
2836 | - |
2837 | - if (impl->depts_db) |
2838 | - { |
2839 | - qDebug() << "Storing departments in the database"; |
2840 | - store_departments(deps); |
2841 | - } |
2842 | - else |
2843 | - { |
2844 | - qWarning() << "Departments db not available"; |
2845 | - } |
2846 | - } |
2847 | - else |
2848 | - { |
2849 | - qWarning() << "bootstrap request failed"; |
2850 | - } |
2851 | - |
2852 | - if (error == click::Index::Error::NoError) |
2853 | - { |
2854 | - if (query().query_string().empty()) |
2855 | - { |
2856 | - add_highlights(searchReply, installedPackages); |
2857 | - } |
2858 | - else |
2859 | - { |
2860 | - qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
2861 | - push_departments(searchReply); |
2862 | - impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb, force_cache); |
2863 | - } |
2864 | - } |
2865 | - }, force_cache); |
2866 | - } |
2867 | - else |
2868 | - { |
2869 | - if (query().query_string().empty()) |
2870 | - { |
2871 | - add_highlights(searchReply, installedPackages); |
2872 | - } |
2873 | - else // normal search |
2874 | - { |
2875 | - qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
2876 | - push_departments(searchReply); |
2877 | - impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb, force_cache); |
2878 | - } |
2879 | - } |
2880 | - }); |
2881 | -} |
2882 | - |
2883 | -PackageSet click::Query::get_installed_packages() |
2884 | -{ |
2885 | - std::promise<PackageSet> installed_promise; |
2886 | - std::future<PackageSet> installed_future = installed_promise.get_future(); |
2887 | - |
2888 | - run_under_qt([&]() |
2889 | - { |
2890 | - clickInterfaceInstance().get_installed_packages( |
2891 | - [&installed_promise](PackageSet installedPackages, InterfaceError){ |
2892 | - installed_promise.set_value(installedPackages); |
2893 | - }); |
2894 | - }); |
2895 | - |
2896 | - return installed_future.get(); |
2897 | -} |
2898 | - |
2899 | - |
2900 | -void click::Query::run(scopes::SearchReplyProxy const& searchReply) |
2901 | -{ |
2902 | - if (impl->qt_ready_.valid()) |
2903 | - impl->qt_ready_.wait(); |
2904 | - |
2905 | - auto q = query().query_string(); |
2906 | - std::string categoryTemplate = CATEGORY_APPS_SEARCH; |
2907 | - if (q.empty()) { |
2908 | - categoryTemplate = CATEGORY_APPS_DISPLAY; |
2909 | - } |
2910 | - if (Configuration::get_purchases_enabled()) { |
2911 | - std::promise<pay::PurchaseSet> purchased_promise; |
2912 | - std::future<pay::PurchaseSet> purchased_future = purchased_promise.get_future(); |
2913 | - qDebug() << "Getting list of purchased apps."; |
2914 | - run_under_qt([this, &purchased_promise]() { |
2915 | - impl->purchases_operation = impl->pay_package.get_purchases([&purchased_promise](const pay::PurchaseSet& purchases) { |
2916 | - purchased_promise.set_value(purchases); |
2917 | - }); |
2918 | - }); |
2919 | - purchased_apps = purchased_future.get(); |
2920 | - } |
2921 | - |
2922 | - add_available_apps(searchReply, get_installed_packages(), categoryTemplate); |
2923 | -} |
2924 | |
2925 | === removed file 'scope/clickstore/store-query.h' |
2926 | --- scope/clickstore/store-query.h 2016-05-10 14:56:11 +0000 |
2927 | +++ scope/clickstore/store-query.h 1970-01-01 00:00:00 +0000 |
2928 | @@ -1,117 +0,0 @@ |
2929 | -/* |
2930 | - * Copyright (C) 2014 Canonical Ltd. |
2931 | - * |
2932 | - * This program is free software: you can redistribute it and/or modify it |
2933 | - * under the terms of the GNU General Public License version 3, as published |
2934 | - * by the Free Software Foundation. |
2935 | - * |
2936 | - * This program is distributed in the hope that it will be useful, but |
2937 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
2938 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2939 | - * PURPOSE. See the GNU General Public License for more details. |
2940 | - * |
2941 | - * You should have received a copy of the GNU General Public License along |
2942 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
2943 | - * |
2944 | - * In addition, as a special exception, the copyright holders give |
2945 | - * permission to link the code of portions of this program with the |
2946 | - * OpenSSL library under certain conditions as described in each |
2947 | - * individual source file, and distribute linked combinations |
2948 | - * including the two. |
2949 | - * You must obey the GNU General Public License in all respects |
2950 | - * for all of the code used other than OpenSSL. If you modify |
2951 | - * file(s) with this exception, you may extend this exception to your |
2952 | - * version of the file(s), but you are not obligated to do so. If you |
2953 | - * do not wish to do so, delete this exception statement from your |
2954 | - * version. If you delete this exception statement from all source |
2955 | - * files in the program, then also delete it here. |
2956 | - */ |
2957 | - |
2958 | -#ifndef STORE_QUERY_H |
2959 | -#define STORE_QUERY_H |
2960 | - |
2961 | -#include <unity/scopes/SearchQueryBase.h> |
2962 | -#include <unity/scopes/Department.h> |
2963 | - |
2964 | -namespace scopes = unity::scopes; |
2965 | - |
2966 | -#include <QSharedPointer> |
2967 | -#include <set> |
2968 | - |
2969 | -#include <click/department-lookup.h> |
2970 | -#include <click/package.h> |
2971 | -#include <click/pay.h> |
2972 | -#include <click/highlights.h> |
2973 | -#include <click/interface.h> |
2974 | - |
2975 | -#include <future> |
2976 | - |
2977 | -namespace click |
2978 | -{ |
2979 | - |
2980 | -class Application; |
2981 | -class Index; |
2982 | -class DepartmentLookup; |
2983 | -class DepartmentsDb; |
2984 | - |
2985 | -class Query : public scopes::SearchQueryBase |
2986 | -{ |
2987 | -public: |
2988 | - struct ResultKeys |
2989 | - { |
2990 | - ResultKeys() = delete; |
2991 | - |
2992 | - constexpr static const char* NAME{"name"}; |
2993 | - constexpr static const char* DESCRIPTION{"description"}; |
2994 | - constexpr static const char* MAIN_SCREENSHOT{"main_screenshot"}; |
2995 | - constexpr static const char* INSTALLED{"installed"}; |
2996 | - constexpr static const char* PURCHASED{"purchased"}; |
2997 | - constexpr static const char* REFUNDABLE_UNTIL{"refundable_until"}; |
2998 | - constexpr static const char* VERSION{"version"}; |
2999 | - }; |
3000 | - |
3001 | - Query(unity::scopes::CannedQuery const& query, |
3002 | - click::Index& index, |
3003 | - click::DepartmentLookup& dept_lookup, |
3004 | - std::shared_ptr<click::DepartmentsDb> depts_db, |
3005 | - click::HighlightList& highlights, |
3006 | - scopes::SearchMetadata const& metadata, |
3007 | - pay::Package& in_package, |
3008 | - std::shared_future<void> const& qt_ready = std::future<void>()); |
3009 | - virtual ~Query(); |
3010 | - |
3011 | - virtual void cancelled() override; |
3012 | - |
3013 | - virtual void run(scopes::SearchReplyProxy const& reply) override; |
3014 | - |
3015 | - pay::PurchaseSet purchased_apps; |
3016 | - |
3017 | -protected: |
3018 | - virtual unity::scopes::Department::SPtr fromClickDepartment(const click::Department::SCPtr click_dept, const std::string& current_dept_id, const click::DepartmentList& subdepts); |
3019 | - virtual unity::scopes::Department::SPtr populate_departments(const click::DepartmentList& depts, const std::string& current_department_id); |
3020 | - virtual void store_departments(const click::DepartmentList& depts); |
3021 | - virtual void push_departments(const scopes::SearchReplyProxy& searchReply, const scopes::Department::SCPtr& root); |
3022 | - virtual void push_departments(scopes::SearchReplyProxy const& searchReply); |
3023 | - virtual void add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& installedPackages); |
3024 | - virtual void add_available_apps(const scopes::SearchReplyProxy &searchReply, const PackageSet &installedPackages, const std::string &category); |
3025 | - virtual click::Interface& clickInterfaceInstance(); |
3026 | - virtual PackageSet get_installed_packages(); |
3027 | - virtual bool push_result(const scopes::SearchReplyProxy &searchReply, scopes::CategorisedResult const& res); |
3028 | - virtual void finished(const scopes::SearchReplyProxy &searchReply); |
3029 | - virtual scopes::Category::SCPtr register_category(scopes::SearchReplyProxy const& searchReply, |
3030 | - std::string const& id, |
3031 | - std::string const& title, |
3032 | - std::string const& icon, |
3033 | - scopes::CategoryRenderer const& renderer_template); |
3034 | - virtual void push_package(const scopes::SearchReplyProxy& searchReply, scopes::Category::SCPtr category, const PackageSet &locallyInstalledApps, |
3035 | - const click::Package& pkg); |
3036 | - virtual void push_highlights(const scopes::SearchReplyProxy& searchReply, const HighlightList& highlights, const PackageSet &locallyInstalledApps); |
3037 | - virtual void run_under_qt(const std::function<void()> &task); |
3038 | - |
3039 | -private: |
3040 | - struct Private; |
3041 | - QSharedPointer<Private> impl; |
3042 | -}; |
3043 | -} |
3044 | - |
3045 | -#endif // CLICK_QUERY_H |
3046 | |
3047 | === removed file 'scope/clickstore/store-scope.cpp' |
3048 | --- scope/clickstore/store-scope.cpp 2016-07-26 19:25:20 +0000 |
3049 | +++ scope/clickstore/store-scope.cpp 1970-01-01 00:00:00 +0000 |
3050 | @@ -1,237 +0,0 @@ |
3051 | -/* |
3052 | - * Copyright (C) 2014-2015 Canonical Ltd. |
3053 | - * |
3054 | - * This program is free software: you can redistribute it and/or modify it |
3055 | - * under the terms of the GNU General Public License version 3, as published |
3056 | - * by the Free Software Foundation. |
3057 | - * |
3058 | - * This program is distributed in the hope that it will be useful, but |
3059 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
3060 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3061 | - * PURPOSE. See the GNU General Public License for more details. |
3062 | - * |
3063 | - * You should have received a copy of the GNU General Public License along |
3064 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
3065 | - * |
3066 | - * In addition, as a special exception, the copyright holders give |
3067 | - * permission to link the code of portions of this program with the |
3068 | - * OpenSSL library under certain conditions as described in each |
3069 | - * individual source file, and distribute linked combinations |
3070 | - * including the two. |
3071 | - * You must obey the GNU General Public License in all respects |
3072 | - * for all of the code used other than OpenSSL. If you modify |
3073 | - * file(s) with this exception, you may extend this exception to your |
3074 | - * version of the file(s), but you are not obligated to do so. If you |
3075 | - * do not wish to do so, delete this exception statement from your |
3076 | - * version. If you delete this exception statement from all source |
3077 | - * files in the program, then also delete it here. |
3078 | - */ |
3079 | - |
3080 | -#include <click/qtbridge.h> |
3081 | -#include <click/departments-db.h> |
3082 | -#include <click/department-lookup.h> |
3083 | -#include "store-scope.h" |
3084 | -#include "store-query.h" |
3085 | -#include <click/preview.h> |
3086 | -#include <click/interface.h> |
3087 | -#include <click/scope_activation.h> |
3088 | - |
3089 | -#include <QSharedPointer> |
3090 | - |
3091 | -#include <click/network_access_manager.h> |
3092 | -#include <click/click-i18n.h> |
3093 | - |
3094 | -#include <logging.h> |
3095 | -#include <iostream> |
3096 | - |
3097 | -click::Scope::Scope() |
3098 | -{ |
3099 | - qt_ready_for_search_f = qt_ready_for_search_p.get_future(); |
3100 | - qt_ready_for_preview_f = qt_ready_for_preview_p.get_future(); |
3101 | - nam.reset(new click::network::AccessManager()); |
3102 | - client.reset(new click::web::Client(nam)); |
3103 | - index.reset(new click::Index(client)); |
3104 | - depts.reset(new click::DepartmentLookup()); |
3105 | - highlights.reset(new click::HighlightList()); |
3106 | - pay_package.reset(new pay::Package(client)); |
3107 | - |
3108 | - try |
3109 | - { |
3110 | - depts_db = click::DepartmentsDb::open(true); |
3111 | - } |
3112 | - catch (const std::runtime_error& e) |
3113 | - { |
3114 | - std::cerr << "Failed to open departments db: " << e.what() << std::endl; |
3115 | - } |
3116 | -} |
3117 | - |
3118 | -click::Scope::~Scope() |
3119 | -{ |
3120 | -} |
3121 | - |
3122 | -void click::Scope::start(std::string const&) |
3123 | -{ |
3124 | - setlocale(LC_ALL, ""); |
3125 | - // FIXME: This is wrong, but needed for json-cpp workaround. |
3126 | - setlocale(LC_MONETARY, "C"); |
3127 | - bindtextdomain(GETTEXT_PACKAGE, GETTEXT_LOCALEDIR); |
3128 | - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
3129 | - click::Date::setup_system_locale(); |
3130 | -} |
3131 | - |
3132 | -void click::Scope::run() |
3133 | -{ |
3134 | - static const int zero = 0; |
3135 | - auto emptyCb = [this]() |
3136 | - { |
3137 | - dm.reset(Ubuntu::DownloadManager::Manager::createSessionManager()); |
3138 | - qt_ready_for_search_p.set_value(); |
3139 | - |
3140 | - sso.reset(new click::CredentialsService()); |
3141 | - client->setCredentialsService(sso); |
3142 | - qt_ready_for_preview_p.set_value(); |
3143 | - }; |
3144 | - |
3145 | - qt::core::world::build_and_run(zero, nullptr, emptyCb); |
3146 | -} |
3147 | - |
3148 | -void click::Scope::stop() |
3149 | -{ |
3150 | - qt::core::world::destroy(); |
3151 | -} |
3152 | - |
3153 | -scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) |
3154 | -{ |
3155 | - return scopes::SearchQueryBase::UPtr(new click::Query(q, *index, *depts, depts_db, *highlights, metadata, |
3156 | - *pay_package, qt_ready_for_search_f.share())); |
3157 | -} |
3158 | - |
3159 | - |
3160 | -unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result, |
3161 | - const unity::scopes::ActionMetadata& metadata) { |
3162 | - qDebug() << "Scope::preview() called."; |
3163 | - auto preview = new click::Preview(result, metadata, qt_ready_for_preview_f.share()); |
3164 | - preview->choose_strategy(client, pay_package, dm, depts_db); |
3165 | - return unity::scopes::PreviewQueryBase::UPtr{preview}; |
3166 | -} |
3167 | - |
3168 | -unity::scopes::ActivationQueryBase::UPtr click::Scope::perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, |
3169 | - std::string const& widget_id, std::string const& _action_id) |
3170 | -{ |
3171 | - std::string action_id = _action_id; |
3172 | - qDebug() << "perform_action called with widget_id" << QString::fromStdString(widget_id) << "and action_id:" << QString::fromStdString(action_id); |
3173 | - auto activation = new ScopeActivation(result, metadata); |
3174 | - |
3175 | - // if the purchase is completed, do the install |
3176 | - if (action_id == "purchaseCompleted") { |
3177 | - qDebug() << "Yay, got finished signal"; |
3178 | - qDebug() << "about to get the download_url"; |
3179 | - std::string download_url = metadata.scope_data().get_dict()["download_url"].get_string(); |
3180 | - qDebug() << "the download url is: " << QString::fromStdString(download_url); |
3181 | - activation->setHint("download_url", unity::scopes::Variant(download_url)); |
3182 | - std::string download_sha512 = metadata.scope_data().get_dict()["download_sha512"].get_string(); |
3183 | - activation->setHint("download_sha512", unity::scopes::Variant(download_sha512)); |
3184 | - activation->setHint("action_id", unity::scopes::Variant(click::Preview::Actions::INSTALL_CLICK)); |
3185 | - activation->setHint("purchased", unity::scopes::Variant(true)); |
3186 | - qDebug() << "returning ShowPreview"; |
3187 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3188 | - } else if (action_id == "purchaseCancelled") { |
3189 | - qDebug() << "Purchase was cancelled, refreshing scope results."; |
3190 | - click::DownloadErrorPreview strategy{result}; |
3191 | - strategy.invalidateScope(STORE_SCOPE_ID.toUtf8().data()); |
3192 | - } else if (action_id == "purchaseError") { |
3193 | - activation->setHint(click::Preview::Actions::DOWNLOAD_FAILED, unity::scopes::Variant(true)); |
3194 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3195 | - } else if (action_id == click::Preview::Actions::INSTALL_CLICK) { |
3196 | - qDebug() << "about to get the download_url"; |
3197 | - std::string download_url = metadata.scope_data().get_dict()["download_url"].get_string(); |
3198 | - qDebug() << "the download url is: " << QString::fromStdString(download_url); |
3199 | - activation->setHint("download_url", unity::scopes::Variant(download_url)); |
3200 | - std::string download_sha512 = metadata.scope_data().get_dict()["download_sha512"].get_string(); |
3201 | - activation->setHint("download_sha512", unity::scopes::Variant(download_sha512)); |
3202 | - activation->setHint("action_id", unity::scopes::Variant(action_id)); |
3203 | - qDebug() << "returning ShowPreview"; |
3204 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3205 | - } else if (action_id == click::Preview::Actions::DOWNLOAD_FAILED) { |
3206 | - activation->setHint(click::Preview::Actions::DOWNLOAD_FAILED, unity::scopes::Variant(true)); |
3207 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3208 | - } else if (action_id == click::Preview::Actions::DOWNLOAD_COMPLETED) { |
3209 | - activation->setHint(click::Preview::Actions::DOWNLOAD_COMPLETED, unity::scopes::Variant(true)); |
3210 | - activation->setHint("installed", unity::scopes::Variant(true)); |
3211 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3212 | - } else if (action_id == click::Preview::Actions::CANCEL_PURCHASE_INSTALLED) { |
3213 | - activation->setHint(click::Preview::Actions::CANCEL_PURCHASE_INSTALLED, unity::scopes::Variant(true)); |
3214 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3215 | - } else if (action_id == click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED) { |
3216 | - activation->setHint(click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED, unity::scopes::Variant(true)); |
3217 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3218 | - } else if (action_id == click::Preview::Actions::UNINSTALL_CLICK) { |
3219 | - activation->setHint(click::Preview::Actions::UNINSTALL_CLICK, unity::scopes::Variant(true)); |
3220 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3221 | - } else if (action_id == click::Preview::Actions::SHOW_UNINSTALLED) { |
3222 | - activation->setHint(click::Preview::Actions::SHOW_UNINSTALLED, unity::scopes::Variant(true)); |
3223 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3224 | - } else if (action_id == click::Preview::Actions::SHOW_INSTALLED) { |
3225 | - activation->setHint(click::Preview::Actions::SHOW_INSTALLED, unity::scopes::Variant(true)); |
3226 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3227 | - } else if (action_id == click::Preview::Actions::CONFIRM_UNINSTALL) { |
3228 | - activation->setHint(click::Preview::Actions::CONFIRM_UNINSTALL, unity::scopes::Variant(true)); |
3229 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3230 | - } else if (action_id == click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED) { |
3231 | - activation->setHint(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED, unity::scopes::Variant(true)); |
3232 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3233 | - } else if (action_id == click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED) { |
3234 | - activation->setHint(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED, unity::scopes::Variant(true)); |
3235 | - activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
3236 | - } else if (action_id == click::Preview::Actions::RATED) { |
3237 | - scopes::VariantMap rating_info = metadata.scope_data().get_dict(); |
3238 | - // Cast to int because widget gives us double, which is wrong. |
3239 | - int rating = ((int)rating_info["rating"].get_double()); |
3240 | - std::string review_text = rating_info["review"].get_string(); |
3241 | - |
3242 | - // We have to get the values and then set them as hints here, to be |
3243 | - // able to pass them on to the Preview, which actually makes the |
3244 | - // call to submit. |
3245 | - activation->setHint("rating", scopes::Variant(rating)); |
3246 | - activation->setHint("review", scopes::Variant(review_text)); |
3247 | - activation->setHint(click::Preview::Actions::RATED, |
3248 | - scopes::Variant(true)); |
3249 | - activation->setHint("widget_id", scopes::Variant(widget_id)); |
3250 | - activation->setStatus(scopes::ActivationResponse::Status::ShowPreview); |
3251 | - } |
3252 | - return scopes::ActivationQueryBase::UPtr(activation); |
3253 | -} |
3254 | - |
3255 | -#define EXPORT __attribute__ ((visibility ("default"))) |
3256 | - |
3257 | -extern "C" |
3258 | -{ |
3259 | - |
3260 | - EXPORT |
3261 | - unity::scopes::ScopeBase* |
3262 | - // cppcheck-suppress unusedFunction |
3263 | - UNITY_SCOPE_CREATE_FUNCTION() |
3264 | - { |
3265 | - // Set up logging |
3266 | - UbuntuOne::AuthLogger::setupLogging(); |
3267 | -#if ENABLE_DEBUG |
3268 | - UbuntuOne::AuthLogger::setLogLevel(QtDebugMsg); |
3269 | -#else |
3270 | - const char* u1_debug = getenv("U1_DEBUG"); |
3271 | - if (u1_debug != NULL && strcmp(u1_debug, "") != 0) { |
3272 | - UbuntuOne::AuthLogger::setLogLevel(QtDebugMsg); |
3273 | - } |
3274 | -#endif |
3275 | - |
3276 | - return new click::Scope(); |
3277 | - } |
3278 | - |
3279 | - EXPORT |
3280 | - void |
3281 | - // cppcheck-suppress unusedFunction |
3282 | - UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base) |
3283 | - { |
3284 | - delete scope_base; |
3285 | - } |
3286 | - |
3287 | -} |
3288 | |
3289 | === removed file 'scope/clickstore/store-scope.h' |
3290 | --- scope/clickstore/store-scope.h 2016-05-25 16:19:58 +0000 |
3291 | +++ scope/clickstore/store-scope.h 1970-01-01 00:00:00 +0000 |
3292 | @@ -1,91 +0,0 @@ |
3293 | -/* |
3294 | - * Copyright (C) 2014 Canonical Ltd. |
3295 | - * |
3296 | - * This program is free software: you can redistribute it and/or modify it |
3297 | - * under the terms of the GNU General Public License version 3, as published |
3298 | - * by the Free Software Foundation. |
3299 | - * |
3300 | - * This program is distributed in the hope that it will be useful, but |
3301 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
3302 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3303 | - * PURPOSE. See the GNU General Public License for more details. |
3304 | - * |
3305 | - * You should have received a copy of the GNU General Public License along |
3306 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
3307 | - * |
3308 | - * In addition, as a special exception, the copyright holders give |
3309 | - * permission to link the code of portions of this program with the |
3310 | - * OpenSSL library under certain conditions as described in each |
3311 | - * individual source file, and distribute linked combinations |
3312 | - * including the two. |
3313 | - * You must obey the GNU General Public License in all respects |
3314 | - * for all of the code used other than OpenSSL. If you modify |
3315 | - * file(s) with this exception, you may extend this exception to your |
3316 | - * version of the file(s), but you are not obligated to do so. If you |
3317 | - * do not wish to do so, delete this exception statement from your |
3318 | - * version. If you delete this exception statement from all source |
3319 | - * files in the program, then also delete it here. |
3320 | - */ |
3321 | - |
3322 | -#ifndef CLICK_SCOPE_H |
3323 | -#define CLICK_SCOPE_H |
3324 | - |
3325 | -#include <click/pay.h> |
3326 | - |
3327 | -#include <memory> |
3328 | -#include <future> |
3329 | - |
3330 | -#include <click/network_access_manager.h> |
3331 | -#include <click/webclient.h> |
3332 | - |
3333 | -#include <ubuntu/download_manager/manager.h> |
3334 | -#include <unity/scopes/ScopeBase.h> |
3335 | -#include <unity/scopes/QueryBase.h> |
3336 | -#include <unity/scopes/ActivationQueryBase.h> |
3337 | - |
3338 | -#include <click/index.h> |
3339 | - |
3340 | -namespace scopes = unity::scopes; |
3341 | - |
3342 | -namespace click |
3343 | -{ |
3344 | - |
3345 | -class DepartmentLookup; |
3346 | -class DepartmentsDb; |
3347 | - |
3348 | -class Scope : public scopes::ScopeBase |
3349 | -{ |
3350 | -public: |
3351 | - Scope(); |
3352 | - ~Scope(); |
3353 | - |
3354 | - virtual void start(std::string const&) override; |
3355 | - |
3356 | - virtual void run() override; |
3357 | - virtual void stop() override; |
3358 | - |
3359 | - virtual scopes::SearchQueryBase::UPtr search(scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata) override; |
3360 | - unity::scopes::PreviewQueryBase::UPtr preview(const unity::scopes::Result&, |
3361 | - const unity::scopes::ActionMetadata&) override; |
3362 | - |
3363 | - virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override; |
3364 | - |
3365 | -private: |
3366 | - std::promise<void> qt_ready_for_search_p; |
3367 | - std::future<void> qt_ready_for_search_f; |
3368 | - std::promise<void> qt_ready_for_preview_p; |
3369 | - std::future<void> qt_ready_for_preview_f; |
3370 | - QSharedPointer<click::network::AccessManager> nam; |
3371 | - QSharedPointer<click::web::Client> client; |
3372 | - QSharedPointer<click::Index> index; |
3373 | - QSharedPointer<pay::Package> pay_package; |
3374 | - QSharedPointer<Ubuntu::DownloadManager::Manager> dm; |
3375 | - QSharedPointer<click::CredentialsService> sso; |
3376 | - std::shared_ptr<click::DepartmentLookup> depts; |
3377 | - std::shared_ptr<click::HighlightList> highlights; |
3378 | - std::shared_ptr<click::DepartmentsDb> depts_db; |
3379 | - |
3380 | - std::string installApplication(unity::scopes::Result const& result); |
3381 | -}; |
3382 | -} |
3383 | -#endif // CLICK_SCOPE_H |
3384 | |
3385 | === modified file 'scope/tests/CMakeLists.txt' |
3386 | --- scope/tests/CMakeLists.txt 2016-07-14 18:37:27 +0000 |
3387 | +++ scope/tests/CMakeLists.txt 2016-10-25 13:13:28 +0000 |
3388 | @@ -1,4 +1,3 @@ |
3389 | -set (CLICKSCOPE_TESTS_TARGET click-scope-tests) |
3390 | set (APPS_SCOPE_TESTS_TARGET apps-scope-tests) |
3391 | find_package(Threads) |
3392 | |
3393 | @@ -17,37 +16,13 @@ |
3394 | ${GMOCK_INCLUDE_DIR} |
3395 | ) |
3396 | |
3397 | -add_executable (${CLICKSCOPE_TESTS_TARGET} |
3398 | - test_query.cpp |
3399 | - test_store_scope.cpp |
3400 | - |
3401 | - ${CMAKE_SOURCE_DIR}/libclickscope/tests/fake_json.cpp |
3402 | -) |
3403 | - |
3404 | add_executable (${APPS_SCOPE_TESTS_TARGET} |
3405 | test_apps_query.cpp |
3406 | test_apps_scope.cpp |
3407 | ) |
3408 | |
3409 | -qt5_use_modules(${CLICKSCOPE_TESTS_TARGET} Core DBus Network Test Sql) |
3410 | qt5_use_modules(${APPS_SCOPE_TESTS_TARGET} Core DBus Network Test Sql) |
3411 | |
3412 | -target_link_libraries(${CLICKSCOPE_TESTS_TARGET} |
3413 | - ${STORE_LIB_UNVERSIONED} |
3414 | - ${SCOPE_LIB_NAME} |
3415 | - |
3416 | - ${UNITY_SCOPES_LDFLAGS} |
3417 | - ${UBUNTUONE_LDFLAGS} |
3418 | - ${UBUNTU_DOWNLOAD_MANAGER_CLIENT_LDFLAGS} |
3419 | - ${UBUNTU_DOWNLOAD_MANAGER_COMMON_LDFLAGS} |
3420 | - ${JSON_CPP_LDFLAGS} |
3421 | - |
3422 | - gmock |
3423 | - gmock_main |
3424 | - |
3425 | - ${CMAKE_THREAD_LIBS_INIT} |
3426 | -) |
3427 | - |
3428 | target_link_libraries(${APPS_SCOPE_TESTS_TARGET} |
3429 | ${APPS_LIB_UNVERSIONED} |
3430 | ${SCOPE_LIB_NAME} |
3431 | @@ -64,25 +39,6 @@ |
3432 | ${CMAKE_THREAD_LIBS_INIT} |
3433 | ) |
3434 | |
3435 | -add_custom_target (test-click-scope |
3436 | - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${CLICKSCOPE_TESTS_TARGET} |
3437 | - DEPENDS ${CLICKSCOPE_TESTS_TARGET} |
3438 | -) |
3439 | - |
3440 | -add_custom_target(test-click-scope-valgrind |
3441 | - COMMAND valgrind --tool=memcheck ${CMAKE_CURRENT_BINARY_DIR}/${CLICKSCOPE_TESTS_TARGET} |
3442 | - DEPENDS ${CLICKSCOPE_TESTS_TARGET} |
3443 | -) |
3444 | - |
3445 | -add_custom_target(test-click-scope-leaks |
3446 | - COMMAND valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${CLICKSCOPE_TESTS_TARGET} |
3447 | - DEPENDS ${CLICKSCOPE_TESTS_TARGET} |
3448 | -) |
3449 | -add_custom_target (test-click-scope-disabled |
3450 | - COMMAND GTEST_ALSO_RUN_DISABLED_TESTS=1 ${CMAKE_CURRENT_BINARY_DIR}/${CLICKSCOPE_TESTS_TARGET} |
3451 | - DEPENDS ${CLICKSCOPE_TESTS_TARGET} |
3452 | -) |
3453 | - |
3454 | # --- |
3455 | |
3456 | set(TEST_SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
3457 | @@ -115,6 +71,3 @@ |
3458 | COMMAND GTEST_ALSO_RUN_DISABLED_TESTS=1 ${CMAKE_CURRENT_BINARY_DIR}/${APPS_SCOPE_TESTS_TARGET} |
3459 | DEPENDS ${APPS_SCOPE_TESTS_TARGET} |
3460 | ) |
3461 | - |
3462 | - |
3463 | -add_subdirectory(fake_launcher) |
3464 | |
3465 | === removed directory 'scope/tests/fake_launcher' |
3466 | === removed file 'scope/tests/fake_launcher/CMakeLists.txt' |
3467 | --- scope/tests/fake_launcher/CMakeLists.txt 2015-05-20 19:58:45 +0000 |
3468 | +++ scope/tests/fake_launcher/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
3469 | @@ -1,14 +0,0 @@ |
3470 | -set(FAKE_LAUNCHER_TARGET fake_launcher) |
3471 | - |
3472 | -include_directories ( |
3473 | - ${CMAKE_SOURCE_DIR}/scope/click |
3474 | -) |
3475 | - |
3476 | -add_executable (${FAKE_LAUNCHER_TARGET} |
3477 | - fake_launcher.cpp |
3478 | - fake_launcher.h |
3479 | -) |
3480 | - |
3481 | -target_link_libraries (${FAKE_LAUNCHER_TARGET} |
3482 | - ${STORE_LIB_UNVERSIONED} |
3483 | -) |
3484 | |
3485 | === removed file 'scope/tests/fake_launcher/fake_launcher.cpp' |
3486 | --- scope/tests/fake_launcher/fake_launcher.cpp 2014-06-18 04:39:23 +0000 |
3487 | +++ scope/tests/fake_launcher/fake_launcher.cpp 1970-01-01 00:00:00 +0000 |
3488 | @@ -1,118 +0,0 @@ |
3489 | -/* |
3490 | - * Copyright (C) 2014 Canonical Ltd. |
3491 | - * |
3492 | - * This program is free software: you can redistribute it and/or modify it |
3493 | - * under the terms of the GNU General Public License version 3, as published |
3494 | - * by the Free Software Foundation. |
3495 | - * |
3496 | - * This program is distributed in the hope that it will be useful, but |
3497 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
3498 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3499 | - * PURPOSE. See the GNU General Public License for more details. |
3500 | - * |
3501 | - * You should have received a copy of the GNU General Public License along |
3502 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
3503 | - * |
3504 | - * In addition, as a special exception, the copyright holders give |
3505 | - * permission to link the code of portions of this program with the |
3506 | - * OpenSSL library under certain conditions as described in each |
3507 | - * individual source file, and distribute linked combinations |
3508 | - * including the two. |
3509 | - * You must obey the GNU General Public License in all respects |
3510 | - * for all of the code used other than OpenSSL. If you modify |
3511 | - * file(s) with this exception, you may extend this exception to your |
3512 | - * version of the file(s), but you are not obligated to do so. If you |
3513 | - * do not wish to do so, delete this exception statement from your |
3514 | - * version. If you delete this exception statement from all source |
3515 | - * files in the program, then also delete it here. |
3516 | - */ |
3517 | - |
3518 | -#include <ubuntu/download_manager/download.h> |
3519 | -#include <ubuntu/download_manager/downloads_list.h> |
3520 | -#include <ubuntu/download_manager/error.h> |
3521 | - |
3522 | -#include <QCoreApplication> |
3523 | -#include <QDBusConnection> |
3524 | -#include <QDebug> |
3525 | -#include <QString> |
3526 | -#include <QTimer> |
3527 | -#include <QTextStream> |
3528 | - |
3529 | -#include <iostream> |
3530 | - |
3531 | -#include <boost/optional.hpp> |
3532 | - |
3533 | -#include <fake_launcher.h> |
3534 | - |
3535 | -void FakeLauncher::startInstallation(QString title, QString icon_url, QString package_name) |
3536 | -{ |
3537 | - qDebug() << "startInstallation" << title << icon_url << package_name; |
3538 | - installations.insert(package_name, new FakeIcon(title, icon_url, this)); |
3539 | - manager->getAllDownloadsWithMetadata("package_name", package_name); |
3540 | -} |
3541 | - |
3542 | -void FakeLauncher::handleDownloadsFound(const QString& key, const QString& value, DownloadsList *download_list) |
3543 | -{ |
3544 | - Q_UNUSED(key) |
3545 | - Q_UNUSED(value) |
3546 | - foreach (const QSharedPointer<Download> download, download_list->downloads()) { |
3547 | - QString package_name{download->metadata()["package_name"].toString()}; |
3548 | - qDebug() << "download found for" << package_name; |
3549 | - installations[package_name]->downloadFound(*download); |
3550 | - } |
3551 | -} |
3552 | - |
3553 | -void FakeLauncher::completeInstallation(QString package_name, QString app_id) |
3554 | -{ |
3555 | - qDebug() << "completeInstallation" << package_name << app_id; |
3556 | - installations[package_name]->complete(app_id); |
3557 | -} |
3558 | - |
3559 | -void FakeIcon::downloadFound(Download& download) |
3560 | -{ |
3561 | - connect(&download, SIGNAL(progress(qulonglong,qulonglong)), this, SLOT(handleProgress(qulonglong,qulonglong))); |
3562 | - connect(&download, SIGNAL(error(Error*)), this, SLOT(handleDownloadError(Error*))); |
3563 | - qDebug() << title << "starting installation"; |
3564 | - // TODO: add icon to the launcher |
3565 | -} |
3566 | - |
3567 | -void FakeIcon::handleProgress(qulonglong transferred, qulonglong total) |
3568 | -{ |
3569 | - qDebug() << title << "download progress" << double(transferred)/total*80; |
3570 | - // TODO: update progress bar |
3571 | -} |
3572 | - |
3573 | -void FakeIcon::handleDownloadError(Error *error) |
3574 | -{ |
3575 | - failure(error->errorString()); |
3576 | -} |
3577 | - |
3578 | -void FakeIcon::failure(QString message) |
3579 | -{ |
3580 | - qDebug() << title << "installation failed" << message; |
3581 | - // TODO: remove icon from the launcher |
3582 | -} |
3583 | - |
3584 | -void FakeIcon::complete(QString app_id) |
3585 | -{ |
3586 | - if (app_id.isEmpty()) { |
3587 | - failure("Failed to install"); |
3588 | - } else { |
3589 | - qDebug() << title << "installation completed" << app_id; |
3590 | - // TODO: update icon with proper app_id |
3591 | - } |
3592 | -} |
3593 | - |
3594 | -int main(int argc, char *argv[]) |
3595 | -{ |
3596 | - |
3597 | - QCoreApplication app(argc, argv); |
3598 | - FakeLauncher launcher; |
3599 | - new FakeLauncherAdaptor(&launcher); |
3600 | - qDebug() << "starting"; |
3601 | - auto bus = QDBusConnection::sessionBus(); |
3602 | - bus.registerObject(LAUNCHER_OBJECT_PATH, &launcher); |
3603 | - bus.registerService(LAUNCHER_BUSNAME); |
3604 | - return app.exec(); |
3605 | -} |
3606 | - |
3607 | |
3608 | === removed file 'scope/tests/fake_launcher/fake_launcher.h' |
3609 | --- scope/tests/fake_launcher/fake_launcher.h 2014-06-18 04:39:23 +0000 |
3610 | +++ scope/tests/fake_launcher/fake_launcher.h 1970-01-01 00:00:00 +0000 |
3611 | @@ -1,116 +0,0 @@ |
3612 | -/* |
3613 | - * Copyright (C) 2014 Canonical Ltd. |
3614 | - * |
3615 | - * This program is free software: you can redistribute it and/or modify it |
3616 | - * under the terms of the GNU General Public License version 3, as published |
3617 | - * by the Free Software Foundation. |
3618 | - * |
3619 | - * This program is distributed in the hope that it will be useful, but |
3620 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
3621 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3622 | - * PURPOSE. See the GNU General Public License for more details. |
3623 | - * |
3624 | - * You should have received a copy of the GNU General Public License along |
3625 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
3626 | - * |
3627 | - * In addition, as a special exception, the copyright holders give |
3628 | - * permission to link the code of portions of this program with the |
3629 | - * OpenSSL library under certain conditions as described in each |
3630 | - * individual source file, and distribute linked combinations |
3631 | - * including the two. |
3632 | - * You must obey the GNU General Public License in all respects |
3633 | - * for all of the code used other than OpenSSL. If you modify |
3634 | - * file(s) with this exception, you may extend this exception to your |
3635 | - * version of the file(s), but you are not obligated to do so. If you |
3636 | - * do not wish to do so, delete this exception statement from your |
3637 | - * version. If you delete this exception statement from all source |
3638 | - * files in the program, then also delete it here. |
3639 | - */ |
3640 | - |
3641 | -#ifndef _FAKE_LAUNCHER_H_ |
3642 | -#define _FAKE_LAUNCHER_H_ |
3643 | - |
3644 | -#include <QObject> |
3645 | -#include <QDBusObjectPath> |
3646 | -#include <QDBusAbstractAdaptor> |
3647 | - |
3648 | -#include <click/dbus_constants.h> |
3649 | -#include <ubuntu/download_manager/manager.h> |
3650 | - |
3651 | -class FakeIcon : public QObject { |
3652 | - Q_OBJECT |
3653 | - |
3654 | -public: |
3655 | - explicit FakeIcon(QString title, QString icon_url, QObject *parent=0) |
3656 | - : QObject(parent), title(title), icon_url(icon_url) |
3657 | - { |
3658 | - } |
3659 | - void downloadFound(Download& download); |
3660 | - void complete(QString app_id); |
3661 | - |
3662 | -private slots: |
3663 | - void handleProgress(qulonglong transferred, qulonglong total); |
3664 | - void handleDownloadError(Error* error); |
3665 | - |
3666 | -private: |
3667 | - Download* download; |
3668 | - QString title; |
3669 | - QString icon_url; |
3670 | - void failure(QString message); |
3671 | -}; |
3672 | - |
3673 | -class FakeLauncher : public QObject { |
3674 | - Q_OBJECT |
3675 | - |
3676 | -public: |
3677 | - explicit FakeLauncher(QObject *parent=0) : QObject(parent) |
3678 | - { |
3679 | - manager = Ubuntu::DownloadManager::Manager::createSessionManager(); |
3680 | - connect(manager, SIGNAL(downloadsWithMetadataFound(QString,QString,DownloadsList*)), |
3681 | - this, SLOT(handleDownloadsFound(QString,QString,DownloadsList*))); |
3682 | - } |
3683 | - |
3684 | -public slots: |
3685 | - void startInstallation(QString title, QString icon_url, QString package_name); |
3686 | - void completeInstallation(QString package_name, QString app_id); |
3687 | - |
3688 | -private slots: |
3689 | - void handleDownloadsFound(const QString& key, const QString& value, DownloadsList* downloads); |
3690 | - |
3691 | -signals: |
3692 | - |
3693 | -private: |
3694 | - Ubuntu::DownloadManager::Manager* manager; |
3695 | - QMap<QString, FakeIcon*> installations; |
3696 | -}; |
3697 | - |
3698 | - |
3699 | -class FakeLauncherAdaptor : public QDBusAbstractAdaptor |
3700 | -{ |
3701 | - Q_OBJECT |
3702 | - Q_CLASSINFO("D-Bus Interface", LAUNCHER_INTERFACE) |
3703 | - |
3704 | -private: |
3705 | - FakeLauncher *_launcher; |
3706 | - |
3707 | -public: |
3708 | - FakeLauncherAdaptor(FakeLauncher *launcher) : QDBusAbstractAdaptor(launcher), _launcher(launcher) |
3709 | - { |
3710 | - } |
3711 | - |
3712 | -public slots: |
3713 | - Q_NOREPLY void startInstallation(QString title, QString icon_url, QString package_name) |
3714 | - { |
3715 | - _launcher->startInstallation(title, icon_url, package_name); |
3716 | - } |
3717 | - |
3718 | - Q_NOREPLY void completeInstallation(QString package_name, QString app_id) |
3719 | - { |
3720 | - _launcher->completeInstallation(package_name, app_id); |
3721 | - } |
3722 | -}; |
3723 | - |
3724 | - |
3725 | -#endif /* _FAKE_LAUNCHER_H_ */ |
3726 | - |
3727 | - |
3728 | |
3729 | === modified file 'scope/tests/test_query.cpp' |
3730 | --- scope/tests/test_query.cpp 2015-12-01 15:39:41 +0000 |
3731 | +++ scope/tests/test_query.cpp 2016-10-25 13:13:28 +0000 |
3732 | @@ -27,8 +27,6 @@ |
3733 | * files in the program, then also delete it here. |
3734 | */ |
3735 | |
3736 | -#include <tests/mock_pay.h> |
3737 | - |
3738 | #include "clickstore/store-query.h" |
3739 | |
3740 | #include <string> |
3741 | @@ -137,10 +135,9 @@ |
3742 | click::DepartmentLookup dept_lookup; |
3743 | click::HighlightList highlights; |
3744 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3745 | - MockPayPackage pay_pkg; |
3746 | PackageSet no_installed_packages; |
3747 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3748 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3749 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3750 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)).Times(1); |
3751 | |
3752 | scopes::testing::MockSearchReply mock_reply; |
3753 | @@ -164,10 +161,9 @@ |
3754 | click::DepartmentLookup dept_lookup; |
3755 | click::HighlightList highlights; |
3756 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3757 | - MockPayPackage pay_pkg; |
3758 | PackageSet no_installed_packages; |
3759 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3760 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3761 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3762 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3763 | |
3764 | scopes::CategoryRenderer renderer("{}"); |
3765 | @@ -195,10 +191,9 @@ |
3766 | click::DepartmentLookup dept_lookup; |
3767 | click::HighlightList highlights; |
3768 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3769 | - MockPayPackage pay_pkg; |
3770 | PackageSet no_installed_packages; |
3771 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3772 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3773 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3774 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3775 | |
3776 | scopes::CategoryRenderer renderer("{}"); |
3777 | @@ -221,10 +216,9 @@ |
3778 | click::DepartmentLookup dept_lookup; |
3779 | click::HighlightList highlights; |
3780 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3781 | - MockPayPackage pay_pkg; |
3782 | PackageSet no_installed_packages; |
3783 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3784 | - MockQueryRun q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3785 | + MockQueryRun q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3786 | auto reply = scopes::SearchReplyProxy(); |
3787 | EXPECT_CALL(q, get_installed_packages()).WillOnce(Return(no_installed_packages)); |
3788 | EXPECT_CALL(q, add_available_apps(reply, no_installed_packages, _)); |
3789 | @@ -251,9 +245,8 @@ |
3790 | }; |
3791 | click::DepartmentLookup dept_lookup; |
3792 | click::HighlightList highlights; |
3793 | - MockPayPackage pay_pkg; |
3794 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3795 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3796 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3797 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3798 | |
3799 | scopes::CategoryRenderer renderer("{}"); |
3800 | @@ -283,9 +276,8 @@ |
3801 | }; |
3802 | click::DepartmentLookup dept_lookup; |
3803 | click::HighlightList highlights; |
3804 | - MockPayPackage pay_pkg; |
3805 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3806 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3807 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3808 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3809 | |
3810 | scopes::CategoryRenderer renderer("{}"); |
3811 | @@ -322,9 +314,8 @@ |
3812 | }; |
3813 | click::DepartmentLookup dept_lookup; |
3814 | click::HighlightList highlights; |
3815 | - MockPayPackage pay_pkg; |
3816 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3817 | - MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata, pay_pkg); |
3818 | + MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata); |
3819 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3820 | |
3821 | scopes::CategoryRenderer renderer("{}"); |
3822 | @@ -348,9 +339,8 @@ |
3823 | |
3824 | click::DepartmentLookup dept_lookup; |
3825 | click::HighlightList highlights; |
3826 | - MockPayPackage pay_pkg; |
3827 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "1"); |
3828 | - MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata, pay_pkg); |
3829 | + MockQuery q(query, mock_index, dept_lookup, depts_db, highlights, metadata); |
3830 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, "1", _)); |
3831 | |
3832 | scopes::CategoryRenderer renderer("{}"); |
3833 | @@ -380,9 +370,8 @@ |
3834 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3835 | click::DepartmentLookup dept_lookup; |
3836 | click::HighlightList highlights; |
3837 | - MockPayPackage pay_pkg; |
3838 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3839 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3840 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3841 | PackageSet installed_packages{{"package_1", "0.1"}}; |
3842 | |
3843 | FakeInterface fake_interface; |
3844 | @@ -408,10 +397,9 @@ |
3845 | click::DepartmentLookup dept_lookup; |
3846 | click::HighlightList highlights; |
3847 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3848 | - MockPayPackage pay_pkg; |
3849 | PackageSet no_installed_packages; |
3850 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3851 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3852 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3853 | q.purchased_apps.insert({"name"}); |
3854 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3855 | |
3856 | @@ -445,9 +433,8 @@ |
3857 | click::DepartmentLookup dept_lookup; |
3858 | click::HighlightList highlights; |
3859 | scopes::SearchMetadata metadata("en_EN", "phone"); |
3860 | - MockPayPackage pay_pkg; |
3861 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3862 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3863 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3864 | q.purchased_apps.insert({"name"}); |
3865 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3866 | |
3867 | @@ -481,9 +468,8 @@ |
3868 | PackageSet no_installed_packages; |
3869 | click::DepartmentLookup dept_lookup; |
3870 | click::HighlightList highlights; |
3871 | - MockPayPackage pay_pkg; |
3872 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3873 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3874 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3875 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3876 | |
3877 | scopes::CategoryRenderer renderer("{}"); |
3878 | @@ -513,9 +499,8 @@ |
3879 | PackageSet no_installed_packages; |
3880 | click::DepartmentLookup dept_lookup; |
3881 | click::HighlightList highlights; |
3882 | - MockPayPackage pay_pkg; |
3883 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3884 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3885 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3886 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3887 | |
3888 | scopes::CategoryRenderer renderer("{}"); |
3889 | @@ -546,9 +531,8 @@ |
3890 | PackageSet no_installed_packages; |
3891 | click::DepartmentLookup dept_lookup; |
3892 | click::HighlightList highlights; |
3893 | - MockPayPackage pay_pkg; |
3894 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3895 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3896 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3897 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3898 | |
3899 | scopes::CategoryRenderer renderer("{}"); |
3900 | @@ -581,9 +565,8 @@ |
3901 | PackageSet no_installed_packages; |
3902 | DepartmentLookup dept_lookup; |
3903 | HighlightList highlights; |
3904 | - MockPayPackage pay_pkg; |
3905 | const unity::scopes::CannedQuery query("foo.scope", "", ""); |
3906 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3907 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3908 | |
3909 | scopes::CategoryRenderer renderer("{}"); |
3910 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
3911 | @@ -613,9 +596,8 @@ |
3912 | PackageSet no_installed_packages; |
3913 | DepartmentLookup dept_lookup; |
3914 | HighlightList highlights; |
3915 | - MockPayPackage pay_pkg; |
3916 | const unity::scopes::CannedQuery query("foo.scope", "", ""); |
3917 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3918 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3919 | |
3920 | scopes::CategoryRenderer renderer("{}"); |
3921 | auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer); |
3922 | @@ -642,9 +624,8 @@ |
3923 | PackageSet no_installed_packages; |
3924 | click::DepartmentLookup dept_lookup; |
3925 | click::HighlightList highlights; |
3926 | - MockPayPackage pay_pkg; |
3927 | const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, ""); |
3928 | - MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg); |
3929 | + MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata); |
3930 | EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _, _)); |
3931 | |
3932 | scopes::CategoryRenderer renderer("{}"); |
3933 | |
3934 | === removed file 'scope/tests/test_store_scope.cpp' |
3935 | --- scope/tests/test_store_scope.cpp 2015-11-24 18:23:23 +0000 |
3936 | +++ scope/tests/test_store_scope.cpp 1970-01-01 00:00:00 +0000 |
3937 | @@ -1,178 +0,0 @@ |
3938 | -/* |
3939 | - * Copyright (C) 2014-2015 Canonical Ltd. |
3940 | - * |
3941 | - * This program is free software: you can redistribute it and/or modify it |
3942 | - * under the terms of the GNU General Public License version 3, as published |
3943 | - * by the Free Software Foundation. |
3944 | - * |
3945 | - * This program is distributed in the hope that it will be useful, but |
3946 | - * WITHOUT ANY WARRANTY; without even the implied warranties of |
3947 | - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3948 | - * PURPOSE. See the GNU General Public License for more details. |
3949 | - * |
3950 | - * You should have received a copy of the GNU General Public License along |
3951 | - * with this program. If not, see <http://www.gnu.org/licenses/>. |
3952 | - * |
3953 | - * In addition, as a special exception, the copyright holders give |
3954 | - * permission to link the code of portions of this program with the |
3955 | - * OpenSSL library under certain conditions as described in each |
3956 | - * individual source file, and distribute linked combinations |
3957 | - * including the two. |
3958 | - * You must obey the GNU General Public License in all respects |
3959 | - * for all of the code used other than OpenSSL. If you modify |
3960 | - * file(s) with this exception, you may extend this exception to your |
3961 | - * version of the file(s), but you are not obligated to do so. If you |
3962 | - * do not wish to do so, delete this exception statement from your |
3963 | - * version. If you delete this exception statement from all source |
3964 | - * files in the program, then also delete it here. |
3965 | - */ |
3966 | - |
3967 | -#include <gtest/gtest.h> |
3968 | -#include <gmock/gmock.h> |
3969 | - |
3970 | -#include <unity/scopes/testing/Result.h> |
3971 | - |
3972 | -#include <click/preview.h> |
3973 | -#include <clickstore/store-scope.h> |
3974 | - |
3975 | -using namespace ::testing; |
3976 | - |
3977 | -class StoreScopeTest : public Test { |
3978 | -protected: |
3979 | - const std::string FAKE_SHA512 = "FAKE_SHA512"; |
3980 | - click::Scope scope; |
3981 | - unity::scopes::testing::Result result; |
3982 | - unity::scopes::ActionMetadata metadata; |
3983 | - unity::scopes::VariantMap metadict; |
3984 | - |
3985 | -public: |
3986 | - StoreScopeTest() : metadata("en_EN", "phone") { |
3987 | - metadict["download_url"] = "fake_download_url"; |
3988 | - metadict["download_sha512"] = FAKE_SHA512; |
3989 | - metadict["rating"] = unity::scopes::Variant(4.0f); |
3990 | - metadict["review"] = "This is a review."; |
3991 | - metadata.set_scope_data(unity::scopes::Variant(metadict)); |
3992 | - } |
3993 | -}; |
3994 | - |
3995 | -TEST_F(StoreScopeTest, testPurchaseCompletedPassesHash) |
3996 | -{ |
3997 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
3998 | - "purchaseCompleted"); |
3999 | - auto response = activation->activate(); |
4000 | - EXPECT_EQ(FAKE_SHA512, response.scope_data().get_dict()["download_sha512"].get_string()); |
4001 | - EXPECT_TRUE(response.scope_data().get_dict()["purchased"].get_bool()); |
4002 | -} |
4003 | - |
4004 | -TEST_F(StoreScopeTest, testPurchaseError) |
4005 | -{ |
4006 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4007 | - "purchaseError"); |
4008 | - auto response = activation->activate(); |
4009 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::DOWNLOAD_FAILED].get_bool()); |
4010 | -} |
4011 | - |
4012 | -TEST_F(StoreScopeTest, testInstallClickPassesHash) |
4013 | -{ |
4014 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4015 | - click::Preview::Actions::INSTALL_CLICK); |
4016 | - auto response = activation->activate(); |
4017 | - EXPECT_EQ(FAKE_SHA512, response.scope_data().get_dict()["download_sha512"].get_string()); |
4018 | -} |
4019 | - |
4020 | -TEST_F(StoreScopeTest, testDownloadFailed) |
4021 | -{ |
4022 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4023 | - click::Preview::Actions::DOWNLOAD_FAILED); |
4024 | - auto response = activation->activate(); |
4025 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::DOWNLOAD_FAILED].get_bool()); |
4026 | -} |
4027 | - |
4028 | -TEST_F(StoreScopeTest, testDownloadCompleted) |
4029 | -{ |
4030 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4031 | - click::Preview::Actions::DOWNLOAD_COMPLETED); |
4032 | - auto response = activation->activate(); |
4033 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::DOWNLOAD_COMPLETED].get_bool()); |
4034 | - EXPECT_TRUE(response.scope_data().get_dict()["installed"].get_bool()); |
4035 | -} |
4036 | - |
4037 | -TEST_F(StoreScopeTest, testCancelPurchaseInstalled) |
4038 | -{ |
4039 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4040 | - click::Preview::Actions::CANCEL_PURCHASE_INSTALLED); |
4041 | - auto response = activation->activate(); |
4042 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::CANCEL_PURCHASE_INSTALLED].get_bool()); |
4043 | -} |
4044 | - |
4045 | -TEST_F(StoreScopeTest, testCancelPurchaseUninstalled) |
4046 | -{ |
4047 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4048 | - click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED); |
4049 | - auto response = activation->activate(); |
4050 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED].get_bool()); |
4051 | -} |
4052 | - |
4053 | -TEST_F(StoreScopeTest, testUninstallClick) |
4054 | -{ |
4055 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4056 | - click::Preview::Actions::UNINSTALL_CLICK); |
4057 | - auto response = activation->activate(); |
4058 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::UNINSTALL_CLICK].get_bool()); |
4059 | -} |
4060 | - |
4061 | -TEST_F(StoreScopeTest, testShowUninstalled) |
4062 | -{ |
4063 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4064 | - click::Preview::Actions::SHOW_UNINSTALLED); |
4065 | - auto response = activation->activate(); |
4066 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::SHOW_UNINSTALLED].get_bool()); |
4067 | -} |
4068 | - |
4069 | -TEST_F(StoreScopeTest, testShowInstalled) |
4070 | -{ |
4071 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4072 | - click::Preview::Actions::SHOW_INSTALLED); |
4073 | - auto response = activation->activate(); |
4074 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::SHOW_INSTALLED].get_bool()); |
4075 | -} |
4076 | - |
4077 | -TEST_F(StoreScopeTest, testConfirmUninstall) |
4078 | -{ |
4079 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4080 | - click::Preview::Actions::CONFIRM_UNINSTALL); |
4081 | - auto response = activation->activate(); |
4082 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::CONFIRM_UNINSTALL].get_bool()); |
4083 | -} |
4084 | - |
4085 | -TEST_F(StoreScopeTest, testConfirmCancelPurchaseUninstalled) |
4086 | -{ |
4087 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4088 | - click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED); |
4089 | - auto response = activation->activate(); |
4090 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED].get_bool()); |
4091 | -} |
4092 | - |
4093 | -TEST_F(StoreScopeTest, testConfirmCancelPurcahseInstalled) |
4094 | -{ |
4095 | - auto activation = scope.perform_action(result, metadata, "widget_id", |
4096 | - click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED); |
4097 | - auto response = activation->activate(); |
4098 | - EXPECT_TRUE(response.scope_data().get_dict()[click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED].get_bool()); |
4099 | -} |
4100 | - |
4101 | -TEST_F(StoreScopeTest, testStoreScopeRatingNew) |
4102 | -{ |
4103 | - auto activation = scope.perform_action(result, metadata, "rating", |
4104 | - click::Preview::Actions::RATED); |
4105 | - auto response = activation->activate(); |
4106 | - EXPECT_EQ("rating", response.scope_data().get_dict()["widget_id"].get_string()); |
4107 | -} |
4108 | - |
4109 | -TEST_F(StoreScopeTest, testStoreScopeRatingEdit) |
4110 | -{ |
4111 | - auto activation = scope.perform_action(result, metadata, "93345", |
4112 | - click::Preview::Actions::RATED); |
4113 | - auto response = activation->activate(); |
4114 | - EXPECT_EQ("93345", response.scope_data().get_dict()["widget_id"].get_string()); |
4115 | -} |
FAILED: Continuous integration, rev:494 /jenkins. canonical. com/unity- api-1/job/ lp-unity- scope-click- ci/120/ /jenkins. canonical. com/unity- api-1/job/ build/908/ console /jenkins. canonical. com/unity- api-1/job/ build-0- fetch/915 /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=amd64, release= yakkety/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=armhf, release= yakkety/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 718/console /jenkins. canonical. com/unity- api-1/job/ build-2- binpkg/ arch=i386, release= yakkety/ 718/console
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/unity- api-1/job/ lp-unity- scope-click- ci/120/ rebuild
https:/