Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 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 |
| 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 Solomakhin | 438d8c9 | 2017-10-26 21:33:18 | [diff] [blame] | 10 | #include "base/run_loop.h" |
| 11 | #include "chrome/browser/profiles/profile.h" |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 12 | #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 Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 16 | #include "components/payments/content/payment_manifest_web_data_service.h" |
Jay Civelli | a7d22b4 | 2017-10-24 18:38:07 | [diff] [blame] | 17 | #include "components/payments/content/utility/payment_manifest_parser.h" |
Rouslan Solomakhin | 438d8c9 | 2017-10-26 21:33:18 | [diff] [blame] | 18 | #include "components/payments/core/test_payment_manifest_downloader.h" |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 19 | #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 Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 24 | |
| 25 | namespace payments { |
| 26 | namespace { |
| 27 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 28 | // Tests for the manifest verifier. |
| 29 | class 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 Solomakhin | dbf593d9 | 2017-11-21 19:20:57 | [diff] [blame] | 47 | content::WebContents* web_contents = |
| 48 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 49 | content::BrowserContext* context = web_contents->GetBrowserContext(); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 50 | auto downloader = std::make_unique<TestDownloader>( |
Rouslan Solomakhin | 438d8c9 | 2017-10-26 21:33:18 | [diff] [blame] | 51 | content::BrowserContext::GetDefaultStoragePartition(context) |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 52 | ->GetURLRequestContext()); |
Rouslan Solomakhin | 438d8c9 | 2017-10-26 21:33:18 | [diff] [blame] | 53 | downloader->AddTestServerURL("https://", https_server_->GetURL("/")); |
gogerald | 84ae626 | 2018-02-06 06:21:46 | [diff] [blame] | 54 | auto parser = std::make_unique<payments::PaymentManifestParser>(); |
| 55 | auto cache = WebDataServiceFactory::GetPaymentManifestWebDataForProfile( |
| 56 | Profile::FromBrowserContext(context), |
| 57 | ServiceAccessType::EXPLICIT_ACCESS); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 58 | |
gogerald | 84ae626 | 2018-02-06 06:21:46 | [diff] [blame] | 59 | ManifestVerifier verifier(web_contents, downloader.get(), parser.get(), |
| 60 | cache.get()); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 61 | |
| 62 | base::RunLoop run_loop; |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 63 | verifier.Verify( |
| 64 | std::move(apps), |
| 65 | base::BindOnce(&ManifestVerifierBrowserTest::OnPaymentAppsVerified, |
| 66 | base::Unretained(this)), |
Rouslan Solomakhin | 438d8c9 | 2017-10-26 21:33:18 | [diff] [blame] | 67 | run_loop.QuitClosure()); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 68 | 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| |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 77 | // and the |expected_methods| and the |
| 78 | // |expect_has_explicitly_verified_methods|. |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 79 | void ExpectApp(int64_t id, |
| 80 | const std::string& expected_scope, |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 81 | const std::set<std::string>& expected_methods, |
| 82 | bool expect_has_explicitly_verified_methods) { |
Rouslan Solomakhin | 478d93e3 | 2017-10-27 17:06:37 | [diff] [blame] | 83 | 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 Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 88 | EXPECT_EQ(expected_methods, actual_methods); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 89 | EXPECT_EQ(expect_has_explicitly_verified_methods, |
| 90 | it->second->has_explicitly_verified_methods); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 91 | } |
| 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 Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 100 | // 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 Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest); |
| 107 | }; |
| 108 | |
| 109 | // Absence of payment handlers should result in absence of verified payment |
| 110 | // handlers. |
| 111 | IN_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. |
| 127 | IN_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. |
| 151 | IN_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. |
| 178 | IN_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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 188 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 189 | } |
| 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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 201 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | // A payment handler with both "basic-card" and "interledger" payment method |
| 206 | // names is valid. |
| 207 | IN_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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 219 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"}, |
| 220 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 221 | } |
| 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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 234 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"}, |
| 235 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | // Two payment handlers with "basic-card" payment method names are both valid. |
| 240 | IN_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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 254 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false); |
| 255 | ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 256 | } |
| 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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 270 | ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false); |
| 271 | ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 272 | } |
| 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": "*". |
| 278 | IN_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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 289 | ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"}, |
| 290 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 291 | } |
| 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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 302 | ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"}, |
| 303 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 304 | } |
| 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": "*". |
| 310 | IN_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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 321 | ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"}, |
| 322 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 323 | } |
| 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()); |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 334 | ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"}, |
| 335 | false); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 336 | } |
| 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. |
| 342 | IN_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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 355 | {"https://bobpay.com/does/not/matter/whats/here"}, true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 356 | } |
| 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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 369 | {"https://bobpay.com/does/not/matter/whats/here"}, true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 370 | } |
| 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. |
| 376 | IN_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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 389 | {"https://404.com/does/not/matter/whats/here"}, true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 390 | } |
| 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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 403 | {"https://404.com/does/not/matter/whats/here"}, true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 404 | } |
| 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. |
| 413 | IN_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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 429 | {"https://georgepay.com/webpay", "https://ikepay.com/webpay"}, |
| 430 | true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 431 | } |
| 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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 449 | {"https://georgepay.com/webpay", "https://ikepay.com/webpay"}, |
| 450 | true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 451 | } |
| 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. |
| 457 | IN_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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 471 | "https://ikepay.com/webpay"}, |
| 472 | true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 473 | } |
| 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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 489 | "https://ikepay.com/webpay"}, |
| 490 | true); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 491 | } |
| 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. |
| 497 | IN_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 Solomakhin | 478d93e3 | 2017-10-27 17:06:37 | [diff] [blame] | 524 | // All known payment method names are valid. |
| 525 | IN_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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 542 | "payer-credit-transfer"}, |
| 543 | false); |
Rouslan Solomakhin | 478d93e3 | 2017-10-27 17:06:37 | [diff] [blame] | 544 | } |
| 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", |
gogerald | a74f9dec | 2018-04-10 00:33:47 | [diff] [blame^] | 562 | "payer-credit-transfer"}, |
| 563 | false); |
Rouslan Solomakhin | 478d93e3 | 2017-10-27 17:06:37 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 567 | } // namespace |
| 568 | } // namespace payments |