Merge lp:~dobey/unity-scope-click/fix-the-flow into lp:unity-scope-click
- fix-the-flow
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | 352 |
Merged at revision: | 335 |
Proposed branch: | lp:~dobey/unity-scope-click/fix-the-flow |
Merge into: | lp:unity-scope-click |
Diff against target: |
703 lines (+137/-103) 11 files modified
libclickscope/click/pay.cpp (+18/-6) libclickscope/click/pay.h (+1/-1) libclickscope/click/preview.cpp (+56/-31) libclickscope/click/preview.h (+17/-6) libclickscope/tests/mock_pay.h (+8/-0) libclickscope/tests/test_pay.cpp (+0/-2) libclickscope/tests/test_preview.cpp (+27/-53) scope/clickapps/apps-scope.cpp (+3/-1) scope/clickapps/apps-scope.h (+3/-1) scope/clickstore/store-scope.cpp (+3/-1) scope/clickstore/store-scope.h (+1/-1) |
To merge this branch: | bzr merge lp:~dobey/unity-scope-click/fix-the-flow |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Charles Kerr (community) | Approve | ||
Review via email: mp+263387@code.launchpad.net |
Commit message
Ensure 'Cancel Purchase' button is shown immediately after a purchase.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:345
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:346
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:347
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:348
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:349
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Charles Kerr (charlesk) wrote : | # |
r351 is an abomination, we must revisit this after the deadline and fix the libpay internals so that this isn't needed. :-)
Still, I agree with this as a short-term workaround to ensure that is_refundable() hits a fresh cache so that it uses the right state to determine if things are refundable or not.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:350
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'libclickscope/click/pay.cpp' |
2 | --- libclickscope/click/pay.cpp 2015-06-17 16:32:08 +0000 |
3 | +++ libclickscope/click/pay.cpp 2015-07-02 22:21:56 +0000 |
4 | @@ -36,6 +36,7 @@ |
5 | |
6 | #include <glib.h> |
7 | #include <libpay/pay-package.h> |
8 | +#include <unistd.h> |
9 | |
10 | #include <QDebug> |
11 | |
12 | @@ -110,11 +111,6 @@ |
13 | return lhs.name == rhs.name; |
14 | } |
15 | |
16 | -Package& Package::instance() { |
17 | - static Package the_instance; |
18 | - return the_instance; |
19 | -} |
20 | - |
21 | Package::Package() : impl(new Private()) |
22 | { |
23 | } |
24 | @@ -201,6 +197,23 @@ |
25 | return false; |
26 | } |
27 | |
28 | +bool Package::is_refundable(const std::string& pkg_name) |
29 | +{ |
30 | + if (!running) { |
31 | + setup_pay_service(); |
32 | + } |
33 | + |
34 | + if (verify(pkg_name)) { |
35 | + // No Hondas, why racing? Wait for it… |
36 | + usleep(10000); |
37 | + |
38 | + return pay_package_item_is_refundable(impl->pay_package, |
39 | + pkg_name.c_str()) == 0 ? false : true; |
40 | + } |
41 | + // If verify() returned false, then it's not purchased. |
42 | + return false; |
43 | +} |
44 | + |
45 | time_t parse_timestamp(json::Value v) |
46 | { |
47 | if (v.isNull()) { |
48 | @@ -213,7 +226,6 @@ |
49 | return when.toTime_t(); |
50 | } |
51 | |
52 | - |
53 | click::web::Cancellable Package::get_purchases(std::function<void(const PurchaseSet&)> callback) |
54 | { |
55 | QSharedPointer<click::CredentialsService> sso(new click::CredentialsService()); |
56 | |
57 | === modified file 'libclickscope/click/pay.h' |
58 | --- libclickscope/click/pay.h 2015-06-17 16:27:26 +0000 |
59 | +++ libclickscope/click/pay.h 2015-07-02 22:21:56 +0000 |
60 | @@ -102,9 +102,9 @@ |
61 | |
62 | virtual bool refund(const std::string& pkg_name); |
63 | virtual bool verify(const std::string& pkg_name); |
64 | + virtual bool is_refundable(const std::string& pkg_name); |
65 | virtual click::web::Cancellable get_purchases(std::function<void(const PurchaseSet& purchased_apps)> callback); |
66 | static std::string get_base_url(); |
67 | - static Package& instance(); |
68 | |
69 | protected: |
70 | virtual void setup_pay_service(); |
71 | |
72 | === modified file 'libclickscope/click/preview.cpp' |
73 | --- libclickscope/click/preview.cpp 2015-06-17 16:59:14 +0000 |
74 | +++ libclickscope/click/preview.cpp 2015-07-02 22:21:56 +0000 |
75 | @@ -103,9 +103,10 @@ |
76 | |
77 | void Preview::choose_strategy(const QSharedPointer<web::Client> &client, |
78 | const QSharedPointer<click::network::AccessManager>& nam, |
79 | + const QSharedPointer<pay::Package>& ppackage, |
80 | std::shared_ptr<click::DepartmentsDb> depts) |
81 | { |
82 | - strategy.reset(build_strategy(result, metadata, client, nam, depts)); |
83 | + strategy.reset(build_strategy(result, metadata, client, nam, ppackage, depts)); |
84 | } |
85 | |
86 | PreviewStrategy* Preview::build_installing(const std::string& download_url, |
87 | @@ -120,9 +121,10 @@ |
88 | |
89 | |
90 | PreviewStrategy* Preview::build_strategy(const unity::scopes::Result &result, |
91 | - const unity::scopes::ActionMetadata &metadata, |
92 | - const QSharedPointer<web::Client> &client, |
93 | - const QSharedPointer<click::network::AccessManager>& nam, |
94 | + const unity::scopes::ActionMetadata &metadata, |
95 | + const QSharedPointer<web::Client> &client, |
96 | + const QSharedPointer<click::network::AccessManager>& nam, |
97 | + const QSharedPointer<pay::Package>& ppackage, |
98 | std::shared_ptr<click::DepartmentsDb> depts) |
99 | { |
100 | if (metadata.scope_data().which() != scopes::Variant::Type::Null) { |
101 | @@ -137,7 +139,7 @@ |
102 | << " and close_preview=" |
103 | << metadict.count(click::Preview::Actions::SHOW_INSTALLED); |
104 | |
105 | - return new InstalledPreview(result, metadata, client, depts); |
106 | + return new InstalledPreview(result, metadata, client, ppackage, depts); |
107 | } else if (metadict.count("action_id") != 0 && metadict.count("download_url") != 0) { |
108 | std::string action_id = metadict["action_id"].get_string(); |
109 | std::string download_url = metadict["download_url"].get_string(); |
110 | @@ -147,7 +149,7 @@ |
111 | } else { |
112 | qWarning() << "unexpected action id " << QString::fromStdString(action_id) |
113 | << " given with download_url" << QString::fromStdString(download_url); |
114 | - return new UninstalledPreview(result, client, depts, nam); |
115 | + return new UninstalledPreview(result, client, depts, nam, ppackage); |
116 | } |
117 | } else if (metadict.count(click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED) != 0) { |
118 | return new CancelPurchasePreview(result, false); |
119 | @@ -156,16 +158,16 @@ |
120 | } else if (metadict.count(click::Preview::Actions::UNINSTALL_CLICK) != 0) { |
121 | return new UninstallConfirmationPreview(result); |
122 | } else if (metadict.count(click::Preview::Actions::CONFIRM_UNINSTALL) != 0) { |
123 | - return new UninstallingPreview(result, client, nam); |
124 | + return new UninstallingPreview(result, client, nam, ppackage); |
125 | } else if (metadict.count(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE) != 0) { |
126 | - return new CancellingPurchasePreview(result, client, nam); |
127 | + return new CancellingPurchasePreview(result, client, nam, ppackage); |
128 | } else if (metadict.count(click::Preview::Actions::RATED) != 0) { |
129 | - return new InstalledPreview(result, metadata, client, depts); |
130 | + return new InstalledPreview(result, metadata, client, ppackage, depts); |
131 | } else if (metadict.count(click::Preview::Actions::SHOW_UNINSTALLED) != 0) { |
132 | - return new UninstalledPreview(result, client, depts, nam); |
133 | + return new UninstalledPreview(result, client, depts, nam, ppackage); |
134 | } else { |
135 | qWarning() << "preview() called with unexpected metadata. returning uninstalled preview"; |
136 | - return new UninstalledPreview(result, client, depts, nam); |
137 | + return new UninstalledPreview(result, client, depts, nam, ppackage); |
138 | } |
139 | } else { |
140 | // metadata.scope_data() is Null, so we return an appropriate "default" preview: |
141 | @@ -174,9 +176,9 @@ |
142 | return new InstalledScopePreview(result); |
143 | } |
144 | if (result["installed"].get_bool() == true) { |
145 | - return new InstalledPreview(result, metadata, client, depts); |
146 | + return new InstalledPreview(result, metadata, client, ppackage, depts); |
147 | } else { |
148 | - return new UninstalledPreview(result, client, depts, nam); |
149 | + return new UninstalledPreview(result, client, depts, nam, ppackage); |
150 | } |
151 | } |
152 | |
153 | @@ -210,6 +212,19 @@ |
154 | { |
155 | } |
156 | |
157 | +PreviewStrategy::PreviewStrategy(const unity::scopes::Result& result, |
158 | + const QSharedPointer<click::web::Client>& client, |
159 | + const QSharedPointer<pay::Package>& ppackage) |
160 | + : result(result), |
161 | + client(client), |
162 | + index(new click::Index(client)), |
163 | + reviews(new click::Reviews(client)), |
164 | + oa_client("ubuntuone", "ubuntuone", "ubuntuone", |
165 | + scopes::OnlineAccountClient::MainLoopSelect::CreateInternalMainLoop), |
166 | + pay_package(ppackage) |
167 | +{ |
168 | +} |
169 | + |
170 | void PreviewStrategy::pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply, |
171 | const PackageDetails &details, |
172 | const scopes::PreviewWidgetList& button_area_widgets) |
173 | @@ -229,6 +244,7 @@ |
174 | index_operation.cancel(); |
175 | reviews_operation.cancel(); |
176 | submit_operation.cancel(); |
177 | + purchase_operation.cancel(); |
178 | } |
179 | |
180 | scopes::PreviewWidget PreviewStrategy::build_other_metadata(const PackageDetails &details) |
181 | @@ -529,15 +545,20 @@ |
182 | return widgets; |
183 | } |
184 | |
185 | -bool PreviewStrategy::isRefundable() const |
186 | +bool PreviewStrategy::isRefundable() |
187 | { |
188 | - time_t refundable_until = 0; |
189 | - if (result.contains("refundable_until")) { |
190 | - refundable_until = result["refundable_until"].get_int64_t(); |
191 | - } |
192 | - time_t now = time(NULL); |
193 | - // refund button is not shown if less than ten seconds left |
194 | - return refundable_until >= (now + 10); |
195 | + if (pay_package.isNull()) |
196 | + { |
197 | + return false; |
198 | + } |
199 | + |
200 | + std::string pkg_name = get_string_maybe_null(result["name"]); |
201 | + if (pkg_name.empty()) |
202 | + { |
203 | + return false; |
204 | + } |
205 | + |
206 | + return pay_package->is_refundable(pkg_name); |
207 | } |
208 | |
209 | void PreviewStrategy::invalidateScope(const std::string& scope_id) |
210 | @@ -657,8 +678,9 @@ |
211 | InstalledPreview::InstalledPreview(const unity::scopes::Result& result, |
212 | const unity::scopes::ActionMetadata& metadata, |
213 | const QSharedPointer<click::web::Client>& client, |
214 | + const QSharedPointer<pay::Package>& ppackage, |
215 | const std::shared_ptr<click::DepartmentsDb>& depts) |
216 | - : PreviewStrategy(result, client), |
217 | + : PreviewStrategy(result, client, ppackage), |
218 | DepartmentUpdater(depts), |
219 | metadata(metadata) |
220 | { |
221 | @@ -1065,8 +1087,9 @@ |
222 | UninstalledPreview::UninstalledPreview(const unity::scopes::Result& result, |
223 | const QSharedPointer<click::web::Client>& client, |
224 | const std::shared_ptr<click::DepartmentsDb>& depts, |
225 | - const QSharedPointer<click::network::AccessManager>& nam) |
226 | - : PreviewStrategy(result, client), |
227 | + const QSharedPointer<click::network::AccessManager>& nam, |
228 | + const QSharedPointer<pay::Package>& ppackage) |
229 | + : PreviewStrategy(result, client, ppackage), |
230 | DepartmentUpdater(depts), nam(nam) |
231 | { |
232 | qDebug() << "Creating new UninstalledPreview for result" << QString::fromStdString(result["name"].get_string()); |
233 | @@ -1160,8 +1183,9 @@ |
234 | // TODO: this class should be removed once uninstall() is handled elsewhere. |
235 | UninstallingPreview::UninstallingPreview(const unity::scopes::Result& result, |
236 | const QSharedPointer<click::web::Client>& client, |
237 | - const QSharedPointer<click::network::AccessManager>& nam) |
238 | - : UninstalledPreview(result, client, nullptr, nam) |
239 | + const QSharedPointer<click::network::AccessManager>& nam, |
240 | + const QSharedPointer<pay::Package>& ppackage) |
241 | + : UninstalledPreview(result, client, nullptr, nam, ppackage) |
242 | { |
243 | } |
244 | |
245 | @@ -1201,9 +1225,10 @@ |
246 | // class CancellingPurchasePreview : public UninstallingPreview |
247 | |
248 | CancellingPurchasePreview::CancellingPurchasePreview(const unity::scopes::Result& result, |
249 | - const QSharedPointer<click::web::Client>& client, |
250 | - const QSharedPointer<click::network::AccessManager>& nam) |
251 | - : UninstallingPreview(result, client, nam) |
252 | + const QSharedPointer<click::web::Client>& client, |
253 | + const QSharedPointer<click::network::AccessManager>& nam, |
254 | + const QSharedPointer<pay::Package>& ppackage) |
255 | + : UninstallingPreview(result, client, nam, ppackage) |
256 | { |
257 | } |
258 | |
259 | @@ -1231,9 +1256,9 @@ |
260 | std::promise<bool> refund_promise; |
261 | std::future<bool> refund_future = refund_promise.get_future(); |
262 | |
263 | - run_under_qt([&refund_promise, package_name]() { |
264 | + run_under_qt([this, &refund_promise, package_name]() { |
265 | qDebug() << "Calling refund for:" << package_name.c_str(); |
266 | - auto ret = pay::Package::instance().refund(package_name); |
267 | + auto ret = pay_package->refund(package_name); |
268 | qDebug() << "Refund returned:" << ret; |
269 | refund_promise.set_value(ret); |
270 | }); |
271 | |
272 | === modified file 'libclickscope/click/preview.h' |
273 | --- libclickscope/click/preview.h 2015-06-17 16:59:14 +0000 |
274 | +++ libclickscope/click/preview.h 2015-07-02 22:21:56 +0000 |
275 | @@ -32,6 +32,7 @@ |
276 | |
277 | #include <click/index.h> |
278 | #include <click/download-manager.h> |
279 | +#include <click/pay.h> |
280 | #include <click/qtbridge.h> |
281 | #include "reviews.h" |
282 | |
283 | @@ -75,6 +76,7 @@ |
284 | const unity::scopes::ActionMetadata& metadata, |
285 | const QSharedPointer<web::Client> &client, |
286 | const QSharedPointer<click::network::AccessManager>& nam, |
287 | + const QSharedPointer<pay::Package>& ppackage, |
288 | std::shared_ptr<click::DepartmentsDb> depts); |
289 | virtual PreviewStrategy* build_installing(const std::string& download_url, |
290 | const std::string& download_sha512, |
291 | @@ -113,6 +115,7 @@ |
292 | virtual ~Preview(); |
293 | void choose_strategy(const QSharedPointer<web::Client> &client, |
294 | const QSharedPointer<click::network::AccessManager>& nam, |
295 | + const QSharedPointer<pay::Package>& ppackage, |
296 | std::shared_ptr<click::DepartmentsDb> depts); |
297 | // From unity::scopes::PreviewQuery |
298 | void cancelled() override; |
299 | @@ -125,8 +128,10 @@ |
300 | |
301 | PreviewStrategy(const unity::scopes::Result& result); |
302 | PreviewStrategy(const unity::scopes::Result& result, |
303 | - const QSharedPointer<click::web::Client>& client); |
304 | - |
305 | + const QSharedPointer<click::web::Client>& client); |
306 | + PreviewStrategy(const unity::scopes::Result& result, |
307 | + const QSharedPointer<click::web::Client>& client, |
308 | + const QSharedPointer<pay::Package>& pay_package); |
309 | virtual ~PreviewStrategy(); |
310 | |
311 | virtual void cancelled(); |
312 | @@ -154,7 +159,7 @@ |
313 | virtual scopes::PreviewWidget build_updates_table(const PackageDetails& details); |
314 | virtual std::string build_whats_new(const PackageDetails& details); |
315 | virtual void run_under_qt(const std::function<void ()> &task); |
316 | - virtual bool isRefundable() const; |
317 | + virtual bool isRefundable(); |
318 | virtual void invalidateScope(const std::string& scope_id); |
319 | |
320 | scopes::Result result; |
321 | @@ -165,6 +170,8 @@ |
322 | click::web::Cancellable reviews_operation; |
323 | click::web::Cancellable submit_operation; |
324 | scopes::OnlineAccountClient oa_client; |
325 | + QSharedPointer<pay::Package> pay_package; |
326 | + click::web::Cancellable purchase_operation; |
327 | }; |
328 | |
329 | class DownloadErrorPreview : public PreviewStrategy |
330 | @@ -206,6 +213,7 @@ |
331 | InstalledPreview(const unity::scopes::Result& result, |
332 | const unity::scopes::ActionMetadata& metadata, |
333 | const QSharedPointer<click::web::Client>& client, |
334 | + const QSharedPointer<pay::Package>& ppackage, |
335 | const std::shared_ptr<click::DepartmentsDb>& depts); |
336 | |
337 | virtual ~InstalledPreview(); |
338 | @@ -273,7 +281,8 @@ |
339 | UninstalledPreview(const unity::scopes::Result& result, |
340 | const QSharedPointer<click::web::Client>& client, |
341 | const std::shared_ptr<click::DepartmentsDb>& depts, |
342 | - const QSharedPointer<click::network::AccessManager>& nam); |
343 | + const QSharedPointer<click::network::AccessManager>& nam, |
344 | + const QSharedPointer<pay::Package>& ppackage); |
345 | |
346 | virtual ~UninstalledPreview(); |
347 | |
348 | @@ -292,7 +301,8 @@ |
349 | public: |
350 | UninstallingPreview(const unity::scopes::Result& result, |
351 | const QSharedPointer<click::web::Client>& client, |
352 | - const QSharedPointer<click::network::AccessManager>& nam); |
353 | + const QSharedPointer<click::network::AccessManager>& nam, |
354 | + const QSharedPointer<pay::Package>& ppackage); |
355 | |
356 | virtual ~UninstallingPreview(); |
357 | |
358 | @@ -308,7 +318,8 @@ |
359 | public: |
360 | CancellingPurchasePreview(const unity::scopes::Result& result, |
361 | const QSharedPointer<click::web::Client>& client, |
362 | - const QSharedPointer<click::network::AccessManager>& nam); |
363 | + const QSharedPointer<click::network::AccessManager>& nam, |
364 | + const QSharedPointer<pay::Package>& ppackage); |
365 | |
366 | virtual ~CancellingPurchasePreview(); |
367 | |
368 | |
369 | === modified file 'libclickscope/tests/mock_pay.h' |
370 | --- libclickscope/tests/mock_pay.h 2015-06-11 19:24:18 +0000 |
371 | +++ libclickscope/tests/mock_pay.h 2015-07-02 22:21:56 +0000 |
372 | @@ -87,10 +87,18 @@ |
373 | do_pay_package_verify(pkg_name); |
374 | } |
375 | |
376 | + bool is_refundable(const std::string& pkg_name) |
377 | + { |
378 | + do_is_refundable(pkg_name); |
379 | + return refundable; |
380 | + } |
381 | + |
382 | MOCK_METHOD0(setup_pay_service, void()); |
383 | MOCK_METHOD1(do_pay_package_refund, void(const std::string&)); |
384 | MOCK_METHOD1(do_pay_package_verify, void(const std::string&)); |
385 | + MOCK_METHOD1(do_is_refundable, void(const std::string&)); |
386 | |
387 | + bool refundable = false; |
388 | bool success = false; |
389 | pay::PurchaseSet purchases; |
390 | }; |
391 | |
392 | === modified file 'libclickscope/tests/test_pay.cpp' |
393 | --- libclickscope/tests/test_pay.cpp 2015-06-11 19:24:18 +0000 |
394 | +++ libclickscope/tests/test_pay.cpp 2015-07-02 22:21:56 +0000 |
395 | @@ -59,14 +59,12 @@ |
396 | clientPtr.reset(new NiceMock<MockClient>(namPtr)); |
397 | package.reset(new MockPayPackage(clientPtr)); |
398 | } |
399 | - |
400 | public: |
401 | MOCK_METHOD1(purchases_callback, void(pay::PurchaseSet)); |
402 | }; |
403 | |
404 | } |
405 | |
406 | - |
407 | TEST_F(PayTest, testPayPackageRefundCalled) |
408 | { |
409 | LifetimeHelper<click::network::Reply, MockNetworkReply> reply; |
410 | |
411 | === modified file 'libclickscope/tests/test_preview.cpp' |
412 | --- libclickscope/tests/test_preview.cpp 2015-05-15 19:51:22 +0000 |
413 | +++ libclickscope/tests/test_preview.cpp 2015-07-02 22:21:56 +0000 |
414 | @@ -35,6 +35,7 @@ |
415 | #include <gtest/gtest.h> |
416 | #include <click/preview.h> |
417 | #include <fake_json.h> |
418 | +#include <mock_pay.h> |
419 | #include <click/index.h> |
420 | #include <click/interface.h> |
421 | #include <click/reviews.h> |
422 | @@ -270,6 +271,7 @@ |
423 | unity::scopes::VariantMap metadict; |
424 | QSharedPointer<click::web::Client> client; |
425 | QSharedPointer<click::network::AccessManager> nam; |
426 | + QSharedPointer<MockPayPackage> pay_package; |
427 | std::shared_ptr<click::DepartmentsDb> depts; |
428 | const std::string FAKE_SHA512 = "FAKE_SHA512"; |
429 | |
430 | @@ -298,7 +300,7 @@ |
431 | metadata.set_scope_data(unity::scopes::Variant(metadict)); |
432 | MockablePreview preview(result, metadata); |
433 | EXPECT_CALL(preview, build_installing(_, FAKE_SHA512, _, _, _, _)); |
434 | - preview.choose_strategy(client, nam, depts); |
435 | + preview.choose_strategy(client, nam, pay_package, depts); |
436 | } |
437 | |
438 | |
439 | @@ -309,6 +311,7 @@ |
440 | unity::scopes::PreviewWidgetList widgets; |
441 | QSharedPointer<click::web::Client> client; |
442 | QSharedPointer<click::network::AccessManager> nam; |
443 | + QSharedPointer<MockPayPackage> pay_package; |
444 | std::shared_ptr<click::DepartmentsDb> depts; |
445 | unity::scopes::testing::MockPreviewReply reply; |
446 | std::shared_ptr<unity::scopes::testing::MockPreviewReply> replyptr{&reply, [](unity::scopes::testing::MockPreviewReply*){}}; |
447 | @@ -342,8 +345,10 @@ |
448 | const unity::scopes::Result& result, |
449 | const QSharedPointer<click::web::Client>& client, |
450 | const std::shared_ptr<click::DepartmentsDb>& depts, |
451 | - const QSharedPointer<click::network::AccessManager>& nam) |
452 | - : click::UninstalledPreview(result, client, depts, nam), object_path(object_path), |
453 | + const QSharedPointer<click::network::AccessManager>& nam, |
454 | + const QSharedPointer<pay::Package> pay_package) |
455 | + : click::UninstalledPreview(result, client, depts, nam, pay_package), |
456 | + object_path(object_path), |
457 | fake_downloader(new FakeDownloader(object_path, nam)) |
458 | { |
459 | |
460 | @@ -370,8 +375,9 @@ |
461 | const unity::scopes::Result& result, |
462 | const QSharedPointer<click::web::Client>& client, |
463 | const std::shared_ptr<click::DepartmentsDb>& depts, |
464 | - const QSharedPointer<click::network::AccessManager>& nam) |
465 | - : FakeBaseUninstalledPreview(object_path, result, client, depts, nam) { |
466 | + const QSharedPointer<click::network::AccessManager>& nam, |
467 | + const QSharedPointer<pay::Package> pay_package) |
468 | + : FakeBaseUninstalledPreview(object_path, result, client, depts, nam, pay_package) { |
469 | } |
470 | }; |
471 | |
472 | @@ -381,7 +387,7 @@ |
473 | |
474 | result["name"] = "fake_app_name"; |
475 | scopes::PreviewWidgetList response; |
476 | - FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam); |
477 | + FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam, pay_package); |
478 | EXPECT_CALL(preview, progressBarWidget(_)) |
479 | .Times(1) |
480 | .WillOnce(Return(response)); |
481 | @@ -394,7 +400,7 @@ |
482 | |
483 | result["name"] = "fake_app_name"; |
484 | scopes::PreviewWidgetList response; |
485 | - FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam); |
486 | + FakeUninstalledPreview preview(fake_object_path, result, client, depts, nam, pay_package); |
487 | EXPECT_CALL(preview, uninstalledActionButtonWidgets(_)) |
488 | .Times(1) |
489 | .WillOnce(Return(response)); |
490 | @@ -405,13 +411,14 @@ |
491 | class FakeUninstalledRefundablePreview : FakeBaseUninstalledPreview { |
492 | public: |
493 | FakeUninstalledRefundablePreview(const unity::scopes::Result& result, |
494 | - const QSharedPointer<click::web::Client>& client, |
495 | - const std::shared_ptr<click::DepartmentsDb>& depts, |
496 | - const QSharedPointer<click::network::AccessManager>& nam) |
497 | - : FakeBaseUninstalledPreview(std::string{""}, result, client, depts, nam){ |
498 | + const QSharedPointer<click::web::Client>& client, |
499 | + const std::shared_ptr<click::DepartmentsDb>& depts, |
500 | + const QSharedPointer<click::network::AccessManager>& nam, |
501 | + const QSharedPointer<pay::Package> pay_package) |
502 | + : FakeBaseUninstalledPreview(std::string{""}, result, client, depts, nam, pay_package){ |
503 | } |
504 | using click::UninstalledPreview::uninstalledActionButtonWidgets; |
505 | - MOCK_CONST_METHOD0(isRefundable, bool()); |
506 | + MOCK_METHOD0(isRefundable, bool()); |
507 | }; |
508 | |
509 | unity::scopes::VariantArray get_actions_from_widgets(const unity::scopes::PreviewWidgetList& widgets, int widget_number) { |
510 | @@ -429,7 +436,7 @@ |
511 | result["name"] = "fake_app_name"; |
512 | result["price"] = 2.99; |
513 | result["purchased"] = true; |
514 | - FakeUninstalledRefundablePreview preview(result, client, depts, nam); |
515 | + FakeUninstalledRefundablePreview preview(result, client, depts, nam, pay_package); |
516 | |
517 | click::PackageDetails pkgdetails; |
518 | EXPECT_CALL(preview, isRefundable()).Times(1) |
519 | @@ -442,7 +449,7 @@ |
520 | result["name"] = "fake_app_name"; |
521 | result["price"] = 2.99; |
522 | result["purchased"] = true; |
523 | - FakeUninstalledRefundablePreview preview(result, client, depts, nam); |
524 | + FakeUninstalledRefundablePreview preview(result, client, depts, nam, pay_package); |
525 | |
526 | click::PackageDetails pkgdetails; |
527 | EXPECT_CALL(preview, isRefundable()).Times(1) |
528 | @@ -458,6 +465,7 @@ |
529 | unity::scopes::VariantMap metadict; |
530 | QSharedPointer<click::web::Client> client; |
531 | QSharedPointer<click::network::AccessManager> nam; |
532 | + QSharedPointer<MockPayPackage> pay_package; |
533 | std::shared_ptr<click::DepartmentsDb> depts; |
534 | |
535 | public: |
536 | @@ -470,16 +478,17 @@ |
537 | FakeInstalledRefundablePreview(const unity::scopes::Result& result, |
538 | const unity::scopes::ActionMetadata& metadata, |
539 | const QSharedPointer<click::web::Client> client, |
540 | + const QSharedPointer<pay::Package> pay_package, |
541 | const std::shared_ptr<click::DepartmentsDb> depts) |
542 | - : click::InstalledPreview(result, metadata, client, depts) { |
543 | + : click::InstalledPreview(result, metadata, client, pay_package, depts) { |
544 | |
545 | } |
546 | using click::InstalledPreview::createButtons; |
547 | - MOCK_CONST_METHOD0(isRefundable, bool()); |
548 | + MOCK_METHOD0(isRefundable, bool()); |
549 | }; |
550 | |
551 | TEST_F(InstalledPreviewTest, testIsRefundableButtonShown) { |
552 | - FakeInstalledRefundablePreview preview(result, metadata, client, depts); |
553 | + FakeInstalledRefundablePreview preview(result, metadata, client, pay_package, depts); |
554 | EXPECT_CALL(preview, isRefundable()).Times(1) |
555 | .WillOnce(Return(true)); |
556 | click::Manifest manifest; |
557 | @@ -490,7 +499,7 @@ |
558 | } |
559 | |
560 | TEST_F(InstalledPreviewTest, testIsRefundableButtonNotShown) { |
561 | - FakeInstalledRefundablePreview preview(result, metadata, client, depts); |
562 | + FakeInstalledRefundablePreview preview(result, metadata, client, pay_package, depts); |
563 | EXPECT_CALL(preview, isRefundable()).Times(1) |
564 | .WillOnce(Return(false)); |
565 | click::Manifest manifest; |
566 | @@ -501,41 +510,6 @@ |
567 | } |
568 | |
569 | |
570 | -class RefundableTest : public PreviewStrategyTest { |
571 | - |
572 | -}; |
573 | - |
574 | -TEST_F(RefundableTest, testIsNotRefundableWhenFieldMissing) { |
575 | - FakeResult result{vm}; |
576 | - FakePreview preview{result}; |
577 | - ASSERT_FALSE(preview.isRefundable()); |
578 | -} |
579 | - |
580 | -TEST_F(RefundableTest, testIsNotRefundableWhenExpired) { |
581 | - FakeResult result{vm}; |
582 | - time_t now = time(NULL); |
583 | - result["refundable_until"] = (int64_t) (now - 300); |
584 | - FakePreview preview{result}; |
585 | - ASSERT_FALSE(preview.isRefundable()); |
586 | -} |
587 | - |
588 | -TEST_F(RefundableTest, testIsRefundable) { |
589 | - FakeResult result{vm}; |
590 | - time_t now = time(NULL); |
591 | - result["refundable_until"] = (int64_t) (now + 300); |
592 | - FakePreview preview{result}; |
593 | - ASSERT_TRUE(preview.isRefundable()); |
594 | -} |
595 | - |
596 | -TEST_F(RefundableTest, testIsNotRefundableWhenExpiringRealSoon) { |
597 | - FakeResult result{vm}; |
598 | - time_t now = time(NULL); |
599 | - result["refundable_until"] = (int64_t) (now + 8); |
600 | - FakePreview preview{result}; |
601 | - ASSERT_FALSE(preview.isRefundable()); |
602 | -} |
603 | - |
604 | - |
605 | class FakeCancelPurchasePreview : public click::CancelPurchasePreview { |
606 | public: |
607 | FakeCancelPurchasePreview(const unity::scopes::Result& result, bool installed) |
608 | |
609 | === modified file 'scope/clickapps/apps-scope.cpp' |
610 | --- scope/clickapps/apps-scope.cpp 2015-05-29 08:59:56 +0000 |
611 | +++ scope/clickapps/apps-scope.cpp 2015-07-02 22:21:56 +0000 |
612 | @@ -52,6 +52,8 @@ |
613 | nam.reset(new click::network::AccessManager()); |
614 | client.reset(new click::web::Client(nam)); |
615 | index.reset(new click::Index(client)); |
616 | + pay_package.reset(new pay::Package(client)); |
617 | + |
618 | try |
619 | { |
620 | depts_db = click::DepartmentsDb::open(false); |
621 | @@ -99,7 +101,7 @@ |
622 | const unity::scopes::ActionMetadata& metadata) { |
623 | qDebug() << "Scope::preview() called."; |
624 | auto preview = new click::Preview(result, metadata); |
625 | - preview->choose_strategy(client, nam, depts_db); |
626 | + preview->choose_strategy(client, nam, pay_package, depts_db); |
627 | return unity::scopes::PreviewQueryBase::UPtr{preview}; |
628 | } |
629 | |
630 | |
631 | === modified file 'scope/clickapps/apps-scope.h' |
632 | --- scope/clickapps/apps-scope.h 2014-08-01 15:04:19 +0000 |
633 | +++ scope/clickapps/apps-scope.h 2015-07-02 22:21:56 +0000 |
634 | @@ -30,14 +30,15 @@ |
635 | #ifndef APPS_SCOPE_H |
636 | #define APPS_SCOPE_H |
637 | |
638 | +#include <click/index.h> |
639 | #include <click/network_access_manager.h> |
640 | +#include <click/pay.h> |
641 | #include <click/webclient.h> |
642 | |
643 | #include <unity/scopes/ScopeBase.h> |
644 | #include <unity/scopes/QueryBase.h> |
645 | #include <unity/scopes/ActivationQueryBase.h> |
646 | |
647 | -#include <click/index.h> |
648 | |
649 | namespace scopes = unity::scopes; |
650 | |
651 | @@ -67,6 +68,7 @@ |
652 | QSharedPointer<click::network::AccessManager> nam; |
653 | QSharedPointer<click::web::Client> client; |
654 | QSharedPointer<click::Index> index; |
655 | + QSharedPointer<pay::Package> pay_package; |
656 | std::shared_ptr<click::DepartmentsDb> depts_db; |
657 | |
658 | std::string installApplication(unity::scopes::Result const& result); |
659 | |
660 | === modified file 'scope/clickstore/store-scope.cpp' |
661 | --- scope/clickstore/store-scope.cpp 2015-04-24 21:30:39 +0000 |
662 | +++ scope/clickstore/store-scope.cpp 2015-07-02 22:21:56 +0000 |
663 | @@ -103,7 +103,7 @@ |
664 | const unity::scopes::ActionMetadata& metadata) { |
665 | qDebug() << "Scope::preview() called."; |
666 | auto preview = new click::Preview(result, metadata); |
667 | - preview->choose_strategy(client, nam, depts_db); |
668 | + preview->choose_strategy(client, nam, pay_package, depts_db); |
669 | return unity::scopes::PreviewQueryBase::UPtr{preview}; |
670 | } |
671 | |
672 | @@ -124,6 +124,7 @@ |
673 | std::string download_sha512 = metadata.scope_data().get_dict()["download_sha512"].get_string(); |
674 | activation->setHint("download_sha512", unity::scopes::Variant(download_sha512)); |
675 | activation->setHint("action_id", unity::scopes::Variant(click::Preview::Actions::INSTALL_CLICK)); |
676 | + activation->setHint("purchased", unity::scopes::Variant(true)); |
677 | qDebug() << "returning ShowPreview"; |
678 | activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
679 | } else if (action_id == "purchaseError") { |
680 | @@ -144,6 +145,7 @@ |
681 | activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
682 | } else if (action_id == click::Preview::Actions::DOWNLOAD_COMPLETED) { |
683 | activation->setHint(click::Preview::Actions::DOWNLOAD_COMPLETED, unity::scopes::Variant(true)); |
684 | + activation->setHint("installed", unity::scopes::Variant(true)); |
685 | activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview); |
686 | } else if (action_id == click::Preview::Actions::CANCEL_PURCHASE_INSTALLED) { |
687 | activation->setHint(click::Preview::Actions::CANCEL_PURCHASE_INSTALLED, unity::scopes::Variant(true)); |
688 | |
689 | === modified file 'scope/clickstore/store-scope.h' |
690 | --- scope/clickstore/store-scope.h 2015-04-14 21:19:21 +0000 |
691 | +++ scope/clickstore/store-scope.h 2015-07-02 22:21:56 +0000 |
692 | @@ -71,10 +71,10 @@ |
693 | QSharedPointer<click::network::AccessManager> nam; |
694 | QSharedPointer<click::web::Client> client; |
695 | QSharedPointer<click::Index> index; |
696 | + QSharedPointer<pay::Package> pay_package; |
697 | std::shared_ptr<click::DepartmentLookup> depts; |
698 | std::shared_ptr<click::HighlightList> highlights; |
699 | std::shared_ptr<click::DepartmentsDb> depts_db; |
700 | - std::shared_ptr<pay::Package> pay_package; |
701 | |
702 | std::string installApplication(unity::scopes::Result const& result); |
703 | }; |
FAILED: Continuous integration, rev:344 jenkins. qa.ubuntu. com/job/ unity-scope- click-ci/ 641/ jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- amd64-ci/ 55/console jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- armhf-ci/ 51/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scope-click- ci/641/ rebuild
http://