blob: 5e179fb4382405e527f11434fafadbc14789e5e1 [file] [log] [blame]
Rouslan Solomakhinde012532017-09-20 15:18:341// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/payments/content/manifest_verifier.h"
6
7#include <stdint.h>
8#include <utility>
9
Rouslan Solomakhin438d8c92017-10-26 21:33:1810#include "base/run_loop.h"
11#include "chrome/browser/profiles/profile.h"
Rouslan Solomakhinde012532017-09-20 15:18:3412#include "chrome/browser/ui/browser.h"
13#include "chrome/browser/ui/tabs/tab_strip_model.h"
14#include "chrome/browser/web_data_service_factory.h"
15#include "chrome/test/base/in_process_browser_test.h"
Rouslan Solomakhinde012532017-09-20 15:18:3416#include "components/payments/content/payment_manifest_web_data_service.h"
Jay Civellia7d22b42017-10-24 18:38:0717#include "components/payments/content/utility/payment_manifest_parser.h"
Rouslan Solomakhin438d8c92017-10-26 21:33:1818#include "components/payments/core/test_payment_manifest_downloader.h"
Rouslan Solomakhinde012532017-09-20 15:18:3419#include "content/public/browser/browser_context.h"
20#include "content/public/browser/storage_partition.h"
21#include "net/test/embedded_test_server/embedded_test_server.h"
22#include "net/url_request/url_request_context_getter.h"
23#include "testing/gtest/include/gtest/gtest.h"
Rouslan Solomakhinde012532017-09-20 15:18:3424
25namespace payments {
26namespace {
27
Rouslan Solomakhinde012532017-09-20 15:18:3428// Tests for the manifest verifier.
29class ManifestVerifierBrowserTest : public InProcessBrowserTest {
30 public:
31 ManifestVerifierBrowserTest() {}
32 ~ManifestVerifierBrowserTest() override {}
33
34 // Starts the HTTPS test server on localhost.
35 void SetUpOnMainThread() override {
36 https_server_ = std::make_unique<net::EmbeddedTestServer>(
37 net::EmbeddedTestServer::TYPE_HTTPS);
38 ASSERT_TRUE(https_server_->InitializeAndListen());
39 https_server_->ServeFilesFromSourceDirectory(
40 "components/test/data/payments");
41 https_server_->StartAcceptingConnections();
42 }
43
44 // Runs the verifier on the |apps| and blocks until the verifier has finished
45 // using all resources.
46 void Verify(content::PaymentAppProvider::PaymentApps apps) {
Rouslan Solomakhindbf593d92017-11-21 19:20:5747 content::WebContents* web_contents =
48 browser()->tab_strip_model()->GetActiveWebContents();
49 content::BrowserContext* context = web_contents->GetBrowserContext();
Rouslan Solomakhinde012532017-09-20 15:18:3450 auto downloader = std::make_unique<TestDownloader>(
Rouslan Solomakhin438d8c92017-10-26 21:33:1851 content::BrowserContext::GetDefaultStoragePartition(context)
Rouslan Solomakhinde012532017-09-20 15:18:3452 ->GetURLRequestContext());
Rouslan Solomakhin438d8c92017-10-26 21:33:1853 downloader->AddTestServerURL("https://", https_server_->GetURL("/"));
gogerald84ae6262018-02-06 06:21:4654 auto parser = std::make_unique<payments::PaymentManifestParser>();
55 auto cache = WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
56 Profile::FromBrowserContext(context),
57 ServiceAccessType::EXPLICIT_ACCESS);
Rouslan Solomakhinde012532017-09-20 15:18:3458
gogerald84ae6262018-02-06 06:21:4659 ManifestVerifier verifier(web_contents, downloader.get(), parser.get(),
60 cache.get());
Rouslan Solomakhinde012532017-09-20 15:18:3461
62 base::RunLoop run_loop;
Rouslan Solomakhinde012532017-09-20 15:18:3463 verifier.Verify(
64 std::move(apps),
65 base::BindOnce(&ManifestVerifierBrowserTest::OnPaymentAppsVerified,
66 base::Unretained(this)),
Rouslan Solomakhin438d8c92017-10-26 21:33:1867 run_loop.QuitClosure());
Rouslan Solomakhinde012532017-09-20 15:18:3468 run_loop.Run();
69 }
70
71 // Returns the apps that have been verified by the Verify() method.
72 const content::PaymentAppProvider::PaymentApps& verified_apps() const {
73 return verified_apps_;
74 }
75
76 // Expects that the verified payment app with |id| has the |expected_scope|
77 // and the |expected_methods|.
78 void ExpectApp(int64_t id,
79 const std::string& expected_scope,
80 const std::set<std::string>& expected_methods) {
Rouslan Solomakhin478d93e32017-10-27 17:06:3781 const auto& it = verified_apps().find(id);
82 ASSERT_NE(verified_apps().end(), it);
83 EXPECT_EQ(GURL(expected_scope), it->second->scope);
84 std::set<std::string> actual_methods(it->second->enabled_methods.begin(),
85 it->second->enabled_methods.end());
Rouslan Solomakhinde012532017-09-20 15:18:3486 EXPECT_EQ(expected_methods, actual_methods);
87 }
88
89 private:
90 // Called by the verifier upon completed verification. These |apps| have only
91 // valid payment methods.
92 void OnPaymentAppsVerified(content::PaymentAppProvider::PaymentApps apps) {
93 verified_apps_ = std::move(apps);
94 }
95
Rouslan Solomakhinde012532017-09-20 15:18:3496 // Serves the payment method manifest files.
97 std::unique_ptr<net::EmbeddedTestServer> https_server_;
98
99 // The apps that have been verified by the Verify() method.
100 content::PaymentAppProvider::PaymentApps verified_apps_;
101
Rouslan Solomakhinde012532017-09-20 15:18:34102 DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest);
103};
104
105// Absence of payment handlers should result in absence of verified payment
106// handlers.
107IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoApps) {
108 {
109 Verify(content::PaymentAppProvider::PaymentApps());
110
111 EXPECT_TRUE(verified_apps().empty());
112 }
113
114 // Repeat verifications should have identical results.
115 {
116 Verify(content::PaymentAppProvider::PaymentApps());
117
118 EXPECT_TRUE(verified_apps().empty());
119 }
120}
121
122// A payment handler without any payment method names is not valid.
123IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoMethods) {
124 {
125 content::PaymentAppProvider::PaymentApps apps;
126 apps[0] = std::make_unique<content::StoredPaymentApp>();
127 apps[0]->scope = GURL("https://bobpay.com/webpay");
128
129 Verify(std::move(apps));
130
131 EXPECT_TRUE(verified_apps().empty());
132 }
133
134 // Repeat verifications should have identical results.
135 {
136 content::PaymentAppProvider::PaymentApps apps;
137 apps[0] = std::make_unique<content::StoredPaymentApp>();
138 apps[0]->scope = GURL("https://bobpay.com/webpay");
139
140 Verify(std::move(apps));
141
142 EXPECT_TRUE(verified_apps().empty());
143 }
144}
145
146// A payment handler with an unknown non-URL payment method name is not valid.
147IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
148 UnknownPaymentMethodNameIsRemoved) {
149 {
150 content::PaymentAppProvider::PaymentApps apps;
151 apps[0] = std::make_unique<content::StoredPaymentApp>();
152 apps[0]->scope = GURL("https://bobpay.com/webpay");
153 apps[0]->enabled_methods.push_back("unknown");
154
155 Verify(std::move(apps));
156
157 EXPECT_TRUE(verified_apps().empty());
158 }
159
160 // Repeat verifications should have identical results.
161 {
162 content::PaymentAppProvider::PaymentApps apps;
163 apps[0] = std::make_unique<content::StoredPaymentApp>();
164 apps[0]->scope = GURL("https://bobpay.com/webpay");
165 apps[0]->enabled_methods.push_back("unknown");
166
167 Verify(std::move(apps));
168
169 EXPECT_TRUE(verified_apps().empty());
170 }
171}
172
173// A payment handler with "basic-card" payment method name is valid.
174IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, KnownPaymentMethodName) {
175 {
176 content::PaymentAppProvider::PaymentApps apps;
177 apps[0] = std::make_unique<content::StoredPaymentApp>();
178 apps[0]->scope = GURL("https://bobpay.com/webpay");
179 apps[0]->enabled_methods.push_back("basic-card");
180
181 Verify(std::move(apps));
182
183 EXPECT_EQ(1U, verified_apps().size());
184 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
185 }
186
187 // Repeat verifications should have identical results.
188 {
189 content::PaymentAppProvider::PaymentApps apps;
190 apps[0] = std::make_unique<content::StoredPaymentApp>();
191 apps[0]->scope = GURL("https://bobpay.com/webpay");
192 apps[0]->enabled_methods.push_back("basic-card");
193
194 Verify(std::move(apps));
195
196 EXPECT_EQ(1U, verified_apps().size());
197 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
198 }
199}
200
201// A payment handler with both "basic-card" and "interledger" payment method
202// names is valid.
203IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
204 TwoKnownPaymentMethodNames) {
205 {
206 content::PaymentAppProvider::PaymentApps apps;
207 apps[0] = std::make_unique<content::StoredPaymentApp>();
208 apps[0]->scope = GURL("https://bobpay.com/webpay");
209 apps[0]->enabled_methods.push_back("basic-card");
210 apps[0]->enabled_methods.push_back("interledger");
211
212 Verify(std::move(apps));
213
214 EXPECT_EQ(1U, verified_apps().size());
215 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"});
216 }
217
218 // Repeat verifications should have identical results.
219 {
220 content::PaymentAppProvider::PaymentApps apps;
221 apps[0] = std::make_unique<content::StoredPaymentApp>();
222 apps[0]->scope = GURL("https://bobpay.com/webpay");
223 apps[0]->enabled_methods.push_back("basic-card");
224 apps[0]->enabled_methods.push_back("interledger");
225
226 Verify(std::move(apps));
227
228 EXPECT_EQ(1U, verified_apps().size());
229 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"});
230 }
231}
232
233// Two payment handlers with "basic-card" payment method names are both valid.
234IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
235 TwoAppsWithKnownPaymentMethodNames) {
236 {
237 content::PaymentAppProvider::PaymentApps apps;
238 apps[0] = std::make_unique<content::StoredPaymentApp>();
239 apps[0]->scope = GURL("https://bobpay.com/webpay");
240 apps[0]->enabled_methods.push_back("basic-card");
241 apps[1] = std::make_unique<content::StoredPaymentApp>();
242 apps[1]->scope = GURL("https://alicepay.com/webpay");
243 apps[1]->enabled_methods.push_back("basic-card");
244
245 Verify(std::move(apps));
246
247 EXPECT_EQ(2U, verified_apps().size());
248 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
249 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"});
250 }
251
252 // Repeat verifications should have identical results.
253 {
254 content::PaymentAppProvider::PaymentApps apps;
255 apps[0] = std::make_unique<content::StoredPaymentApp>();
256 apps[0]->scope = GURL("https://bobpay.com/webpay");
257 apps[0]->enabled_methods.push_back("basic-card");
258 apps[1] = std::make_unique<content::StoredPaymentApp>();
259 apps[1]->scope = GURL("https://alicepay.com/webpay");
260 apps[1]->enabled_methods.push_back("basic-card");
261 Verify(std::move(apps));
262
263 EXPECT_EQ(2U, verified_apps().size());
264 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
265 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"});
266 }
267}
268
269// Verify that a payment handler from https://bobpay.com/webpay can use the
270// payment method name https://frankpay.com/webpay, because
271// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
272IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
273 BobPayHandlerCanUseMethodThatSupportsAllOrigins) {
274 {
275 content::PaymentAppProvider::PaymentApps apps;
276 apps[0] = std::make_unique<content::StoredPaymentApp>();
277 apps[0]->scope = GURL("https://bobpay.com/webpay");
278 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
279
280 Verify(std::move(apps));
281
282 EXPECT_EQ(1U, verified_apps().size());
283 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"});
284 }
285
286 // Repeat verifications should have identical results.
287 {
288 content::PaymentAppProvider::PaymentApps apps;
289 apps[0] = std::make_unique<content::StoredPaymentApp>();
290 apps[0]->scope = GURL("https://bobpay.com/webpay");
291 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
292 Verify(std::move(apps));
293
294 EXPECT_EQ(1U, verified_apps().size());
295 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"});
296 }
297}
298
299// Verify that a payment handler from an unreachable website can use the payment
300// method name https://frankpay.com/webpay, because
301// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
302IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
303 Handler404CanUseMethodThatSupportsAllOrigins) {
304 {
305 content::PaymentAppProvider::PaymentApps apps;
306 apps[0] = std::make_unique<content::StoredPaymentApp>();
307 apps[0]->scope = GURL("https://404.com/webpay");
308 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
309
310 Verify(std::move(apps));
311
312 EXPECT_EQ(1U, verified_apps().size());
313 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"});
314 }
315
316 // Repeat verifications should have identical results.
317 {
318 content::PaymentAppProvider::PaymentApps apps;
319 apps[0] = std::make_unique<content::StoredPaymentApp>();
320 apps[0]->scope = GURL("https://404.com/webpay");
321 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
322 Verify(std::move(apps));
323
324 EXPECT_EQ(1U, verified_apps().size());
325 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"});
326 }
327}
328
329// Verify that a payment handler from anywhere on https://bobpay.com can use the
330// payment method name from anywhere else on https://bobpay.com, because of the
331// origin match.
332IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
333 BobPayCanUseAnyMethodOnOwnOrigin) {
334 {
335 content::PaymentAppProvider::PaymentApps apps;
336 apps[0] = std::make_unique<content::StoredPaymentApp>();
337 apps[0]->scope = GURL("https://bobpay.com/anything/here");
338 apps[0]->enabled_methods.push_back(
339 "https://bobpay.com/does/not/matter/whats/here");
340
341 Verify(std::move(apps));
342
343 EXPECT_EQ(1U, verified_apps().size());
344 ExpectApp(0, "https://bobpay.com/anything/here",
345 {"https://bobpay.com/does/not/matter/whats/here"});
346 }
347
348 // Repeat verifications should have identical results.
349 {
350 content::PaymentAppProvider::PaymentApps apps;
351 apps[0] = std::make_unique<content::StoredPaymentApp>();
352 apps[0]->scope = GURL("https://bobpay.com/anything/here");
353 apps[0]->enabled_methods.push_back(
354 "https://bobpay.com/does/not/matter/whats/here");
355 Verify(std::move(apps));
356
357 EXPECT_EQ(1U, verified_apps().size());
358 ExpectApp(0, "https://bobpay.com/anything/here",
359 {"https://bobpay.com/does/not/matter/whats/here"});
360 }
361}
362
363// Verify that a payment handler from anywhere on an unreachable website can use
364// the payment method name from anywhere else on the same unreachable website,
365// because they have identical origin.
366IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
367 Handler404CanUseAnyMethodOnOwnOrigin) {
368 {
369 content::PaymentAppProvider::PaymentApps apps;
370 apps[0] = std::make_unique<content::StoredPaymentApp>();
371 apps[0]->scope = GURL("https://404.com/anything/here");
372 apps[0]->enabled_methods.push_back(
373 "https://404.com/does/not/matter/whats/here");
374
375 Verify(std::move(apps));
376
377 EXPECT_EQ(1U, verified_apps().size());
378 ExpectApp(0, "https://404.com/anything/here",
379 {"https://404.com/does/not/matter/whats/here"});
380 }
381
382 // Repeat verifications should have identical results.
383 {
384 content::PaymentAppProvider::PaymentApps apps;
385 apps[0] = std::make_unique<content::StoredPaymentApp>();
386 apps[0]->scope = GURL("https://404.com/anything/here");
387 apps[0]->enabled_methods.push_back(
388 "https://404.com/does/not/matter/whats/here");
389 Verify(std::move(apps));
390
391 EXPECT_EQ(1U, verified_apps().size());
392 ExpectApp(0, "https://404.com/anything/here",
393 {"https://404.com/does/not/matter/whats/here"});
394 }
395}
396
397// Verify that only the payment handler from https://alicepay.com/webpay can use
398// payment methods https://georgepay.com/webpay and https://ikepay.com/webpay,
399// because both https://georgepay.com/payment-manifest.json and
400// https://ikepay.com/payment-manifest.json contain "supported_origins":
401// ["https://alicepay.com"]. The payment handler from https://bobpay.com/webpay
402// cannot use these payment methods, however.
403IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, OneSupportedOrigin) {
404 {
405 content::PaymentAppProvider::PaymentApps apps;
406 apps[0] = std::make_unique<content::StoredPaymentApp>();
407 apps[0]->scope = GURL("https://alicepay.com/webpay");
408 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
409 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
410 apps[1] = std::make_unique<content::StoredPaymentApp>();
411 apps[1]->scope = GURL("https://bobpay.com/webpay");
412 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
413 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
414
415 Verify(std::move(apps));
416
417 EXPECT_EQ(1U, verified_apps().size());
418 ExpectApp(0, "https://alicepay.com/webpay",
419 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"});
420 }
421
422 // Repeat verifications should have identical results.
423 {
424 content::PaymentAppProvider::PaymentApps apps;
425 apps[0] = std::make_unique<content::StoredPaymentApp>();
426 apps[0]->scope = GURL("https://alicepay.com/webpay");
427 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
428 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
429 apps[1] = std::make_unique<content::StoredPaymentApp>();
430 apps[1]->scope = GURL("https://bobpay.com/webpay");
431 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
432 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
433
434 Verify(std::move(apps));
435
436 EXPECT_EQ(1U, verified_apps().size());
437 ExpectApp(0, "https://alicepay.com/webpay",
438 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"});
439 }
440}
441
442// Verify that a payment handler from https://alicepay.com/webpay can use all
443// three of non-URL payment method name, same-origin URL payment method name,
444// and different-origin URL payment method name.
445IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, ThreeTypesOfMethods) {
446 {
447 content::PaymentAppProvider::PaymentApps apps;
448 apps[0] = std::make_unique<content::StoredPaymentApp>();
449 apps[0]->scope = GURL("https://alicepay.com/webpay");
450 apps[0]->enabled_methods.push_back("basic-card");
451 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
452 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
453
454 Verify(std::move(apps));
455
456 EXPECT_EQ(1U, verified_apps().size());
457 ExpectApp(0, "https://alicepay.com/webpay",
458 {"basic-card", "https://alicepay.com/webpay2",
459 "https://ikepay.com/webpay"});
460 }
461
462 // Repeat verifications should have identical results.
463 {
464 content::PaymentAppProvider::PaymentApps apps;
465 apps[0] = std::make_unique<content::StoredPaymentApp>();
466 apps[0]->scope = GURL("https://alicepay.com/webpay");
467 apps[0]->enabled_methods.push_back("basic-card");
468 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
469 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
470
471 Verify(std::move(apps));
472
473 EXPECT_EQ(1U, verified_apps().size());
474 ExpectApp(0, "https://alicepay.com/webpay",
475 {"basic-card", "https://alicepay.com/webpay2",
476 "https://ikepay.com/webpay"});
477 }
478}
479
480// Verify that a payment handler from https://bobpay.com/webpay cannot use
481// payment method names that are unreachable websites, the origin of which does
482// not match that of the payment handler.
483IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, PaymentMethodName404) {
484 {
485 content::PaymentAppProvider::PaymentApps apps;
486 apps[0] = std::make_unique<content::StoredPaymentApp>();
487 apps[0]->scope = GURL("https://bobpay.com/webpay");
488 apps[0]->enabled_methods.push_back("https://404.com/webpay");
489 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
490
491 Verify(std::move(apps));
492
493 EXPECT_TRUE(verified_apps().empty());
494 }
495
496 // Repeat verifications should have identical results.
497 {
498 content::PaymentAppProvider::PaymentApps apps;
499 apps[0] = std::make_unique<content::StoredPaymentApp>();
500 apps[0]->scope = GURL("https://bobpay.com/webpay");
501 apps[0]->enabled_methods.push_back("https://404.com/webpay");
502 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
503
504 Verify(std::move(apps));
505
506 EXPECT_TRUE(verified_apps().empty());
507 }
508}
509
Rouslan Solomakhin478d93e32017-10-27 17:06:37510// All known payment method names are valid.
511IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
512 AllKnownPaymentMethodNames) {
513 {
514 content::PaymentAppProvider::PaymentApps apps;
515 apps[0] = std::make_unique<content::StoredPaymentApp>();
516 apps[0]->scope = GURL("https://bobpay.com/webpay");
517 apps[0]->enabled_methods.push_back("basic-card");
518 apps[0]->enabled_methods.push_back("interledger");
519 apps[0]->enabled_methods.push_back("payee-credit-transfer");
520 apps[0]->enabled_methods.push_back("payer-credit-transfer");
521 apps[0]->enabled_methods.push_back("not-supported");
522
523 Verify(std::move(apps));
524
525 EXPECT_EQ(1U, verified_apps().size());
526 ExpectApp(0, "https://bobpay.com/webpay",
527 {"basic-card", "interledger", "payee-credit-transfer",
528 "payer-credit-transfer"});
529 }
530
531 // Repeat verifications should have identical results.
532 {
533 content::PaymentAppProvider::PaymentApps apps;
534 apps[0] = std::make_unique<content::StoredPaymentApp>();
535 apps[0]->scope = GURL("https://bobpay.com/webpay");
536 apps[0]->enabled_methods.push_back("basic-card");
537 apps[0]->enabled_methods.push_back("interledger");
538 apps[0]->enabled_methods.push_back("payee-credit-transfer");
539 apps[0]->enabled_methods.push_back("payer-credit-transfer");
540 apps[0]->enabled_methods.push_back("not-supported");
541
542 Verify(std::move(apps));
543
544 EXPECT_EQ(1U, verified_apps().size());
545 ExpectApp(0, "https://bobpay.com/webpay",
546 {"basic-card", "interledger", "payee-credit-transfer",
547 "payer-credit-transfer"});
548 }
549}
550
Rouslan Solomakhinde012532017-09-20 15:18:34551} // namespace
552} // namespace payments