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

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

Issue 2887713002: PaymentHandler: Merge PaymentAppRequest and PaymentRequestEvent. (Closed)
Patch Set: rebase 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"
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;
25 using ::payments::mojom::PaymentAppRequestPtr;
26 using ::payments::mojom::PaymentAppResponsePtr;
27 using ::payments::mojom::PaymentCurrencyAmount;
28 using ::payments::mojom::PaymentDetailsModifier;
29 using ::payments::mojom::PaymentDetailsModifierPtr;
30 using ::payments::mojom::PaymentItem;
31 using ::payments::mojom::PaymentMethodData;
32
24 void GetAllPaymentAppsCallback(const base::Closure& done_callback, 33 void GetAllPaymentAppsCallback(const base::Closure& done_callback,
25 PaymentAppProvider::PaymentApps* out_apps, 34 PaymentAppProvider::PaymentApps* out_apps,
26 PaymentAppProvider::PaymentApps apps) { 35 PaymentAppProvider::PaymentApps apps) {
27 *out_apps = std::move(apps); 36 *out_apps = std::move(apps);
28 done_callback.Run(); 37 done_callback.Run();
29 } 38 }
30 39
31 void InvokePaymentAppCallback( 40 void InvokePaymentAppCallback(const base::Closure& done_callback,
32 const base::Closure& done_callback, 41 PaymentAppResponsePtr* out_response,
33 payments::mojom::PaymentAppResponsePtr* out_response, 42 PaymentAppResponsePtr response) {
34 payments::mojom::PaymentAppResponsePtr response) {
35 *out_response = std::move(response); 43 *out_response = std::move(response);
36 done_callback.Run(); 44 done_callback.Run();
37 } 45 }
38 46
39 } // namespace 47 } // namespace
40 48
41 class PaymentAppBrowserTest : public ContentBrowserTest { 49 class PaymentAppBrowserTest : public ContentBrowserTest {
42 public: 50 public:
43 PaymentAppBrowserTest() {} 51 PaymentAppBrowserTest() {}
44 ~PaymentAppBrowserTest() override {} 52 ~PaymentAppBrowserTest() override {}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 std::vector<int64_t> ids; 96 std::vector<int64_t> ids;
89 for (const auto& app_info : apps) { 97 for (const auto& app_info : apps) {
90 for (const auto& instrument : app_info.second) { 98 for (const auto& instrument : app_info.second) {
91 ids.push_back(instrument->registration_id); 99 ids.push_back(instrument->registration_id);
92 } 100 }
93 } 101 }
94 102
95 return ids; 103 return ids;
96 } 104 }
97 105
98 payments::mojom::PaymentAppResponsePtr InvokePaymentApp( 106 PaymentAppResponsePtr InvokePaymentAppWithTestData(int64_t registration_id) {
99 int64_t registration_id) { 107 PaymentAppRequestPtr app_request = PaymentAppRequest::New();
100 payments::mojom::PaymentAppRequestPtr app_request = 108
101 payments::mojom::PaymentAppRequest::New(); 109 app_request->top_level_origin = GURL("https://example.com");
102 app_request->method_data.push_back( 110
103 payments::mojom::PaymentMethodData::New()); 111 app_request->payment_request_origin = GURL("https://example.com");
104 app_request->total = payments::mojom::PaymentItem::New(); 112
105 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); 113 app_request->payment_request_id = "payment-request-id";
114
115 app_request->method_data.push_back(PaymentMethodData::New());
116 app_request->method_data[0]->supported_methods = {"basic-card"};
117
118 app_request->total = PaymentItem::New();
119 app_request->total->amount = PaymentCurrencyAmount::New();
120 app_request->total->amount->currency = "USD";
121
122 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New();
123 modifier->total = PaymentItem::New();
124 modifier->total->amount = PaymentCurrencyAmount::New();
125 modifier->total->amount->currency = "USD";
126 modifier->method_data = PaymentMethodData::New();
127 modifier->method_data->supported_methods = {"basic-card"};
128 app_request->modifiers.push_back(std::move(modifier));
129
130 app_request->instrument_key = "instrument-key";
106 131
107 base::RunLoop run_loop; 132 base::RunLoop run_loop;
108 payments::mojom::PaymentAppResponsePtr response; 133 PaymentAppResponsePtr response;
109 PaymentAppProvider::GetInstance()->InvokePaymentApp( 134 PaymentAppProvider::GetInstance()->InvokePaymentApp(
110 shell()->web_contents()->GetBrowserContext(), registration_id, 135 shell()->web_contents()->GetBrowserContext(), registration_id,
111 std::move(app_request), 136 std::move(app_request),
112 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(), 137 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(),
113 &response)); 138 &response));
114 run_loop.Run(); 139 run_loop.Run();
115 140
116 return response; 141 return response;
117 } 142 }
118 143
(...skipping 18 matching lines...) Expand all
137 162
138 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); 163 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
139 }; 164 };
140 165
141 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) { 166 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
142 RegisterPaymentApp(); 167 RegisterPaymentApp();
143 168
144 std::vector<int64_t> ids = GetAllPaymentAppIDs(); 169 std::vector<int64_t> ids = GetAllPaymentAppIDs();
145 ASSERT_EQ(1U, ids.size()); 170 ASSERT_EQ(1U, ids.size());
146 171
147 payments::mojom::PaymentAppResponsePtr response(InvokePaymentApp(ids[0])); 172 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(ids[0]));
148 ASSERT_EQ("test", response->method_name); 173 ASSERT_EQ("test", response->method_name);
149 174
150 ClearStoragePartitionData(); 175 ClearStoragePartitionData();
151 176
152 ids = GetAllPaymentAppIDs(); 177 ids = GetAllPaymentAppIDs();
153 ASSERT_EQ(0U, ids.size()); 178 ASSERT_EQ(0U, ids.size());
179
180 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
181 EXPECT_EQ("https://example.com/",
182 PopConsoleString() /* paymentRequestOrigin */);
183 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
184 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]",
185 PopConsoleString() /* methodData */);
186 EXPECT_EQ(
187 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
188 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
189 PopConsoleString() /* total */);
190 EXPECT_EQ(
191 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"],"
192 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
193 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
194 PopConsoleString() /* modifiers */);
195 EXPECT_EQ("instrument-key", PopConsoleString() /* instrumentKey */);
154 } 196 }
155 197
156 } // namespace content 198 } // namespace content
OLDNEW
« no previous file with comments | « components/payments/mojom/payment_app.mojom ('k') | content/renderer/service_worker/service_worker_type_converters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698