| OLD | NEW |
| 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" |
| 11 #include "content/public/browser/payment_app_provider.h" | 11 #include "content/public/browser/payment_app_provider.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 15 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
| 16 #include "content/public/test/content_browser_test_utils.h" | 16 #include "content/public/test/content_browser_test_utils.h" |
| 17 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 using ::payments::mojom::PaymentAppRequest; | 24 using ::payments::mojom::PaymentRequestEventData; |
| 25 using ::payments::mojom::PaymentAppRequestPtr; | 25 using ::payments::mojom::PaymentRequestEventDataPtr; |
| 26 using ::payments::mojom::PaymentAppResponsePtr; | 26 using ::payments::mojom::PaymentAppResponsePtr; |
| 27 using ::payments::mojom::PaymentCurrencyAmount; | 27 using ::payments::mojom::PaymentCurrencyAmount; |
| 28 using ::payments::mojom::PaymentDetailsModifier; | 28 using ::payments::mojom::PaymentDetailsModifier; |
| 29 using ::payments::mojom::PaymentDetailsModifierPtr; | 29 using ::payments::mojom::PaymentDetailsModifierPtr; |
| 30 using ::payments::mojom::PaymentItem; | 30 using ::payments::mojom::PaymentItem; |
| 31 using ::payments::mojom::PaymentMethodData; | 31 using ::payments::mojom::PaymentMethodData; |
| 32 | 32 |
| 33 void GetAllPaymentAppsCallback(const base::Closure& done_callback, | 33 void GetAllPaymentAppsCallback(const base::Closure& done_callback, |
| 34 PaymentAppProvider::PaymentApps* out_apps, | 34 PaymentAppProvider::PaymentApps* out_apps, |
| 35 PaymentAppProvider::PaymentApps apps) { | 35 PaymentAppProvider::PaymentApps apps) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 return registrationIds; | 104 return registrationIds; |
| 105 } | 105 } |
| 106 | 106 |
| 107 PaymentAppResponsePtr InvokePaymentAppWithTestData( | 107 PaymentAppResponsePtr InvokePaymentAppWithTestData( |
| 108 int64_t registration_id, | 108 int64_t registration_id, |
| 109 const std::string& supported_method, | 109 const std::string& supported_method, |
| 110 const std::string& instrument_key) { | 110 const std::string& instrument_key) { |
| 111 PaymentAppRequestPtr app_request = PaymentAppRequest::New(); | 111 PaymentRequestEventDataPtr event_data = PaymentRequestEventData::New(); |
| 112 | 112 |
| 113 app_request->top_level_origin = GURL("https://example.com"); | 113 event_data->top_level_origin = GURL("https://example.com"); |
| 114 | 114 |
| 115 app_request->payment_request_origin = GURL("https://example.com"); | 115 event_data->payment_request_origin = GURL("https://example.com"); |
| 116 | 116 |
| 117 app_request->payment_request_id = "payment-request-id"; | 117 event_data->payment_request_id = "payment-request-id"; |
| 118 | 118 |
| 119 app_request->method_data.push_back(PaymentMethodData::New()); | 119 event_data->method_data.push_back(PaymentMethodData::New()); |
| 120 app_request->method_data[0]->supported_methods = {supported_method}; | 120 event_data->method_data[0]->supported_methods = {supported_method}; |
| 121 | 121 |
| 122 app_request->total = PaymentItem::New(); | 122 event_data->total = PaymentItem::New(); |
| 123 app_request->total->amount = PaymentCurrencyAmount::New(); | 123 event_data->total->amount = PaymentCurrencyAmount::New(); |
| 124 app_request->total->amount->currency = "USD"; | 124 event_data->total->amount->currency = "USD"; |
| 125 | 125 |
| 126 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New(); | 126 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New(); |
| 127 modifier->total = PaymentItem::New(); | 127 modifier->total = PaymentItem::New(); |
| 128 modifier->total->amount = PaymentCurrencyAmount::New(); | 128 modifier->total->amount = PaymentCurrencyAmount::New(); |
| 129 modifier->total->amount->currency = "USD"; | 129 modifier->total->amount->currency = "USD"; |
| 130 modifier->method_data = PaymentMethodData::New(); | 130 modifier->method_data = PaymentMethodData::New(); |
| 131 modifier->method_data->supported_methods = {supported_method}; | 131 modifier->method_data->supported_methods = {supported_method}; |
| 132 app_request->modifiers.push_back(std::move(modifier)); | 132 event_data->modifiers.push_back(std::move(modifier)); |
| 133 | 133 |
| 134 app_request->instrument_key = instrument_key; | 134 event_data->instrument_key = instrument_key; |
| 135 | 135 |
| 136 base::RunLoop run_loop; | 136 base::RunLoop run_loop; |
| 137 PaymentAppResponsePtr response; | 137 PaymentAppResponsePtr response; |
| 138 PaymentAppProvider::GetInstance()->InvokePaymentApp( | 138 PaymentAppProvider::GetInstance()->InvokePaymentApp( |
| 139 shell()->web_contents()->GetBrowserContext(), registration_id, | 139 shell()->web_contents()->GetBrowserContext(), registration_id, |
| 140 std::move(app_request), | 140 std::move(event_data), |
| 141 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(), | 141 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(), |
| 142 &response)); | 142 &response)); |
| 143 run_loop.Run(); | 143 run_loop.Run(); |
| 144 | 144 |
| 145 return response; | 145 return response; |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ClearStoragePartitionData() { | 148 void ClearStoragePartitionData() { |
| 149 // Clear data from the storage partition. Parameters are set to clear data | 149 // Clear data from the storage partition. Parameters are set to clear data |
| 150 // for service workers, for all origins, for an unbounded time range. | 150 // for service workers, for all origins, for an unbounded time range. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 PopConsoleString() /* total */); | 234 PopConsoleString() /* total */); |
| 235 EXPECT_EQ( | 235 EXPECT_EQ( |
| 236 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://" | 236 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"https://" |
| 237 "bobpay.com\"]," | 237 "bobpay.com\"]," |
| 238 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:" | 238 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:" |
| 239 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]", | 239 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]", |
| 240 PopConsoleString() /* modifiers */); | 240 PopConsoleString() /* modifiers */); |
| 241 EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */); | 241 EXPECT_EQ("bobpay-payment-app-id", PopConsoleString() /* instrumentKey */); |
| 242 } | 242 } |
| 243 } // namespace content | 243 } // namespace content |
| OLD | NEW |