[basic-card] Migrate payment-handler WPTs

With basic card now disabled and soon to be removed, migrate the
payment-handler web platform tests to use URL based payment methods
instead of basic-card.

The test cases that are exclusively related to basic-card are removed.
Many tests are updated to use a simple payment app with just a
paymentrequest event listener, app-simple.js, which is migrated from
basic-card.js, with the basic-card related values removed.

The untrusted-event tests are updated to use an example URL method as
they don't require a valid payment method.

Bug: 1209835
Change-Id: I79b95ff7df30eda7cbf253fa895566e6e2214aa0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3569944
Reviewed-by: Stephen McGruer <smcgruer@chromium.org>
Commit-Queue: Nick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/main@{#989446}
diff --git a/payment-handler/app-can-make-payment.js b/payment-handler/app-can-make-payment.js
index 0bb9490..14fea9c 100644
--- a/payment-handler/app-can-make-payment.js
+++ b/payment-handler/app-can-make-payment.js
@@ -53,13 +53,6 @@
   }
 
   const [methodName] = method.supportedMethods;
-  if (methodName === 'basic-card') {
-    const msg =
-      '"basic-card" payment method must never be checked in CanMakePaymentEvent';
-    event.respondWith(Promise.reject(new Error(msg)));
-    return;
-  }
-
   const [modifierMethodName] = modifier.supportedMethods;
   if (modifierMethodName !== methodName) {
     const msg = `Unexpected modifier method name: "${modifierMethodName}". Expected "${methodName}".`;
diff --git a/payment-handler/basic-card.js b/payment-handler/app-simple.js
similarity index 77%
rename from payment-handler/basic-card.js
rename to payment-handler/app-simple.js
index 2db5d4b..833a01f 100644
--- a/payment-handler/basic-card.js
+++ b/payment-handler/app-simple.js
@@ -17,7 +17,7 @@
   }
 
   const methodData = event.methodData[0];
-  const expectedMethodName = 'basic-card';
+  const expectedMethodName = window.location.origin + '/payment-handler/payment-app/';
   if (methodData.supportedMethods !== expectedMethodName) {
     const msg = `Expected payment method name "${expectedMethodName}", but got "${
       methodData.supportedMethods
@@ -69,25 +69,6 @@
   }
 
   event.respondWith({
-    methodName: 'basic-card',
-    details: {
-      billingAddress: {
-        addressLine: ['1875 Explorer St #1000'],
-        city: 'Reston',
-        country: 'US',
-        dependentLocality: '',
-        organization: 'Google',
-        phone: '+15555555555',
-        postalCode: '20190',
-        recipient: 'Jon Doe',
-        region: 'VA',
-        sortingCode: '',
-      },
-      cardNumber: '4111111111111111',
-      cardSecurityCode: '123',
-      cardholderName: 'Jon Doe',
-      expiryMonth: '12',
-      expiryYear: '2028',
-    },
+    methodName: expectedMethodName,
   });
 });
diff --git a/payment-handler/basic-card.json b/payment-handler/basic-card.json
deleted file mode 100644
index 002dd87..0000000
--- a/payment-handler/basic-card.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
-  "name": "Test Basic Card Payment Handler",
-  "icons": [
-    {
-      "src": "/images/rgrg-256x256.png",
-      "sizes": "256x256",
-      "type": "image/png"
-    }
-  ]
-}
diff --git a/payment-handler/can-make-payment-event.https.html b/payment-handler/can-make-payment-event.https.html
index c4e5453..b2016a0 100644
--- a/payment-handler/can-make-payment-event.https.html
+++ b/payment-handler/can-make-payment-event.https.html
@@ -5,8 +5,6 @@
 <link rel="manifest" href="manifest.json">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
-<p>The "basic-card" test requires that you don't have a prepaid MIR card stored
-in the browser. If you do, please remove it for the duration of the test.</p>
 <script>
 const instrumentKey = 'instrument-key';
 
@@ -239,141 +237,4 @@
   );
   await promise_rejects_dom(t, 'NotSupportedError', request.show());
 }, 'If CanMakePaymentEvent.respondWith(Promise.reject(error)) is called, then the payment method is not supported.');
-
-promise_test(async t => {
-  const methodName = 'basic-card';
-  await registerApp(methodName);
-  const request = buildPaymentRequest(methodName);
-  assert_not_equals(request, undefined);
-  let paymentRequestCanMakePaymentResult;
-  try {
-    paymentRequestCanMakePaymentResult = await request.canMakePayment();
-  } catch (err) {
-    assert_equals(
-      err.name,
-      'NotAllowedError',
-      'If it throws, then it must be NotAllowedError',
-    );
-  }
-  assert_true(
-    paymentRequestCanMakePaymentResult,
-    'canMakePayment() must return true due to capability matching in the browser.',
-  );
-}, 'If an app supports "basic-card" in general and that\'s what merchant requests as well, then capability filtering should make the app available for use. CanMakePaymentEvent should not be fired for "basic-card".');
-
-promise_test(async t => {
-  const methodName = 'basic-card';
-  await registerApp(methodName);
-  const cardNetwork = 'mir';
-  const request = new PaymentRequest(
-    [
-      {
-        supportedMethods: methodName,
-        data: {
-          supportedNetworks: [cardNetwork],
-        },
-      },
-    ],
-    {
-      total: {
-        label: 'Total',
-        amount: {
-          currency: 'USD',
-          value: '0',
-        },
-      },
-    },
-  );
-  assert_not_equals(request, undefined);
-  let paymentRequestCanMakePaymentResult;
-  try {
-    paymentRequestCanMakePaymentResult = await request.canMakePayment();
-  } catch (err) {
-    assert_equals(
-      err.name,
-      'NotAllowedError',
-      'If it throws, then it must be NotAllowedError',
-    );
-  }
-  assert_false(
-    paymentRequestCanMakePaymentResult,
-    'canMakePayment() must return false due to capability matching in the browser.',
-  );
-}, 'If an app has less specific "basic-card" capabilites than merchant\'s request, capability filtering should not make the app available for use. CanMakePaymentEvent should not be fired for "basic-card". ');
-
-promise_test(async t => {
-  const methodName = 'basic-card';
-  const cardNetwork = 'mir';
-  const registration = await registerApp(methodName);
-  await registration.paymentManager.instruments.set(instrumentKey, {
-    name: 'Test Payment Method',
-    method: methodName,
-    capabilities: {
-      supportedNetworks: [cardNetwork],
-    },
-  });
-  const request = new PaymentRequest(
-    [
-      {
-        supportedMethods: methodName,
-        data: {
-          supportedNetworks: [cardNetwork],
-        },
-      },
-    ],
-    {
-      total: {
-        label: 'Total',
-        amount: {
-          currency: 'USD',
-          value: '0',
-        },
-      },
-    },
-  );
-  assert_not_equals(request, undefined);
-  let paymentRequestCanMakePaymentResult;
-  try {
-    paymentRequestCanMakePaymentResult = await request.canMakePayment();
-  } catch (err) {
-    assert_equals(
-      err.name,
-      'NotAllowedError',
-      'If it throws, then it must be NotAllowedError',
-    );
-  }
-  assert_true(
-    paymentRequestCanMakePaymentResult,
-    'canMakePayment() must return true due to capability matching in the browser.',
-  );
-}, 'If an app has the exact "basic-card" capabilities that a merchant requested, capability filtering should make the app available for use. CanMakePaymentEvent should not be fired for "basic-card".');
-
-promise_test(async t => {
-  const methodName = 'basic-card';
-  const cardNetwork = 'mir';
-  const registration = await registerApp(methodName);
-  await registration.paymentManager.instruments.set(instrumentKey, {
-    name: 'Test Payment Method',
-    method: methodName,
-    capabilities: {
-      supportedNetworks: [cardNetwork],
-    },
-  });
-  const request = buildPaymentRequest(methodName);
-  assert_not_equals(request, undefined);
-  let paymentRequestCanMakePaymentResult;
-  try {
-    paymentRequestCanMakePaymentResult = await request.canMakePayment();
-  } catch (err) {
-    assert_equals(
-      err.name,
-      'NotAllowedError',
-      'If it throws, then it must be NotAllowedError',
-    );
-  }
-  assert_true(
-    paymentRequestCanMakePaymentResult,
-    'canMakePayment() must return true due to capability matching in the browser.',
-  );
-}, 'If an app has more specific "basic-card" capabilities than merchant\'s request, capability filtering should make the app available for use. CanMakePaymentEvent should not be fired for "basic-card".');
 </script>
diff --git a/payment-handler/change-payment-method-manual.https.html b/payment-handler/change-payment-method-manual.https.html
index abdb3d7..1640420 100644
--- a/payment-handler/change-payment-method-manual.https.html
+++ b/payment-handler/change-payment-method-manual.https.html
@@ -5,7 +5,7 @@
   rel="help"
   href="https://w3c.github.io/payment-handler/#changepaymentmethod-method"
 />
-<link rel="manifest" href="/payment-handler/basic-card.json" />
+<link rel="manifest" href="/payment-handler/manifest.json" />
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/resources/testdriver.js"></script>
diff --git a/payment-handler/change-shipping-option-manual.https.html b/payment-handler/change-shipping-option-manual.https.html
index 00d1aee..2511fc5 100644
--- a/payment-handler/change-shipping-option-manual.https.html
+++ b/payment-handler/change-shipping-option-manual.https.html
@@ -2,7 +2,7 @@
 <meta charset="utf-8" />
 <title>Tests for PaymentRequestEvent.changeShippingOption()</title>
 
-<link rel="manifest" href="/payment-handler/basic-card.json" />
+<link rel="manifest" href="/payment-handler/manifest.json" />
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/resources/testdriver.js"></script>
diff --git a/payment-handler/payment-instruments.https.html b/payment-handler/payment-instruments.https.html
index 605d331..121c131 100644
--- a/payment-handler/payment-instruments.https.html
+++ b/payment-handler/payment-instruments.https.html
@@ -2,12 +2,14 @@
 <meta charset="utf-8">
 <title>Tests for PaymentInstruments interface</title>
 <link rel="help" href="https://w3c.github.io/payment-handler/#paymentinstruments-interface">
-<link rel="manifest" href="basic-card.json">
+<link rel="manifest" href="manifest.json">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="register-and-activate-service-worker.js"></script>
 <script>
 function runTests(registration) {
+  const methodName = window.location.origin + '/payment-handler/payment-app/';
+
   promise_test(async t => {
     await registration.paymentManager.instruments.clear();
     await registration.paymentManager.instruments.set('instrument-key-1', {
@@ -76,8 +78,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
-        capabilities: {supportedNetworks: ['mir']},
+        method: methodName,
       },
     );
     const result = await registration.paymentManager.instruments.get(
@@ -103,8 +104,7 @@
         icons: [
           {src: '/images/green-16x16.png', sizes: '16x16', type: 'image/png'},
         ],
-        method: 'basic-card',
-        capabilities: {supportedNetworks: ['mir']},
+        method: methodName,
       },
     );
     let result = await registration.paymentManager.instruments.get(
@@ -118,7 +118,7 @@
     );
     assert_equals(result.icons[0].sizes, '16x16');
     assert_equals(result.icons[0].type, 'image/png');
-    assert_equals(result.method, 'basic-card');
+    assert_equals(result.method, methodName);
     assert_array_equals(result.capabilities.supportedNetworks, ['mir']);
     await registration.paymentManager.instruments.set(
       'existing-instrument-key',
@@ -131,8 +131,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
-        capabilities: {supportedNetworks: ['visa']},
+        method: methodName,
       },
     );
     result = await registration.paymentManager.instruments.get(
@@ -146,8 +145,7 @@
     );
     assert_equals(result.icons[0].sizes, '256x256');
     assert_equals(result.icons[0].type, 'image/png');
-    assert_equals(result.method, 'basic-card');
-    assert_array_equals(result.capabilities.supportedNetworks, ['visa']);
+    assert_equals(result.method, methodName);
   }, 'Resetting an existing instrument updates the instrument');
 
   promise_test(async t => {
@@ -163,8 +161,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
-        capabilities: {supportedNetworks: ['mir']},
+        method: methodName,
       },
     );
     await registration.paymentManager.instruments.clear();
@@ -187,7 +184,7 @@
             type: 'image/jif',
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -206,7 +203,7 @@
             type: 'image/pn' + 'g'.repeat(100000),
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -223,7 +220,7 @@
           type: 'image/png',
         },
       ],
-      method: 'basic-card',
+      method: methodName,
     });
   }, "Don't crash when registering an instrument with a very long icon size 888...x888...");
 
@@ -237,7 +234,7 @@
           type: 'image/png',
         },
       ],
-      method: 'basic-card',
+      method: methodName,
     });
   }, "Don't crash when 'sizes' missing from icon definition");
 
@@ -251,7 +248,7 @@
           sizes: '256x256',
         },
       ],
-      method: 'basic-card',
+      method: methodName,
     });
   }, "Don't crash when 'type' missing from icon definition");
 
@@ -268,7 +265,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -287,7 +284,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -306,7 +303,7 @@
             type: 'image/png',
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -326,7 +323,7 @@
             type: 'image/gif',
           },
         ],
-        method: 'basic-card',
+        method: methodName,
       },
     );
     return promise_rejects_js(t, TypeError, setPromise);
@@ -378,5 +375,5 @@
   }, "Don't crash on null characters in key, name, method, and capability strings.");
 }
 
-registerAndActiveServiceWorker('basic-card.js', 'payment-app/', runTests);
+registerAndActiveServiceWorker('app-simple.js', 'payment-app/', runTests);
 </script>
diff --git a/payment-handler/payment-request-event-manual.https.html b/payment-handler/payment-request-event-manual.https.html
index 3c8deb3..e595dd2 100644
--- a/payment-handler/payment-request-event-manual.https.html
+++ b/payment-handler/payment-request-event-manual.https.html
@@ -9,13 +9,14 @@
 <p>When the payment sheet is shown, please authorize the mock payment.</p>
 <script>
 async function setInstrumentsAndRunTests(registration) {
+  const methodName = window.location.origin + '/payment-handler/payment-app/';
   await registration.paymentManager.instruments.clear();
   await registration.paymentManager.instruments.set('instrument-key', {
     name: 'Instrument Name',
     icons: [
       {src: '/images/rgrg-256x256.png', sizes: '256x256', type: 'image/png'},
     ],
-    method: 'basic-card',
+    method: methodName,
     capabilities: {supportedNetworks: ['mir']},
   });
   runTests();
@@ -25,7 +26,7 @@
   promise_test(async t => {
     const response = await new PaymentRequest(
       [
-        {supportedMethods: 'basic-card', data: {}},
+        {supportedMethods: methodName, data: {}},
         {supportedMethods: 'interledger', data: {supportedNetworks: ['mir']}},
       ],
       {
@@ -37,7 +38,7 @@
         ],
         modifiers: [
           {
-            supportedMethods: 'basic-card',
+            supportedMethods: methodName,
             data: {supportedNetworks: ['mir']},
             total: {
               label: 'MIR total',
@@ -48,7 +49,7 @@
             ],
           },
           {
-            supportedMethods: 'basic-card',
+            supportedMethods: methodName,
             data: {supportedNetworks: ['visa']},
             total: {
               label: 'VISA total',
@@ -74,30 +75,13 @@
     ).show();
     const promise = response.complete('success');
     assert_equals(response.requestId, 'test-payment-request-identifier');
-    assert_equals(response.methodName, 'basic-card');
-    assert_array_equals(response.details.billingAddress.addressLine, [
-      '1875 Explorer St #1000',
-    ]);
-    assert_equals(response.details.billingAddress.city, 'Reston');
-    assert_equals(response.details.billingAddress.country, 'US');
-    assert_equals(response.details.billingAddress.dependentLocality, '');
-    assert_equals(response.details.billingAddress.organization, 'Google');
-    assert_equals(response.details.billingAddress.phone, '+15555555555');
-    assert_equals(response.details.billingAddress.postalCode, '20190');
-    assert_equals(response.details.billingAddress.recipient, 'Jon Doe');
-    assert_equals(response.details.billingAddress.region, 'VA');
-    assert_equals(response.details.billingAddress.sortingCode, '');
-    assert_equals(response.details.cardNumber, '4111111111111111');
-    assert_equals(response.details.cardSecurityCode, '123');
-    assert_equals(response.details.cardholderName, 'Jon Doe');
-    assert_equals(response.details.expiryMonth, '12');
-    assert_equals(response.details.expiryYear, '2028');
+    assert_equals(response.methodName, methodName);
     return promise;
   }, 'Can perform payment');
 }
 
 registerAndActiveServiceWorker(
-  'basic-card.js',
+  'app-simple.js',
   'payment-app/',
   setInstrumentsAndRunTests,
 );
diff --git a/payment-handler/same-object-attributes.https.html b/payment-handler/same-object-attributes.https.html
index b9a9dd8..2e5dea3 100644
--- a/payment-handler/same-object-attributes.https.html
+++ b/payment-handler/same-object-attributes.https.html
@@ -9,7 +9,7 @@
 
 promise_test(async t => {
   const registration = await service_worker_unregister_and_register(
-      t, 'basic-card.js', 'payment-app/');
+      t, 'app-simple.js', 'payment-app/');
   await wait_for_state(t, registration.installing, 'activated');
 
   assert_equals(registration.paymentManager, registration.paymentManager);
diff --git a/payment-handler/supports-shipping-contact-delegation-manual.https.html b/payment-handler/supports-shipping-contact-delegation-manual.https.html
index 75b3668..939e542 100644
--- a/payment-handler/supports-shipping-contact-delegation-manual.https.html
+++ b/payment-handler/supports-shipping-contact-delegation-manual.https.html
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <meta charset="utf-8" />
 <title>Tests for Delegation of shipping and contact collection to PH</title>
-<link rel="manifest" href="/payment-handler/basic-card.json" />
+<link rel="manifest" href="/payment-handler/manifest.json" />
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/resources/testdriver.js"></script>
diff --git a/payment-handler/untrusted-event.js b/payment-handler/untrusted-event.js
index 2407029..e067952 100644
--- a/payment-handler/untrusted-event.js
+++ b/payment-handler/untrusted-event.js
@@ -6,23 +6,23 @@
   if (e.data == 'paymentrequest') {
     self.dispatchEvent(new PaymentRequestEvent('paymentrequest', {
       methodData: [{
-        supportedMethods: 'basic-card'
+        supportedMethods: 'https://example.com/pay'
       }],
       total: {
         currency: 'USD',
         value: '100'
       },
       modifiers: [{
-        supportedMethods: 'basic-card'
+        supportedMethods: 'https://example.com/pay'
       }]
     }));
   } else if (e.data == 'canmakepayment') {
     self.dispatchEvent(new CanMakePaymentEvent('canmakepayment', {
       methodData: [{
-        supportedMethods: 'basic-card'
+        supportedMethods: 'https://example.com/pay'
       }],
       modifiers: [{
-        supportedMethods: 'basic-card'
+        supportedMethods: 'https://example.com/pay'
       }]
     }));
   }