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

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

Issue 2873903003: PaymentHandler: Stop using GetAllManifests() in content side tests. (Closed)
Patch Set: PaymentHandler: Use GetAllPaymentApps() in content side. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <cstddef> 5 #include <cstddef>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ASSERT_EQ(1U, manifest.second->options.size()); 138 ASSERT_EQ(1U, manifest.second->options.size());
139 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value()); 139 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value());
140 EXPECT_EQ("Visa ****", manifest.second->options[0]->name); 140 EXPECT_EQ("Visa ****", manifest.second->options[0]->name);
141 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id); 141 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id);
142 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size()); 142 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size());
143 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]); 143 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]);
144 } 144 }
145 } 145 }
146 146
147 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) { 147 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) {
148 static const struct { 148 PaymentManager* manager1 = CreatePaymentManager(
149 const char* scopeUrl; 149 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js"));
150 const char* scriptUrl; 150 PaymentManager* manager2 = CreatePaymentManager(
151 } kPaymentAppInfo[] = { 151 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js"));
152 {"https://example.com/a", "https://example.com/a/script.js"},
153 {"https://example.com/b", "https://example.com/b/script.js"},
154 {"https://example.com/c", "https://example.com/c/script.js"}};
155 152
156 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { 153 PaymentHandlerStatus status;
157 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), 154 SetPaymentInstrument(manager1, "test_key1",
158 GURL(kPaymentAppInfo[i].scriptUrl)); 155 payments::mojom::PaymentInstrument::New(),
159 } 156 base::Bind(&SetPaymentInstrumentCallback, &status));
157 SetPaymentInstrument(manager2, "test_key2",
158 payments::mojom::PaymentInstrument::New(),
159 base::Bind(&SetPaymentInstrumentCallback, &status));
160 SetPaymentInstrument(manager2, "test_key3",
161 payments::mojom::PaymentInstrument::New(),
162 base::Bind(&SetPaymentInstrumentCallback, &status));
160 163
161 PaymentAppProvider::Manifests manifests; 164 PaymentAppProvider::PaymentApps apps;
162 bool called = false; 165 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps));
163 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); 166 ASSERT_EQ(2U, apps.size());
164 ASSERT_TRUE(called);
165 ASSERT_EQ(3U, manifests.size());
166 167
167 payments::mojom::PaymentAppRequestPtr app_request = 168 payments::mojom::PaymentAppRequestPtr app_request =
168 payments::mojom::PaymentAppRequest::New(); 169 payments::mojom::PaymentAppRequest::New();
169 app_request->method_data.push_back(payments::mojom::PaymentMethodData::New()); 170 app_request->method_data.push_back(payments::mojom::PaymentMethodData::New());
170 app_request->total = payments::mojom::PaymentItem::New(); 171 app_request->total = payments::mojom::PaymentItem::New();
171 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); 172 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New();
172 173
173 called = false; 174 bool called = false;
174 InvokePaymentApp(manifests[1].first, std::move(app_request), 175 InvokePaymentApp(apps[GURL("https://hellopay.com/")][0]->registration_id,
176 std::move(app_request),
175 base::Bind(&InvokePaymentAppCallback, &called)); 177 base::Bind(&InvokePaymentAppCallback, &called));
176 ASSERT_TRUE(called); 178 ASSERT_TRUE(called);
177 179
178 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); 180 EXPECT_EQ(apps[GURL("https://hellopay.com/")][0]->registration_id,
179 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); 181 last_sw_registration_id());
180 } 182 }
181 183
182 TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) { 184 TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) {
183 PaymentManager* manager1 = CreatePaymentManager( 185 PaymentManager* manager1 = CreatePaymentManager(
184 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); 186 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js"));
185 PaymentManager* manager2 = CreatePaymentManager( 187 PaymentManager* manager2 = CreatePaymentManager(
186 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js")); 188 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js"));
187 189
188 PaymentHandlerStatus status; 190 PaymentHandlerStatus status;
189 SetPaymentInstrument(manager1, "test_key1", 191 SetPaymentInstrument(manager1, "test_key1",
190 payments::mojom::PaymentInstrument::New(), 192 payments::mojom::PaymentInstrument::New(),
191 base::Bind(&SetPaymentInstrumentCallback, &status)); 193 base::Bind(&SetPaymentInstrumentCallback, &status));
192 SetPaymentInstrument(manager2, "test_key2", 194 SetPaymentInstrument(manager2, "test_key2",
193 payments::mojom::PaymentInstrument::New(), 195 payments::mojom::PaymentInstrument::New(),
194 base::Bind(&SetPaymentInstrumentCallback, &status)); 196 base::Bind(&SetPaymentInstrumentCallback, &status));
195 SetPaymentInstrument(manager2, "test_key3", 197 SetPaymentInstrument(manager2, "test_key3",
196 payments::mojom::PaymentInstrument::New(), 198 payments::mojom::PaymentInstrument::New(),
197 base::Bind(&SetPaymentInstrumentCallback, &status)); 199 base::Bind(&SetPaymentInstrumentCallback, &status));
198 200
199 PaymentAppProvider::PaymentApps apps; 201 PaymentAppProvider::PaymentApps apps;
200 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); 202 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps));
201 203
202 ASSERT_EQ(2U, apps.size()); 204 ASSERT_EQ(2U, apps.size());
203 ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size()); 205 ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size());
204 ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size()); 206 ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size());
205 } 207 }
206 208
207 } // namespace content 209 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_browsertest.cc ('k') | content/test/data/payments/payment_app_invocation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698