blob: 4a8a219150db02ab76d920fb7734721f66a7474e [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|
gogeralda74f9dec2018-04-10 00:33:4777 // and the |expected_methods| and the
78 // |expect_has_explicitly_verified_methods|.
Rouslan Solomakhinde012532017-09-20 15:18:3479 void ExpectApp(int64_t id,
80 const std::string& expected_scope,
gogeralda74f9dec2018-04-10 00:33:4781 const std::set<std::string>& expected_methods,
82 bool expect_has_explicitly_verified_methods) {
Rouslan Solomakhin478d93e32017-10-27 17:06:3783 const auto& it = verified_apps().find(id);
84 ASSERT_NE(verified_apps().end(), it);
85 EXPECT_EQ(GURL(expected_scope), it->second->scope);
86 std::set<std::string> actual_methods(it->second->enabled_methods.begin(),
87 it->second->enabled_methods.end());
Rouslan Solomakhinde012532017-09-20 15:18:3488 EXPECT_EQ(expected_methods, actual_methods);
gogeralda74f9dec2018-04-10 00:33:4789 EXPECT_EQ(expect_has_explicitly_verified_methods,
90 it->second->has_explicitly_verified_methods);
Rouslan Solomakhinde012532017-09-20 15:18:3491 }
92
93 private:
94 // Called by the verifier upon completed verification. These |apps| have only
95 // valid payment methods.
96 void OnPaymentAppsVerified(content::PaymentAppProvider::PaymentApps apps) {
97 verified_apps_ = std::move(apps);
98 }
99
Rouslan Solomakhinde012532017-09-20 15:18:34100 // Serves the payment method manifest files.
101 std::unique_ptr<net::EmbeddedTestServer> https_server_;
102
103 // The apps that have been verified by the Verify() method.
104 content::PaymentAppProvider::PaymentApps verified_apps_;
105
Rouslan Solomakhinde012532017-09-20 15:18:34106 DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest);
107};
108
109// Absence of payment handlers should result in absence of verified payment
110// handlers.
111IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoApps) {
112 {
113 Verify(content::PaymentAppProvider::PaymentApps());
114
115 EXPECT_TRUE(verified_apps().empty());
116 }
117
118 // Repeat verifications should have identical results.
119 {
120 Verify(content::PaymentAppProvider::PaymentApps());
121
122 EXPECT_TRUE(verified_apps().empty());
123 }
124}
125
126// A payment handler without any payment method names is not valid.
127IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoMethods) {
128 {
129 content::PaymentAppProvider::PaymentApps apps;
130 apps[0] = std::make_unique<content::StoredPaymentApp>();
131 apps[0]->scope = GURL("https://bobpay.com/webpay");
132
133 Verify(std::move(apps));
134
135 EXPECT_TRUE(verified_apps().empty());
136 }
137
138 // Repeat verifications should have identical results.
139 {
140 content::PaymentAppProvider::PaymentApps apps;
141 apps[0] = std::make_unique<content::StoredPaymentApp>();
142 apps[0]->scope = GURL("https://bobpay.com/webpay");
143
144 Verify(std::move(apps));
145
146 EXPECT_TRUE(verified_apps().empty());
147 }
148}
149
150// A payment handler with an unknown non-URL payment method name is not valid.
151IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
152 UnknownPaymentMethodNameIsRemoved) {
153 {
154 content::PaymentAppProvider::PaymentApps apps;
155 apps[0] = std::make_unique<content::StoredPaymentApp>();
156 apps[0]->scope = GURL("https://bobpay.com/webpay");
157 apps[0]->enabled_methods.push_back("unknown");
158
159 Verify(std::move(apps));
160
161 EXPECT_TRUE(verified_apps().empty());
162 }
163
164 // Repeat verifications should have identical results.
165 {
166 content::PaymentAppProvider::PaymentApps apps;
167 apps[0] = std::make_unique<content::StoredPaymentApp>();
168 apps[0]->scope = GURL("https://bobpay.com/webpay");
169 apps[0]->enabled_methods.push_back("unknown");
170
171 Verify(std::move(apps));
172
173 EXPECT_TRUE(verified_apps().empty());
174 }
175}
176
177// A payment handler with "basic-card" payment method name is valid.
178IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, KnownPaymentMethodName) {
179 {
180 content::PaymentAppProvider::PaymentApps apps;
181 apps[0] = std::make_unique<content::StoredPaymentApp>();
182 apps[0]->scope = GURL("https://bobpay.com/webpay");
183 apps[0]->enabled_methods.push_back("basic-card");
184
185 Verify(std::move(apps));
186
187 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47188 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhinde012532017-09-20 15:18:34189 }
190
191 // Repeat verifications should have identical results.
192 {
193 content::PaymentAppProvider::PaymentApps apps;
194 apps[0] = std::make_unique<content::StoredPaymentApp>();
195 apps[0]->scope = GURL("https://bobpay.com/webpay");
196 apps[0]->enabled_methods.push_back("basic-card");
197
198 Verify(std::move(apps));
199
200 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47201 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhinde012532017-09-20 15:18:34202 }
203}
204
205// A payment handler with both "basic-card" and "interledger" payment method
206// names is valid.
207IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
208 TwoKnownPaymentMethodNames) {
209 {
210 content::PaymentAppProvider::PaymentApps apps;
211 apps[0] = std::make_unique<content::StoredPaymentApp>();
212 apps[0]->scope = GURL("https://bobpay.com/webpay");
213 apps[0]->enabled_methods.push_back("basic-card");
214 apps[0]->enabled_methods.push_back("interledger");
215
216 Verify(std::move(apps));
217
218 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47219 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
220 false);
Rouslan Solomakhinde012532017-09-20 15:18:34221 }
222
223 // Repeat verifications should have identical results.
224 {
225 content::PaymentAppProvider::PaymentApps apps;
226 apps[0] = std::make_unique<content::StoredPaymentApp>();
227 apps[0]->scope = GURL("https://bobpay.com/webpay");
228 apps[0]->enabled_methods.push_back("basic-card");
229 apps[0]->enabled_methods.push_back("interledger");
230
231 Verify(std::move(apps));
232
233 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47234 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
235 false);
Rouslan Solomakhinde012532017-09-20 15:18:34236 }
237}
238
239// Two payment handlers with "basic-card" payment method names are both valid.
240IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
241 TwoAppsWithKnownPaymentMethodNames) {
242 {
243 content::PaymentAppProvider::PaymentApps apps;
244 apps[0] = std::make_unique<content::StoredPaymentApp>();
245 apps[0]->scope = GURL("https://bobpay.com/webpay");
246 apps[0]->enabled_methods.push_back("basic-card");
247 apps[1] = std::make_unique<content::StoredPaymentApp>();
248 apps[1]->scope = GURL("https://alicepay.com/webpay");
249 apps[1]->enabled_methods.push_back("basic-card");
250
251 Verify(std::move(apps));
252
253 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47254 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
255 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhinde012532017-09-20 15:18:34256 }
257
258 // Repeat verifications should have identical results.
259 {
260 content::PaymentAppProvider::PaymentApps apps;
261 apps[0] = std::make_unique<content::StoredPaymentApp>();
262 apps[0]->scope = GURL("https://bobpay.com/webpay");
263 apps[0]->enabled_methods.push_back("basic-card");
264 apps[1] = std::make_unique<content::StoredPaymentApp>();
265 apps[1]->scope = GURL("https://alicepay.com/webpay");
266 apps[1]->enabled_methods.push_back("basic-card");
267 Verify(std::move(apps));
268
269 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47270 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
271 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhinde012532017-09-20 15:18:34272 }
273}
274
275// Verify that a payment handler from https://bobpay.com/webpay can use the
276// payment method name https://frankpay.com/webpay, because
277// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
278IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
279 BobPayHandlerCanUseMethodThatSupportsAllOrigins) {
280 {
281 content::PaymentAppProvider::PaymentApps apps;
282 apps[0] = std::make_unique<content::StoredPaymentApp>();
283 apps[0]->scope = GURL("https://bobpay.com/webpay");
284 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
285
286 Verify(std::move(apps));
287
288 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47289 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
290 false);
Rouslan Solomakhinde012532017-09-20 15:18:34291 }
292
293 // Repeat verifications should have identical results.
294 {
295 content::PaymentAppProvider::PaymentApps apps;
296 apps[0] = std::make_unique<content::StoredPaymentApp>();
297 apps[0]->scope = GURL("https://bobpay.com/webpay");
298 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
299 Verify(std::move(apps));
300
301 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47302 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
303 false);
Rouslan Solomakhinde012532017-09-20 15:18:34304 }
305}
306
307// Verify that a payment handler from an unreachable website can use the payment
308// method name https://frankpay.com/webpay, because
309// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
310IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
311 Handler404CanUseMethodThatSupportsAllOrigins) {
312 {
313 content::PaymentAppProvider::PaymentApps apps;
314 apps[0] = std::make_unique<content::StoredPaymentApp>();
315 apps[0]->scope = GURL("https://404.com/webpay");
316 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
317
318 Verify(std::move(apps));
319
320 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47321 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
322 false);
Rouslan Solomakhinde012532017-09-20 15:18:34323 }
324
325 // Repeat verifications should have identical results.
326 {
327 content::PaymentAppProvider::PaymentApps apps;
328 apps[0] = std::make_unique<content::StoredPaymentApp>();
329 apps[0]->scope = GURL("https://404.com/webpay");
330 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
331 Verify(std::move(apps));
332
333 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47334 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
335 false);
Rouslan Solomakhinde012532017-09-20 15:18:34336 }
337}
338
339// Verify that a payment handler from anywhere on https://bobpay.com can use the
340// payment method name from anywhere else on https://bobpay.com, because of the
341// origin match.
342IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
343 BobPayCanUseAnyMethodOnOwnOrigin) {
344 {
345 content::PaymentAppProvider::PaymentApps apps;
346 apps[0] = std::make_unique<content::StoredPaymentApp>();
347 apps[0]->scope = GURL("https://bobpay.com/anything/here");
348 apps[0]->enabled_methods.push_back(
349 "https://bobpay.com/does/not/matter/whats/here");
350
351 Verify(std::move(apps));
352
353 EXPECT_EQ(1U, verified_apps().size());
354 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47355 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhinde012532017-09-20 15:18:34356 }
357
358 // Repeat verifications should have identical results.
359 {
360 content::PaymentAppProvider::PaymentApps apps;
361 apps[0] = std::make_unique<content::StoredPaymentApp>();
362 apps[0]->scope = GURL("https://bobpay.com/anything/here");
363 apps[0]->enabled_methods.push_back(
364 "https://bobpay.com/does/not/matter/whats/here");
365 Verify(std::move(apps));
366
367 EXPECT_EQ(1U, verified_apps().size());
368 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47369 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhinde012532017-09-20 15:18:34370 }
371}
372
373// Verify that a payment handler from anywhere on an unreachable website can use
374// the payment method name from anywhere else on the same unreachable website,
375// because they have identical origin.
376IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
377 Handler404CanUseAnyMethodOnOwnOrigin) {
378 {
379 content::PaymentAppProvider::PaymentApps apps;
380 apps[0] = std::make_unique<content::StoredPaymentApp>();
381 apps[0]->scope = GURL("https://404.com/anything/here");
382 apps[0]->enabled_methods.push_back(
383 "https://404.com/does/not/matter/whats/here");
384
385 Verify(std::move(apps));
386
387 EXPECT_EQ(1U, verified_apps().size());
388 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47389 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhinde012532017-09-20 15:18:34390 }
391
392 // Repeat verifications should have identical results.
393 {
394 content::PaymentAppProvider::PaymentApps apps;
395 apps[0] = std::make_unique<content::StoredPaymentApp>();
396 apps[0]->scope = GURL("https://404.com/anything/here");
397 apps[0]->enabled_methods.push_back(
398 "https://404.com/does/not/matter/whats/here");
399 Verify(std::move(apps));
400
401 EXPECT_EQ(1U, verified_apps().size());
402 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47403 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhinde012532017-09-20 15:18:34404 }
405}
406
407// Verify that only the payment handler from https://alicepay.com/webpay can use
408// payment methods https://georgepay.com/webpay and https://ikepay.com/webpay,
409// because both https://georgepay.com/payment-manifest.json and
410// https://ikepay.com/payment-manifest.json contain "supported_origins":
411// ["https://alicepay.com"]. The payment handler from https://bobpay.com/webpay
412// cannot use these payment methods, however.
413IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, OneSupportedOrigin) {
414 {
415 content::PaymentAppProvider::PaymentApps apps;
416 apps[0] = std::make_unique<content::StoredPaymentApp>();
417 apps[0]->scope = GURL("https://alicepay.com/webpay");
418 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
419 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
420 apps[1] = std::make_unique<content::StoredPaymentApp>();
421 apps[1]->scope = GURL("https://bobpay.com/webpay");
422 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
423 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
424
425 Verify(std::move(apps));
426
427 EXPECT_EQ(1U, verified_apps().size());
428 ExpectApp(0, "https://alicepay.com/webpay",
gogeralda74f9dec2018-04-10 00:33:47429 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
430 true);
Rouslan Solomakhinde012532017-09-20 15:18:34431 }
432
433 // Repeat verifications should have identical results.
434 {
435 content::PaymentAppProvider::PaymentApps apps;
436 apps[0] = std::make_unique<content::StoredPaymentApp>();
437 apps[0]->scope = GURL("https://alicepay.com/webpay");
438 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
439 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
440 apps[1] = std::make_unique<content::StoredPaymentApp>();
441 apps[1]->scope = GURL("https://bobpay.com/webpay");
442 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
443 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
444
445 Verify(std::move(apps));
446
447 EXPECT_EQ(1U, verified_apps().size());
448 ExpectApp(0, "https://alicepay.com/webpay",
gogeralda74f9dec2018-04-10 00:33:47449 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
450 true);
Rouslan Solomakhinde012532017-09-20 15:18:34451 }
452}
453
454// Verify that a payment handler from https://alicepay.com/webpay can use all
455// three of non-URL payment method name, same-origin URL payment method name,
456// and different-origin URL payment method name.
457IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, ThreeTypesOfMethods) {
458 {
459 content::PaymentAppProvider::PaymentApps apps;
460 apps[0] = std::make_unique<content::StoredPaymentApp>();
461 apps[0]->scope = GURL("https://alicepay.com/webpay");
462 apps[0]->enabled_methods.push_back("basic-card");
463 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
464 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
465
466 Verify(std::move(apps));
467
468 EXPECT_EQ(1U, verified_apps().size());
469 ExpectApp(0, "https://alicepay.com/webpay",
470 {"basic-card", "https://alicepay.com/webpay2",
gogeralda74f9dec2018-04-10 00:33:47471 "https://ikepay.com/webpay"},
472 true);
Rouslan Solomakhinde012532017-09-20 15:18:34473 }
474
475 // Repeat verifications should have identical results.
476 {
477 content::PaymentAppProvider::PaymentApps apps;
478 apps[0] = std::make_unique<content::StoredPaymentApp>();
479 apps[0]->scope = GURL("https://alicepay.com/webpay");
480 apps[0]->enabled_methods.push_back("basic-card");
481 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
482 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
483
484 Verify(std::move(apps));
485
486 EXPECT_EQ(1U, verified_apps().size());
487 ExpectApp(0, "https://alicepay.com/webpay",
488 {"basic-card", "https://alicepay.com/webpay2",
gogeralda74f9dec2018-04-10 00:33:47489 "https://ikepay.com/webpay"},
490 true);
Rouslan Solomakhinde012532017-09-20 15:18:34491 }
492}
493
494// Verify that a payment handler from https://bobpay.com/webpay cannot use
495// payment method names that are unreachable websites, the origin of which does
496// not match that of the payment handler.
497IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, PaymentMethodName404) {
498 {
499 content::PaymentAppProvider::PaymentApps apps;
500 apps[0] = std::make_unique<content::StoredPaymentApp>();
501 apps[0]->scope = GURL("https://bobpay.com/webpay");
502 apps[0]->enabled_methods.push_back("https://404.com/webpay");
503 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
504
505 Verify(std::move(apps));
506
507 EXPECT_TRUE(verified_apps().empty());
508 }
509
510 // Repeat verifications should have identical results.
511 {
512 content::PaymentAppProvider::PaymentApps apps;
513 apps[0] = std::make_unique<content::StoredPaymentApp>();
514 apps[0]->scope = GURL("https://bobpay.com/webpay");
515 apps[0]->enabled_methods.push_back("https://404.com/webpay");
516 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
517
518 Verify(std::move(apps));
519
520 EXPECT_TRUE(verified_apps().empty());
521 }
522}
523
Rouslan Solomakhin478d93e32017-10-27 17:06:37524// All known payment method names are valid.
525IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
526 AllKnownPaymentMethodNames) {
527 {
528 content::PaymentAppProvider::PaymentApps apps;
529 apps[0] = std::make_unique<content::StoredPaymentApp>();
530 apps[0]->scope = GURL("https://bobpay.com/webpay");
531 apps[0]->enabled_methods.push_back("basic-card");
532 apps[0]->enabled_methods.push_back("interledger");
533 apps[0]->enabled_methods.push_back("payee-credit-transfer");
534 apps[0]->enabled_methods.push_back("payer-credit-transfer");
535 apps[0]->enabled_methods.push_back("not-supported");
536
537 Verify(std::move(apps));
538
539 EXPECT_EQ(1U, verified_apps().size());
540 ExpectApp(0, "https://bobpay.com/webpay",
541 {"basic-card", "interledger", "payee-credit-transfer",
gogeralda74f9dec2018-04-10 00:33:47542 "payer-credit-transfer"},
543 false);
Rouslan Solomakhin478d93e32017-10-27 17:06:37544 }
545
546 // Repeat verifications should have identical results.
547 {
548 content::PaymentAppProvider::PaymentApps apps;
549 apps[0] = std::make_unique<content::StoredPaymentApp>();
550 apps[0]->scope = GURL("https://bobpay.com/webpay");
551 apps[0]->enabled_methods.push_back("basic-card");
552 apps[0]->enabled_methods.push_back("interledger");
553 apps[0]->enabled_methods.push_back("payee-credit-transfer");
554 apps[0]->enabled_methods.push_back("payer-credit-transfer");
555 apps[0]->enabled_methods.push_back("not-supported");
556
557 Verify(std::move(apps));
558
559 EXPECT_EQ(1U, verified_apps().size());
560 ExpectApp(0, "https://bobpay.com/webpay",
561 {"basic-card", "interledger", "payee-credit-transfer",
gogeralda74f9dec2018-04-10 00:33:47562 "payer-credit-transfer"},
563 false);
Rouslan Solomakhin478d93e32017-10-27 17:06:37564 }
565}
566
Rouslan Solomakhinde012532017-09-20 15:18:34567} // namespace
568} // namespace payments