From 188e782c41828ccf35383f6b61a3438d57175bdc Mon Sep 17 00:00:00 2001 From: Rouslan Solomakhin Date: Wed, 25 Jan 2023 15:45:22 +0000 Subject: [PATCH] Remove unused instrument.set() calls from test support files Bug: 1327265 Change-Id: I2e3d209cae6eca326ff8da0e8d2dc6cef0966d4f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4184395 Reviewed-by: Nick Burris Commit-Queue: Rouslan Solomakhin Cr-Commit-Position: refs/heads/main@{#1096783} --- .../payments/alicepay.test/app1/index.html | 17 ----- .../data/payments/alicepay.test/app1/index.js | 74 ------------------- .../payments/alicepay.test/app2/index.html | 17 ----- .../data/payments/alicepay.test/app2/index.js | 74 ------------------- .../app_store_billing_tests/index.html | 1 - .../payments/app_store_billing_tests/index.js | 27 ------- .../data/payments/bobpay.test/app1/index.html | 4 - .../data/payments/bobpay.test/app1/index.js | 74 ------------------- .../enforce_full_delegation.test/index.html | 3 - .../enforce_full_delegation.test/index.js | 62 ---------------- .../data/payments/kylepay.test/index.html | 1 - .../test/data/payments/kylepay.test/index.js | 29 -------- .../data/payments/maxpay.test/installer.js | 59 --------------- .../data/payments/maxpay.test/merchant.html | 11 --- 14 files changed, 453 deletions(-) delete mode 100644 components/test/data/payments/alicepay.test/app1/index.html delete mode 100644 components/test/data/payments/alicepay.test/app1/index.js delete mode 100644 components/test/data/payments/alicepay.test/app2/index.html delete mode 100644 components/test/data/payments/alicepay.test/app2/index.js delete mode 100644 components/test/data/payments/bobpay.test/app1/index.js diff --git a/components/test/data/payments/alicepay.test/app1/index.html b/components/test/data/payments/alicepay.test/app1/index.html deleted file mode 100644 index d81ba41722f098..00000000000000 --- a/components/test/data/payments/alicepay.test/app1/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Alice Pay 1 - - - - - - diff --git a/components/test/data/payments/alicepay.test/app1/index.js b/components/test/data/payments/alicepay.test/app1/index.js deleted file mode 100644 index 893c00adf7a151..00000000000000 --- a/components/test/data/payments/alicepay.test/app1/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2017 The Chromium Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * Prints output. - * @param {String} src - Where the message is coming from. - * @param {String} txt - The text to print. - */ -function output(src, txt) { - // Handle DOMException: - if (txt.message) { - txt = txt.message; - } - txt = src + ': ' + txt; - if (!domAutomationController) { - txt += ' window.domAutomationController not found.'; - } else { - domAutomationController.send(txt); - } - console.warn(txt); -} - -/** - * Installs a payment app. - * @param {String} method - The payment method name that this app supports. - */ -function install(method) { - if (!navigator.serviceWorker) { - output('install()', 'ServiceWorker API not found.'); - return; - } - - navigator.serviceWorker.getRegistration('app.js') - .then((registration) => { - if (registration) { - output( - 'serviceWorker.getRegistration()', - 'The ServiceWorker is already installed.'); - return; - } - navigator.serviceWorker.register('app.js') - .then(() => { - return navigator.serviceWorker.ready; - }) - .then((registration) => { - if (!registration.paymentManager) { - output( - 'serviceWorker.register()', - 'PaymentManager API not found.'); - return; - } - - registration.paymentManager.instruments - .set('123456', {name: 'Alice Pay', method: method}) - .then(() => { - output( - 'instruments.set()', - 'Payment app for "' + method + '" method installed.'); - }) - .catch((error) => { - output('instruments.set()', error); - }); - }) - .catch((error) => { - output('serviceWorker.register()', error); - }); - }) - .catch((error) => { - output('serviceWorker.getRegistration()', error); - }); -} diff --git a/components/test/data/payments/alicepay.test/app2/index.html b/components/test/data/payments/alicepay.test/app2/index.html deleted file mode 100644 index bb0b9f029004fb..00000000000000 --- a/components/test/data/payments/alicepay.test/app2/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Alice Pay 2 - - - - - - diff --git a/components/test/data/payments/alicepay.test/app2/index.js b/components/test/data/payments/alicepay.test/app2/index.js deleted file mode 100644 index 893c00adf7a151..00000000000000 --- a/components/test/data/payments/alicepay.test/app2/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2017 The Chromium Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * Prints output. - * @param {String} src - Where the message is coming from. - * @param {String} txt - The text to print. - */ -function output(src, txt) { - // Handle DOMException: - if (txt.message) { - txt = txt.message; - } - txt = src + ': ' + txt; - if (!domAutomationController) { - txt += ' window.domAutomationController not found.'; - } else { - domAutomationController.send(txt); - } - console.warn(txt); -} - -/** - * Installs a payment app. - * @param {String} method - The payment method name that this app supports. - */ -function install(method) { - if (!navigator.serviceWorker) { - output('install()', 'ServiceWorker API not found.'); - return; - } - - navigator.serviceWorker.getRegistration('app.js') - .then((registration) => { - if (registration) { - output( - 'serviceWorker.getRegistration()', - 'The ServiceWorker is already installed.'); - return; - } - navigator.serviceWorker.register('app.js') - .then(() => { - return navigator.serviceWorker.ready; - }) - .then((registration) => { - if (!registration.paymentManager) { - output( - 'serviceWorker.register()', - 'PaymentManager API not found.'); - return; - } - - registration.paymentManager.instruments - .set('123456', {name: 'Alice Pay', method: method}) - .then(() => { - output( - 'instruments.set()', - 'Payment app for "' + method + '" method installed.'); - }) - .catch((error) => { - output('instruments.set()', error); - }); - }) - .catch((error) => { - output('serviceWorker.register()', error); - }); - }) - .catch((error) => { - output('serviceWorker.getRegistration()', error); - }); -} diff --git a/components/test/data/payments/app_store_billing_tests/index.html b/components/test/data/payments/app_store_billing_tests/index.html index cb1be676f96ccc..df66c5e5c5bf06 100644 --- a/components/test/data/payments/app_store_billing_tests/index.html +++ b/components/test/data/payments/app_store_billing_tests/index.html @@ -5,7 +5,6 @@ - diff --git a/components/test/data/payments/app_store_billing_tests/index.js b/components/test/data/payments/app_store_billing_tests/index.js index 81c4d5552f6359..90ea1ff9397de2 100644 --- a/components/test/data/payments/app_store_billing_tests/index.js +++ b/components/test/data/payments/app_store_billing_tests/index.js @@ -8,33 +8,6 @@ const methodName = window.location.origin + '/method_manifest.json'; let request; let supportedInstruments = []; -/** - * Install a payment app. - * @return {string} - a message indicating whether the installation is - * successful. - */ -async function install() { - info('installing'); - - await navigator.serviceWorker.register('empty_app.js'); - const registration = await navigator.serviceWorker.ready; - if (!registration.paymentManager) { - return 'No payment handler capability in this browser. Is' + - 'chrome://flags/#service-worker-payment-apps enabled?'; - } - - if (!registration.paymentManager.instruments) { - return 'Payment handler is not fully implemented. ' + - 'Cannot set the instruments.'; - } - await registration.paymentManager.instruments.set('instrument-key', { - // Chrome uses name and icon from the web app manifest - name: 'MaxPay', - method: methodName, - }); - return 'success'; -} - /** * Add a payment method to the payment request. * @param {string} method - the payment method. diff --git a/components/test/data/payments/bobpay.test/app1/index.html b/components/test/data/payments/bobpay.test/app1/index.html index c85a870775a178..9edf87d71232ad 100644 --- a/components/test/data/payments/bobpay.test/app1/index.html +++ b/components/test/data/payments/bobpay.test/app1/index.html @@ -9,9 +9,5 @@ Bob Pay 1 - - - - diff --git a/components/test/data/payments/bobpay.test/app1/index.js b/components/test/data/payments/bobpay.test/app1/index.js deleted file mode 100644 index 854aa12653d253..00000000000000 --- a/components/test/data/payments/bobpay.test/app1/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2018 The Chromium Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * Prints output. - * @param {String} src - Where the message is coming from. - * @param {String} txt - The text to print. - */ -function output(src, txt) { - // Handle DOMException: - if (txt.message) { - txt = txt.message; - } - txt = src + ': ' + txt; - if (!domAutomationController) { - txt += ' window.domAutomationController not found.'; - } else { - domAutomationController.send(txt); - } - console.warn(txt); -} - -/** - * Installs a payment app. - * @param {String} method - The payment method name that this app supports. - */ -function install(method) { - if (!navigator.serviceWorker) { - output('install()', 'ServiceWorker API not found.'); - return; - } - - navigator.serviceWorker.getRegistration('app.js') - .then((registration) => { - if (registration) { - output( - 'serviceWorker.getRegistration()', - 'The ServiceWorker is already installed.'); - return; - } - navigator.serviceWorker.register('app.js') - .then(() => { - return navigator.serviceWorker.ready; - }) - .then((registration) => { - if (!registration.paymentManager) { - output( - 'serviceWorker.register()', - 'PaymentManager API not found.'); - return; - } - - registration.paymentManager.instruments - .set('123456', {name: 'Bob Pay', method: method}) - .then(() => { - output( - 'instruments.set()', - 'Payment app for "' + method + '" method installed.'); - }) - .catch((error) => { - output('instruments.set()', error); - }); - }) - .catch((error) => { - output('serviceWorker.register()', error); - }); - }) - .catch((error) => { - output('serviceWorker.getRegistration()', error); - }); -} diff --git a/components/test/data/payments/enforce_full_delegation.test/index.html b/components/test/data/payments/enforce_full_delegation.test/index.html index 4b7d4b6554aab1..f2f75c3f3a4324 100644 --- a/components/test/data/payments/enforce_full_delegation.test/index.html +++ b/components/test/data/payments/enforce_full_delegation.test/index.html @@ -8,7 +8,6 @@ - Enforce Full Delegation Tests -
-
diff --git a/components/test/data/payments/enforce_full_delegation.test/index.js b/components/test/data/payments/enforce_full_delegation.test/index.js index d357b6cc59b72b..18c2980aeef57c 100644 --- a/components/test/data/payments/enforce_full_delegation.test/index.js +++ b/components/test/data/payments/enforce_full_delegation.test/index.js @@ -11,68 +11,6 @@ const SW_SRC_URL = 'app.js'; let request; let supportedInstruments = []; -/** - * Installs the given payment handler with the given payment method. - * @param {string} method - The payment method that this service worker - * supports. - * @return {Promise} - 'success' or error message on failure. - */ -async function install(method = METHOD_NAME) { - info('installing'); - try { - const registration = await navigator.serviceWorker.register(SW_SRC_URL); - await activation(registration); - await registration.paymentManager.instruments.set( - 'instrument-for-' + method, {name: 'Instrument Name', method}); - return 'success'; - } catch (e) { - return e.message; - } -} - -/** - * Returns a promise that resolves when the service worker of the given - * registration has activated. - * @param {ServiceWorkerRegistration} registration - A service worker - * registration. - * @return {Promise} - A promise that resolves when the service worker - * has activated. - */ -async function activation(registration) { - return new Promise((resolve) => { - if (registration.active) { - resolve(); - return; - } - registration.addEventListener('updatefound', () => { - const newWorker = registration.installing; - if (newWorker.state == 'activated') { - resolve(); - return; - } - newWorker.addEventListener('statechange', () => { - if (newWorker.state == 'activated') { - resolve(); - } - }); - }); - }); -} - -/** - * Uninstall the payment handler. - * @return {string} - the message about the uninstallation result. - */ -async function uninstall() { - info('uninstall'); - let registration = await navigator.serviceWorker.getRegistration(SW_SRC_URL); - if (!registration) { - return 'The Payment handler has not been installed yet.'; - } - await registration.unregister(); - return 'success'; -} - /** * Delegates handling of the provided options to the payment handler. * @param {Array} delegations The list of payment options to delegate. diff --git a/components/test/data/payments/kylepay.test/index.html b/components/test/data/payments/kylepay.test/index.html index 265b68c8e6dac2..518365e67f914c 100644 --- a/components/test/data/payments/kylepay.test/index.html +++ b/components/test/data/payments/kylepay.test/index.html @@ -9,7 +9,6 @@ Kyle Pay - diff --git a/components/test/data/payments/kylepay.test/index.js b/components/test/data/payments/kylepay.test/index.js index b852ec6413cb85..775025410f2c27 100644 --- a/components/test/data/payments/kylepay.test/index.js +++ b/components/test/data/payments/kylepay.test/index.js @@ -4,35 +4,6 @@ * found in the LICENSE file. */ -/** - * Installs KylePay payment app. - * @param {String} method - The payment method name that this app supports. - * @return {string} The 'success' or error message. - */ -async function install(method) { - try { - let registration = await navigator.serviceWorker.getRegistration('app.js'); - if (registration) { - return 'The payment handler is already installed.'; - } - await navigator.serviceWorker.register('app.js'); - await navigator.serviceWorker.ready; - if (!registration.paymentManager) { - return 'PaymentManager API not found.'; - } - if (!registration.paymentManager.instruments) { - return 'PaymentInstruments API not found.'; - } - await registration.paymentManager.instruments.set('instrument-id', { - name: 'Kyle Pay', - method, - }); - return enableDelegations(); - } catch (e) { - return e.toString(); - } -} - /** * Enables the delegations for this payment method. * @return {Promise} - Either "success" or an error message. diff --git a/components/test/data/payments/maxpay.test/installer.js b/components/test/data/payments/maxpay.test/installer.js index 683859eddc9470..3191751a07e49d 100644 --- a/components/test/data/payments/maxpay.test/installer.js +++ b/components/test/data/payments/maxpay.test/installer.js @@ -8,19 +8,6 @@ const methodName = window.location.origin + '/pay'; const swSrcUrl = './payment_handler_sw.js'; let resultPromise; -/** - * Update the installation status in the widget called 'installationStatus'. - */ -async function updateStatusView() { - const installationStatusViewId = 'installationStatus'; - const registration = await navigator.serviceWorker.getRegistration(swSrcUrl); - if (registration) { - document.getElementById(installationStatusViewId).innerText = 'installed'; - } else { - document.getElementById(installationStatusViewId).innerText = 'uninstalled'; - } -} - /** * Insert a message to the widget called 'log'. * @param {string} text - the text that is intended to be inserted into the log. @@ -30,50 +17,6 @@ function updateLogView(text) { messageElement.innerText = text + '\n' + messageElement.innerText; } -/** - * Installs the payment handler. - * @return {string} - the message about the installation result. - */ -async function install() { - try { - let registration = - await navigator.serviceWorker.getRegistration(swSrcUrl); - if (registration) { - return 'The payment handler is already installed.'; - } - - await navigator.serviceWorker.register(swSrcUrl); - registration = await navigator.serviceWorker.ready; - await updateStatusView(); - - if (!registration.paymentManager) { - return 'PaymentManager API not found.'; - } - - await registration.paymentManager.instruments.set('instrument-id', { - name: 'Instrument Name', - method: methodName, - }); - return 'success'; - } catch (e) { - return e.message; - } -} - -/** - * Uninstall the payment handler. - * @return {string} - the message about the uninstallation result. - */ -async function uninstall() { - let registration = await navigator.serviceWorker.getRegistration(swSrcUrl); - if (!registration) { - return 'The Payment handler has not been installed yet.'; - } - await registration.unregister(); - await updateStatusView(); - return 'Uninstall successfully.'; -} - /** * Launches the payment handler and waits until its window is ready. * @param {string} url - The URL to open in the payment handler window. @@ -120,5 +63,3 @@ async function getResult() { return e.message; } } - -updateStatusView(); diff --git a/components/test/data/payments/maxpay.test/merchant.html b/components/test/data/payments/maxpay.test/merchant.html index a8dd4d4324ac25..d4463ac79e7bc5 100644 --- a/components/test/data/payments/maxpay.test/merchant.html +++ b/components/test/data/payments/maxpay.test/merchant.html @@ -30,14 +30,6 @@

Use Max Pay

- -
-
Installation Status:
Messages: