Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(542)

Unified Diff: content/test/data/payments/payment_app.js

Issue 2646313002: PaymentApp: Implement invokePaymentApp() in renderer side. (Closed)
Patch Set: address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/BUILD.gn ('k') | content/test/data/payments/payment_app_invocation.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/data/payments/payment_app.js
diff --git a/content/test/data/payments/payment_app.js b/content/test/data/payments/payment_app.js
new file mode 100644
index 0000000000000000000000000000000000000000..a3b40e7055ae1e9dba9a6c6f55e5184b76d2918b
--- /dev/null
+++ b/content/test/data/payments/payment_app.js
@@ -0,0 +1,42 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function sendResultToTest(data) {
+ clients.matchAll({includeUncontrolled: true}).then(clients => {
+ clients.forEach(client => {
+ if (client.url.indexOf('payment_app_invocation.html') != -1) {
+ client.postMessage(data);
+ }
+ });
+ });
+}
+
+function getMessageFromPaymentAppWindow() {
+ return new Promise((resolve, reject) => {
+ var listener = self.addEventListener('message', e => {
+ resolve(e.data);
+ self.removeEventListener(listener);
+ });
+ });
+}
+
+self.addEventListener('paymentrequest', e => {
+ var payment_app_window;
+
+ // SW ------------------ openWindow() -----------------> payment_app_window
+ // SW <---- postMessage('payment_app_window_ready') ---- payment_app_window
+ // SW ------- postMessage('payment_app_request') ------> payment_app_window
+ // SW <------ postMessage('payment_app_response') ------ payment_app_window
+ e.waitUntil(clients.openWindow('payment_app_window.html')
+ .then(window_client => {
+ payment_app_window = window_client;
+ return getMessageFromPaymentAppWindow();
+ })
+ .then(message => {
+ sendResultToTest(message);
+ payment_app_window.postMessage('payment_app_request');
+ return getMessageFromPaymentAppWindow();
+ })
+ .then(message => { sendResultToTest(message); }));
+});
« no previous file with comments | « content/test/BUILD.gn ('k') | content/test/data/payments/payment_app_invocation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698