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

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

Issue 2887713002: PaymentHandler: Merge PaymentAppRequest and PaymentRequestEvent. (Closed)
Patch Set: PaymentHandler: Merge PaymentAppRequest and PaymentRequestEvent. Created 3 years, 7 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/public/browser/payment_app_provider.h" 9 #include "content/public/browser/payment_app_provider.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h" 16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace content { 19 namespace content {
20 namespace { 20 namespace {
21 21
22 using ::payments::mojom::PaymentAppRequest;
23 using ::payments::mojom::PaymentAppRequestPtr;
24 using ::payments::mojom::PaymentAppResponsePtr;
25 using ::payments::mojom::PaymentCurrencyAmount;
26 using ::payments::mojom::PaymentDetailsModifier;
27 using ::payments::mojom::PaymentDetailsModifierPtr;
28 using ::payments::mojom::PaymentItem;
29 using ::payments::mojom::PaymentMethodData;
30
22 void GetAllPaymentAppsCallback(const base::Closure& done_callback, 31 void GetAllPaymentAppsCallback(const base::Closure& done_callback,
23 PaymentAppProvider::PaymentApps* out_apps, 32 PaymentAppProvider::PaymentApps* out_apps,
24 PaymentAppProvider::PaymentApps apps) { 33 PaymentAppProvider::PaymentApps apps) {
25 *out_apps = std::move(apps); 34 *out_apps = std::move(apps);
26 done_callback.Run(); 35 done_callback.Run();
27 } 36 }
28 37
29 void InvokePaymentAppCallback( 38 void InvokePaymentAppCallback(const base::Closure& done_callback,
30 const base::Closure& done_callback, 39 PaymentAppResponsePtr* out_response,
31 payments::mojom::PaymentAppResponsePtr* out_response, 40 PaymentAppResponsePtr response) {
32 payments::mojom::PaymentAppResponsePtr response) {
33 *out_response = std::move(response); 41 *out_response = std::move(response);
34 done_callback.Run(); 42 done_callback.Run();
35 } 43 }
36 44
37 } // namespace 45 } // namespace
38 46
39 class PaymentAppBrowserTest : public ContentBrowserTest { 47 class PaymentAppBrowserTest : public ContentBrowserTest {
40 public: 48 public:
41 PaymentAppBrowserTest() {} 49 PaymentAppBrowserTest() {}
42 ~PaymentAppBrowserTest() override {} 50 ~PaymentAppBrowserTest() override {}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 std::vector<int64_t> ids; 94 std::vector<int64_t> ids;
87 for (const auto& app_info : apps) { 95 for (const auto& app_info : apps) {
88 for (const auto& instrument : app_info.second) { 96 for (const auto& instrument : app_info.second) {
89 ids.push_back(instrument->registration_id); 97 ids.push_back(instrument->registration_id);
90 } 98 }
91 } 99 }
92 100
93 return ids; 101 return ids;
94 } 102 }
95 103
96 payments::mojom::PaymentAppResponsePtr InvokePaymentApp( 104 PaymentAppResponsePtr InvokePaymentAppWithTestData(int64_t registration_id) {
97 int64_t registration_id) { 105 PaymentAppRequestPtr app_request = PaymentAppRequest::New();
98 payments::mojom::PaymentAppRequestPtr app_request = 106
99 payments::mojom::PaymentAppRequest::New(); 107 app_request->top_level_origin = GURL("https://example.com");
100 app_request->method_data.push_back( 108
101 payments::mojom::PaymentMethodData::New()); 109 app_request->payment_request_origin = GURL("https://example.com");
102 app_request->total = payments::mojom::PaymentItem::New(); 110
103 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); 111 app_request->payment_request_id = "payment-request-id";
112
113 app_request->method_data.push_back(PaymentMethodData::New());
114 app_request->method_data[0]->supported_methods = {"basic-card"};
115
116 app_request->total = PaymentItem::New();
117 app_request->total->amount = PaymentCurrencyAmount::New();
118 app_request->total->amount->currency = "USD";
119
120 PaymentDetailsModifierPtr modifier = PaymentDetailsModifier::New();
121 modifier->total = PaymentItem::New();
122 modifier->total->amount = PaymentCurrencyAmount::New();
123 modifier->total->amount->currency = "USD";
124 modifier->method_data = PaymentMethodData::New();
125 modifier->method_data->supported_methods = {"basic-card"};
126 app_request->modifiers.push_back(std::move(modifier));
127
128 app_request->instrument_key = "instrument-key";
104 129
105 base::RunLoop run_loop; 130 base::RunLoop run_loop;
106 payments::mojom::PaymentAppResponsePtr response; 131 PaymentAppResponsePtr response;
107 PaymentAppProvider::GetInstance()->InvokePaymentApp( 132 PaymentAppProvider::GetInstance()->InvokePaymentApp(
108 shell()->web_contents()->GetBrowserContext(), registration_id, 133 shell()->web_contents()->GetBrowserContext(), registration_id,
109 std::move(app_request), 134 std::move(app_request),
110 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(), 135 base::Bind(&InvokePaymentAppCallback, run_loop.QuitClosure(),
111 &response)); 136 &response));
112 run_loop.Run(); 137 run_loop.Run();
113 138
114 return response; 139 return response;
115 } 140 }
116 141
117 private: 142 private:
118 std::unique_ptr<net::EmbeddedTestServer> https_server_; 143 std::unique_ptr<net::EmbeddedTestServer> https_server_;
119 144
120 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest); 145 DISALLOW_COPY_AND_ASSIGN(PaymentAppBrowserTest);
121 }; 146 };
122 147
123 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) { 148 IN_PROC_BROWSER_TEST_F(PaymentAppBrowserTest, PaymentAppInvocation) {
124 RegisterPaymentApp(); 149 RegisterPaymentApp();
125 150
126 std::vector<int64_t> ids = GetAllPaymentAppIDs(); 151 std::vector<int64_t> ids = GetAllPaymentAppIDs();
127 ASSERT_EQ(1U, ids.size()); 152 ASSERT_EQ(1U, ids.size());
128 153
129 payments::mojom::PaymentAppResponsePtr response(InvokePaymentApp(ids[0])); 154 PaymentAppResponsePtr response(InvokePaymentAppWithTestData(ids[0]));
130 ASSERT_EQ("test", response->method_name); 155 ASSERT_EQ("test", response->method_name);
156
157 EXPECT_EQ("https://example.com/", PopConsoleString() /* topLevelOrigin */);
158 EXPECT_EQ("https://example.com/",
159 PopConsoleString() /* paymentRequestOrigin */);
160 EXPECT_EQ("payment-request-id", PopConsoleString() /* paymentRequestId */);
161 EXPECT_EQ("[{\"supportedMethods\":[\"basic-card\"]}]",
162 PopConsoleString() /* methodData */);
163 EXPECT_EQ(
164 "{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:iso:std:iso:"
165 "4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}",
166 PopConsoleString() /* total */);
167 EXPECT_EQ(
168 "[{\"additionalDisplayItems\":[],\"supportedMethods\":[\"basic-card\"],"
169 "\"total\":{\"amount\":{\"currency\":\"USD\",\"currencySystem\":\"urn:"
170 "iso:std:iso:4217\",\"value\":\"\"},\"label\":\"\",\"pending\":false}}]",
171 PopConsoleString() /* modifiers */);
172 EXPECT_EQ("instrument-key", PopConsoleString() /* instrumentKey */);
131 } 173 }
132 174
133 } // namespace content 175 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698