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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/payments/payment_app_browsertest.cc
diff --git a/content/browser/payments/payment_app_browsertest.cc b/content/browser/payments/payment_app_browsertest.cc
index f5e732ca7c3f8df4e1a840f2565abb40a83f0b97..c58b7af21aab5d3566e9d226ac384a0e79de3439 100644
--- a/content/browser/payments/payment_app_browsertest.cc
+++ b/content/browser/payments/payment_app_browsertest.cc
@@ -84,7 +84,7 @@ class PaymentAppBrowserTest : public ContentBrowserTest {
ASSERT_EQ("registered", script_result);
}
- std::vector<int64_t> GetAllPaymentAppIDs() {
+ std::map<std::string, int64_t> GetAllPaymentInstrumentRegistrationIDs() {
base::RunLoop run_loop;
PaymentAppProvider::PaymentApps apps;
PaymentAppProvider::GetInstance()->GetAllPaymentApps(
@@ -93,17 +93,21 @@ class PaymentAppBrowserTest : public ContentBrowserTest {
&apps));
run_loop.Run();
- std::vector<int64_t> ids;
+ std::map<std::string, int64_t> registrationIds;
for (const auto& app_info : apps) {
for (const auto& instrument : app_info.second) {
- ids.push_back(instrument->registration_id);
+ registrationIds.insert(std::pair<std::string, int64_t>(
+ instrument->instrument_key, instrument->registration_id));
}
}
- return ids;
+ return registrationIds;
}
- PaymentAppResponsePtr InvokePaymentAppWithTestData(int64_t registration_id) {
+ PaymentAppResponsePtr InvokePaymentAppWithTestData(
+ int64_t registration_id,
+ const std::string& supported_method,
+ const std::string& instrument_key) {
PaymentAppRequestPtr app_request = PaymentAppRequest::New();
app_request->top_level_origin = GURL("https://example.com");
@@ -113,7 +117,7 @@ class PaymentAppBrowserTest : public ContentBrowserTest {
app_request->payment_request_id = "payment-request-id";
app_request->method_data.push_back(PaymentMethodData::New());
- app_request->method_data[0]->supported_methods = {"basic-card"};
+ app_request->method_data[0]->supported_methods = {supported_method};
app_request->total = PaymentItem::New();
app_request->total->amount = PaymentCurrencyAmount::New();
@@ -124,10 +128,10 @@ class PaymentAppBrowserTest : public ContentBrowserTest {
modifier->total->amount = PaymentCurrencyAmount::New();
modifier->total->amount->currency = "USD";
modifier->method_data = PaymentMethodData::New();
- modifier->method_data->supported_methods = {"basic-card"};
+ modifier->method_data->supported_methods = {supported_method};
app_request->modifiers.push_back(std::move(modifier));
- app_request->instrument_key = "instrument-key";
+ app_request->instrument_key = instrument_key;
base::RunLoop run_loop;
PaymentAppResponsePtr response;
@@ -166,16 +170,19 @@ class PaymentAppBrowserTest : public ContentBrowserTest {
IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
RegisterPaymentApp();
- std::vector<int64_t> ids = GetAllPaymentAppIDs();
- ASSERT_EQ(1U, ids.size());
+ std::map<std::string, int64_t> registrationIds =
+ GetAllPaymentInstrumentRegistrationIDs();
+ ASSERT_EQ(2U, registrationIds.size());
- PaymentAppResponsePtr response(InvokePaymentAppWithTestData(ids[0]));
+ PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
+ registrationIds.at("basic-card-payment-app-id"), "basic-card",
+ "basic-card-payment-app-id"));
ASSERT_EQ("test", response->method_name);
ClearStoragePartitionData();
- ids = GetAllPaymentAppIDs();
- ASSERT_EQ(0U, ids.size());
+ registrationIds = GetAllPaymentInstrumentRegistrationIDs();
+ ASSERT_EQ(0U, registrationIds.size());
EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
EXPECT_EQ("https://example.com/",
@@ -192,7 +199,45 @@ IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
"\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
"iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
PopConsoleString() /* modifiers */);
- EXPECT_EQ("instrument-key", PopConsoleString() /* instrumentKey */);
+ EXPECT_EQ("basic-card-payment-app-id",
+ PopConsoleString() /* instrumentKey */);
}
+IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppOpenWindowFailed) {
+ RegisterPaymentApp();
+
+ std::map<std::string, int64_t> registrationIds =
+ GetAllPaymentInstrumentRegistrationIDs();
+ ASSERT_EQ(2U, registrationIds.size());
+
+ PaymentAppResponsePtr response(InvokePaymentAppWithTestData(
+ registrationIds.at("bobpay-payment-app-id"), "https://bobpay.com",
+ "bobpay-payment-app-id"));
+ // InvokePaymentAppCallback returns empty method_name in case of failure, like
+ // in PaymentRequestRespondWithObserver::OnResponseRejected.
+ ASSERT_EQ("", response->method_name);
+
+ ClearStoragePartitionData();
+
+ registrationIds = GetAllPaymentInstrumentRegistrationIDs();
+ ASSERT_EQ(0U, registrationIds.size());
+
+ EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
+ EXPECT_EQ("https://example.com/",
+ PopConsoleString() /* paymentRequestOrigin */);
+ EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
+ EXPECT_EQ("[{\"supportedMethods\":[\"https://bobpay.com\"]}]",
+ PopConsoleString() /* methodData */);
+ EXPECT_EQ(
+ "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
+ "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
+ PopConsoleString() /* total */);
+ EXPECT_EQ(
+ "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://"
+ "bobpay.com\"],"
+ "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
+ "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
+ PopConsoleString() /* modifiers */);
+ EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */);
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698