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

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

Issue 2893823004: [Payments] Implement openWindow for service worker based payment handler (Closed)
Patch Set: rename ipc messages Created 3 years, 6 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 "components/payments/mojom/payment_app.mojom.h" 8 #include "components/payments/mojom/payment_app.mojom.h"
9 #include "content/browser/storage_partition_impl.h" 9 #include "content/browser/storage_partition_impl.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.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::vector<int64_t> GetAllPaymentAppIDs() { 87 std::map<std::string, int64_t> GetAllPaymentInstrumentRegistrationIDs() {
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::vector<int64_t> ids; 96 std::map<std::string, 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) { 98 for (const auto& instrument : app_info.second) {
99 ids.push_back(instrument->registration_id); 99 registrationIds.insert(std::pair<std::string, int64_t>(
100 instrument->instrument_key, instrument->registration_id));
100 } 101 }
101 } 102 }
102 103
103 return ids; 104 return registrationIds;
104 } 105 }
105 106
106 PaymentAppResponsePtr InvokePaymentAppWithTestData(int64_t registration_id) { 107 PaymentAppResponsePtr InvokePaymentAppWithTestData(
108 int64_t registration_id,
109 const std::string& supported_method,
110 const std::string& instrument_key) {
107 PaymentAppRequestPtr app_request = PaymentAppRequest::New(); 111 PaymentAppRequestPtr app_request = PaymentAppRequest::New();
108 112
109 app_request->top_level_origin = GURL("https://example.com"); 113 app_request->top_level_origin = GURL("https://example.com");
110 114
111 app_request->payment_request_origin = GURL("https://example.com"); 115 app_request->payment_request_origin = GURL("https://example.com");
112 116
113 app_request->payment_request_id = "payment-request-id"; 117 app_request->payment_request_id = "payment-request-id";
114 118
115 app_request->method_data.push_back(PaymentMethodData::New()); 119 app_request->method_data.push_back(PaymentMethodData::New());
116 app_request->method_data[0]->supported_methods = {"basic-card"}; 120 app_request->method_data[0]->supported_methods = {supported_method};
117 121
118 app_request->total = PaymentItem::New(); 122 app_request->total = PaymentItem::New();
119 app_request->total->amount = PaymentCurrencyAmount::New(); 123 app_request->total->amount = PaymentCurrencyAmount::New();
120 app_request->total->amount->currency = "USD"; 124 app_request->total->amount->currency = "USD";
121 125
122 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New(); 126 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New();
123 modifier->total = PaymentItem::New(); 127 modifier->total = PaymentItem::New();
124 modifier->total->amount = PaymentCurrencyAmount::New(); 128 modifier->total->amount = PaymentCurrencyAmount::New();
125 modifier->total->amount->currency = "USD"; 129 modifier->total->amount->currency = "USD";
126 modifier->method_data = PaymentMethodData::New(); 130 modifier->method_data = PaymentMethodData::New();
127 modifier->method_data->supported_methods = {"basic-card"}; 131 modifier->method_data->supported_methods = {supported_method};
128 app_request->modifiers.push_back(std::move(modifier)); 132 app_request->modifiers.push_back(std::move(modifier));
129 133
130 app_request->instrument_key = "instrument-key"; 134 app_request->instrument_key = instrument_key;
131 135
132 base::RunLoop run_loop; 136 base::RunLoop run_loop;
133 PaymentAppResponsePtr response; 137 PaymentAppResponsePtr response;
134 PaymentAppProvider::GetInstance()->InvokePaymentApp( 138 PaymentAppProvider::GetInstance()->InvokePaymentApp(
135 shell()->web_contents()->GetBrowserContext(), registration_id, 139 shell()->web_contents()->GetBrowserContext(), registration_id,
136 std::move(app_request), 140 std::move(app_request),
137 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(), 141 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(),
138 &response)); 142 &response));
139 run_loop.Run(); 143 run_loop.Run();
140 144
(...skipping 18 matching lines...) Expand all
159 163
160 private: 164 private:
161 std::unique_ptr<net::EmbeddedTestServer> https_server_; 165 std::unique_ptr<net::EmbeddedTestServer> https_server_;
162 166
163 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); 167 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
164 }; 168 };
165 169
166 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) { 170 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
167 RegisterPaymentApp(); 171 RegisterPaymentApp();
168 172
169 std::vector<int64_t> ids = GetAllPaymentAppIDs(); 173 std::map<std::string, int64_t> registrationIds =
170 ASSERT_EQ(1U, ids.size()); 174 GetAllPaymentInstrumentRegistrationIDs();
175 ASSERT_EQ(2U, registrationIds.size());
171 176
172 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(ids[0])); 177 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
178 registrationIds.at("basic-card-payment-app-id"), "basic-card",
179 "basic-card-payment-app-id"));
173 ASSERT_EQ("test", response->method_name); 180 ASSERT_EQ("test", response->method_name);
174 181
175 ClearStoragePartitionData(); 182 ClearStoragePartitionData();
176 183
177 ids = GetAllPaymentAppIDs(); 184 registrationIds = GetAllPaymentInstrumentRegistrationIDs();
178 ASSERT_EQ(0U, ids.size()); 185 ASSERT_EQ(0U, registrationIds.size());
179 186
180 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */); 187 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
181 EXPECT_EQ("https://example.com/", 188 EXPECT_EQ("https://example.com/",
182 PopConsoleString() /* paymentRequestOrigin */); 189 PopConsoleString() /* paymentRequestOrigin */);
183 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */); 190 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
184 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]", 191 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]",
185 PopConsoleString() /* methodData */); 192 PopConsoleString() /* methodData */);
186 EXPECT_EQ( 193 EXPECT_EQ(
187 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:" 194 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
188 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}", 195 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
189 PopConsoleString() /* total */); 196 PopConsoleString() /* total */);
190 EXPECT_EQ( 197 EXPECT_EQ(
191 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"]," 198 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"],"
192 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:" 199 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
193 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]", 200 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
194 PopConsoleString() /* modifiers */); 201 PopConsoleString() /* modifiers */);
195 EXPECT_EQ("instrument-key", PopConsoleString() /* instrumentKey */); 202 EXPECT_EQ("basic-card-payment-app-id",
203 PopConsoleString() /* instrumentKey */);
196 } 204 }
197 205
206 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppOpenWindowFailed) {
207 RegisterPaymentApp();
208
209 std::map<std::string, int64_t> registrationIds =
210 GetAllPaymentInstrumentRegistrationIDs();
211 ASSERT_EQ(2U, registrationIds.size());
212
213 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
214 registrationIds.at("bobpay-payment-app-id"), "https://bobpay.com",
215 "bobpay-payment-app-id"));
216 // InvokePaymentAppCallback returns empty method_name in case of failure, like
217 // in PaymentRequestRespondWithObserver::OnResponseRejected.
218 ASSERT_EQ("", response->method_name);
219
220 ClearStoragePartitionData();
221
222 registrationIds = GetAllPaymentInstrumentRegistrationIDs();
223 ASSERT_EQ(0U, registrationIds.size());
224
225 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
226 EXPECT_EQ("https://example.com/",
227 PopConsoleString() /* paymentRequestOrigin */);
228 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
229 EXPECT_EQ("[{\"supportedMethods\":[\"https://bobpay.com\"]}]",
230 PopConsoleString() /* methodData */);
231 EXPECT_EQ(
232 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
233 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
234 PopConsoleString() /* total */);
235 EXPECT_EQ(
236 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://"
237 "bobpay.com\"],"
238 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
239 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
240 PopConsoleString() /* modifiers */);
241 EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */);
242 }
198 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698