Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/payments/payment_app_browsertest.cc

Issue 2969713002: [Payments] Present web payment app instead of instruments to user (Closed)
Patch Set: address comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/storage_partition_impl.h" 8 #include "content/browser/storage_partition_impl.h"
9 #include "content/public/browser/browser_context.h" 9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/payment_app_provider.h" 10 #include "content/public/browser/payment_app_provider.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EXPECT_TRUE(RunScript("resultQueue.pop()", &script_result)); 77 EXPECT_TRUE(RunScript("resultQueue.pop()", &script_result));
78 return script_result; 78 return script_result;
79 } 79 }
80 80
81 void RegisterPaymentApp() { 81 void RegisterPaymentApp() {
82 std::string script_result; 82 std::string script_result;
83 ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result)); 83 ASSERT_TRUE(RunScript("registerPaymentApp()", &script_result));
84 ASSERT_EQ("registered", script_result); 84 ASSERT_EQ("registered", script_result);
85 } 85 }
86 86
87 std::map<std::string, int64_t> GetAllPaymentInstrumentRegistrationIDs() { 87 std::vector<int64_t> GetAllPaymentAppRegistrationIDs() {
88 base::RunLoop run_loop; 88 base::RunLoop run_loop;
89 PaymentAppProvider::PaymentApps apps; 89 PaymentAppProvider::PaymentApps apps;
90 PaymentAppProvider::GetInstance()->GetAllPaymentApps( 90 PaymentAppProvider::GetInstance()->GetAllPaymentApps(
91 shell()->web_contents()->GetBrowserContext(), 91 shell()->web_contents()->GetBrowserContext(),
92 base::BindOnce(&GetAllPaymentAppsCallback, run_loop.QuitClosure(), 92 base::BindOnce(&GetAllPaymentAppsCallback, run_loop.QuitClosure(),
93 &apps)); 93 &apps));
94 run_loop.Run(); 94 run_loop.Run();
95 95
96 std::map<std::string, int64_t> registrationIds; 96 std::vector<int64_t> registrationIds;
97 for (const auto& app_info : apps) { 97 for (const auto& app_info : apps) {
98 for (const auto& instrument : app_info.second->instruments) { 98 registrationIds.push_back(app_info.second->registration_id);
99 registrationIds.insert(std::pair<std::string, int64_t>(
100 instrument->instrument_key, app_info.second->registration_id));
101 }
102 } 99 }
103 100
104 return registrationIds; 101 return registrationIds;
105 } 102 }
106 103
107 PaymentAppResponsePtr InvokePaymentAppWithTestData( 104 PaymentAppResponsePtr InvokePaymentAppWithTestData(
108 int64_t registration_id, 105 int64_t registration_id,
109 const std::string& supported_method, 106 const std::string& supported_method,
110 const std::string& instrument_key) { 107 const std::string& instrument_key) {
111 PaymentRequestEventDataPtr event_data = PaymentRequestEventData::New(); 108 PaymentRequestEventDataPtr event_data = PaymentRequestEventData::New();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 160
164 private: 161 private:
165 std::unique_ptr<net::EmbeddedTestServer> https_server_; 162 std::unique_ptr<net::EmbeddedTestServer> https_server_;
166 163
167 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); 164 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
168 }; 165 };
169 166
170 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) { 167 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
171 RegisterPaymentApp(); 168 RegisterPaymentApp();
172 169
173 std::map<std::string, int64_t> registrationIds = 170 std::vector<int64_t> registrationIds = GetAllPaymentAppRegistrationIDs();
174 GetAllPaymentInstrumentRegistrationIDs(); 171 ASSERT_EQ(1U, registrationIds.size());
175 ASSERT_EQ(2U, registrationIds.size());
176 172
177 PaymentAppResponsePtr response(InvokePaymentAppWithTestData( 173 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
178 registrationIds.at("basic-card-payment-app-id"), "basic-card", 174 registrationIds[0], "basic-card", "basic-card-payment-app-id"));
179 "basic-card-payment-app-id"));
180 ASSERT_EQ("test", response->method_name); 175 ASSERT_EQ("test", response->method_name);
181 176
182 ClearStoragePartitionData(); 177 ClearStoragePartitionData();
183 178
184 registrationIds = GetAllPaymentInstrumentRegistrationIDs(); 179 registrationIds = GetAllPaymentAppRegistrationIDs();
185 ASSERT_EQ(0U, registrationIds.size()); 180 ASSERT_EQ(0U, registrationIds.size());
186 181
187 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */); 182 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
188 EXPECT_EQ("https://example.com/", 183 EXPECT_EQ("https://example.com/",
189 PopConsoleString() /* paymentRequestOrigin */); 184 PopConsoleString() /* paymentRequestOrigin */);
190 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */); 185 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
191 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]", 186 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]",
192 PopConsoleString() /* methodData */); 187 PopConsoleString() /* methodData */);
193 EXPECT_EQ( 188 EXPECT_EQ(
194 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:" 189 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
195 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}", 190 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
196 PopConsoleString() /* total */); 191 PopConsoleString() /* total */);
197 EXPECT_EQ( 192 EXPECT_EQ(
198 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"]," 193 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"],"
199 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:" 194 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
200 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]", 195 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
201 PopConsoleString() /* modifiers */); 196 PopConsoleString() /* modifiers */);
202 EXPECT_EQ("basic-card-payment-app-id", 197 EXPECT_EQ("basic-card-payment-app-id",
203 PopConsoleString() /* instrumentKey */); 198 PopConsoleString() /* instrumentKey */);
204 } 199 }
205 200
206 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppOpenWindowFailed) { 201 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppOpenWindowFailed) {
207 RegisterPaymentApp(); 202 RegisterPaymentApp();
208 203
209 std::map<std::string, int64_t> registrationIds = 204 std::vector<int64_t> registrationIds = GetAllPaymentAppRegistrationIDs();
210 GetAllPaymentInstrumentRegistrationIDs(); 205 ASSERT_EQ(1U, registrationIds.size());
211 ASSERT_EQ(2U, registrationIds.size());
212 206
213 PaymentAppResponsePtr response(InvokePaymentAppWithTestData( 207 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
214 registrationIds.at("bobpay-payment-app-id"), "https://bobpay.com", 208 registrationIds[0], "https://bobpay.com", "bobpay-payment-app-id"));
215 "bobpay-payment-app-id"));
216 // InvokePaymentAppCallback returns empty method_name in case of failure, like 209 // InvokePaymentAppCallback returns empty method_name in case of failure, like
217 // in PaymentRequestRespondWithObserver::OnResponseRejected. 210 // in PaymentRequestRespondWithObserver::OnResponseRejected.
218 ASSERT_EQ("", response->method_name); 211 ASSERT_EQ("", response->method_name);
219 212
220 ClearStoragePartitionData(); 213 ClearStoragePartitionData();
221 214
222 registrationIds = GetAllPaymentInstrumentRegistrationIDs(); 215 registrationIds = GetAllPaymentAppRegistrationIDs();
223 ASSERT_EQ(0U, registrationIds.size()); 216 ASSERT_EQ(0U, registrationIds.size());
224 217
225 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */); 218 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
226 EXPECT_EQ("https://example.com/", 219 EXPECT_EQ("https://example.com/",
227 PopConsoleString() /* paymentRequestOrigin */); 220 PopConsoleString() /* paymentRequestOrigin */);
228 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */); 221 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
229 EXPECT_EQ("[{\"supportedMethods\":[\"https://bobpay.com\"]}]", 222 EXPECT_EQ("[{\"supportedMethods\":[\"https://bobpay.com\"]}]",
230 PopConsoleString() /* methodData */); 223 PopConsoleString() /* methodData */);
231 EXPECT_EQ( 224 EXPECT_EQ(
232 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:" 225 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
233 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}", 226 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
234 PopConsoleString() /* total */); 227 PopConsoleString() /* total */);
235 EXPECT_EQ( 228 EXPECT_EQ(
236 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://" 229 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://"
237 "bobpay.com\"]," 230 "bobpay.com\"],"
238 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:" 231 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
239 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]", 232 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
240 PopConsoleString() /* modifiers */); 233 PopConsoleString() /* modifiers */);
241 EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */); 234 EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */);
242 } 235 }
243 } // namespace content 236 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/android/payments/service_worker_payment_app_bridge.cc ('k') | content/browser/payments/payment_app_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698