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