|
11 | 11 | <script src="/resources/testdriver.js"></script>
|
12 | 12 | <body>
|
13 | 13 | <script>
|
14 |
| - 'use strict'; |
| 14 | + "use strict"; |
15 | 15 | const applePayMethod = {
|
16 |
| - supportedMethods: 'https://apple.com/apple-pay', |
| 16 | + supportedMethods: "https://apple.com/apple-pay", |
17 | 17 | data: {
|
18 | 18 | version: 3,
|
19 |
| - merchantIdentifier: 'merchant.com.example', |
20 |
| - countryCode: 'US', |
21 |
| - merchantCapabilities: ['supports3DS'], |
22 |
| - supportedNetworks: ['visa'], |
| 19 | + merchantIdentifier: "merchant.com.example", |
| 20 | + countryCode: "US", |
| 21 | + merchantCapabilities: ["supports3DS"], |
| 22 | + supportedNetworks: ["visa"], |
23 | 23 | },
|
24 | 24 | };
|
25 |
| - const methods = [{supportedMethods: 'basic-card'}, applePayMethod]; |
| 25 | + const methods = [{supportedMethods: "basic-card"}, applePayMethod]; |
26 | 26 | const details = {
|
27 | 27 | total: {
|
28 |
| - label: 'Total', |
| 28 | + label: "Total", |
29 | 29 | amount: {
|
30 |
| - currency: 'USD', |
31 |
| - value: '1.00', |
| 30 | + currency: "USD", |
| 31 | + value: "1.00", |
32 | 32 | },
|
33 | 33 | },
|
34 | 34 | };
|
|
39 | 39 | * @param {String} src Optional resource URL to load.
|
40 | 40 | * @returns {Promise} Resolves when the src loads.
|
41 | 41 | */
|
42 |
| - async function attachIframe(src = 'blank.html') { |
43 |
| - const iframe = document.createElement('iframe'); |
| 42 | + async function attachIframe(src = "blank.html") { |
| 43 | + const iframe = document.createElement("iframe"); |
44 | 44 | iframe.allowPaymentRequest = true;
|
45 | 45 | iframe.src = src;
|
46 | 46 | document.body.appendChild(iframe);
|
47 | 47 | await new Promise(resolve => {
|
48 |
| - iframe.addEventListener('load', resolve, {once: true}); |
| 48 | + iframe.addEventListener("load", resolve, {once: true}); |
49 | 49 | });
|
50 | 50 | return iframe;
|
51 | 51 | }
|
|
56 | 56 | * @param {String} src Optional resource URL to load.
|
57 | 57 | * @returns {Promise} Resolves when the src loads.
|
58 | 58 | */
|
59 |
| - async function loadPopupInsideUserGesture(src = 'blank.html') { |
60 |
| - const popupWindow = window.open(src, '', 'width=400,height=400'); |
| 59 | + async function loadPopupInsideUserGesture(src = "blank.html") { |
| 60 | + const popupWindow = window.open(src, "", "width=400,height=400"); |
61 | 61 | await new Promise(resolve => {
|
62 |
| - popupWindow.addEventListener('load', resolve, {once: true}); |
| 62 | + popupWindow.addEventListener("load", resolve, {once: true}); |
63 | 63 | });
|
64 | 64 | popupWindow.focus();
|
65 | 65 | return popupWindow;
|
|
73 | 73 | // showing boolean" to true and then try to show a second payment sheet in
|
74 | 74 | // the same window. The second show() should reject.
|
75 | 75 | const [showPromise1, showPromise2] = await test_driver.bless(
|
76 |
| - 'testing one payment sheet per window', |
| 76 | + "testing one payment sheet per window", |
77 | 77 | () => {
|
78 | 78 | return [request1.show(), request2.show()];
|
79 | 79 | },
|
80 | 80 | );
|
81 | 81 | await promise_rejects(
|
82 | 82 | t,
|
83 |
| - 'AbortError', |
| 83 | + "AbortError", |
84 | 84 | showPromise2,
|
85 |
| - 'Attempting to show a second payment request must reject.', |
| 85 | + "Attempting to show a second payment request must reject.", |
86 | 86 | );
|
87 | 87 |
|
88 | 88 | await request1.abort();
|
89 | 89 | await promise_rejects(
|
90 | 90 | t,
|
91 |
| - 'AbortError', |
| 91 | + "AbortError", |
92 | 92 | showPromise1,
|
93 |
| - 'request1 was aborted via .abort()', |
| 93 | + "request1 was aborted via .abort()", |
94 | 94 | );
|
95 | 95 |
|
96 | 96 | // Finally, request2 should have been "closed", so trying to show
|
|
99 | 99 | const rejectedPromise = request2.show();
|
100 | 100 | await promise_rejects(
|
101 | 101 | t,
|
102 |
| - 'InvalidStateError', |
| 102 | + "InvalidStateError", |
103 | 103 | rejectedPromise,
|
104 |
| - 'Attempting to show a second payment request must reject.', |
| 104 | + "Attempting to show a second payment request must reject.", |
105 | 105 | );
|
106 | 106 | // Finally, we confirm that request2's returned promises are unique.
|
107 | 107 | assert_not_equals(
|
108 | 108 | showPromise2,
|
109 | 109 | rejectedPromise,
|
110 |
| - 'Returned Promises be unique', |
| 110 | + "Returned Promises be unique", |
111 | 111 | );
|
112 |
| - }, 'The top browsing context can only show one payment sheet at a time.'); |
| 112 | + }, "The top browsing context can only show one payment sheet at a time."); |
113 | 113 |
|
114 | 114 | promise_test(async t => {
|
115 | 115 | const iframe = await attachIframe();
|
|
121 | 121 |
|
122 | 122 | // Let's get some blessed showPromises
|
123 | 123 | const [showPromise] = await test_driver.bless(
|
124 |
| - 'testing top window show() blocked by payment sheet in iframe', |
| 124 | + "testing top window show() blocked by payment sheet in iframe", |
125 | 125 | () => {
|
126 | 126 | // iframe sets "is showing boolean", ignore the returned promise.
|
127 | 127 | iframeRequest.show();
|
|
132 | 132 |
|
133 | 133 | await promise_rejects(
|
134 | 134 | t,
|
135 |
| - 'AbortError', |
| 135 | + "AbortError", |
136 | 136 | showPromise,
|
137 |
| - 'iframe is already showing a payment request.', |
| 137 | + "iframe is already showing a payment request.", |
138 | 138 | );
|
139 | 139 |
|
140 | 140 | // Cleanup
|
|
154 | 154 | // windowRequest.show() sets "is showing boolean" to true. Then we try to
|
155 | 155 | // show a payment request in the iframe, which should reject.
|
156 | 156 | const [iframeShowPromise] = await test_driver.bless(
|
157 |
| - 'testing iframe show() blocked by payment sheet in top window', |
| 157 | + "testing iframe show() blocked by payment sheet in top window", |
158 | 158 | () => {
|
159 | 159 | windowRequest.show();
|
160 | 160 | return [iframeRequest.show()];
|
|
163 | 163 |
|
164 | 164 | await promise_rejects(
|
165 | 165 | t,
|
166 |
| - 'AbortError', |
| 166 | + "AbortError", |
167 | 167 | iframeShowPromise,
|
168 |
| - 'The top window is already showing a payment request.', |
| 168 | + "The top window is already showing a payment request.", |
169 | 169 | );
|
170 | 170 |
|
171 | 171 | // Cleanup
|
172 | 172 | await windowRequest.abort();
|
173 | 173 | iframe.remove();
|
174 |
| - }, 'An iframe cannot show a payment request if the top-level window is already showing one.'); |
| 174 | + }, "An iframe cannot show a payment request if the top-level window is already showing one."); |
175 | 175 |
|
176 | 176 | promise_test(async t => {
|
177 | 177 | // Create a PaymentReuqest in top-level window.
|
|
186 | 186 | popupShowPromise,
|
187 | 187 | windowShowPromise,
|
188 | 188 | ] = await test_driver.bless(
|
189 |
| - 'testing top-level show() blocked by payment sheet in popup', |
| 189 | + "testing top-level show() blocked by payment sheet in popup", |
190 | 190 | async () => {
|
191 | 191 | const popupWindow = await loadPopupInsideUserGesture();
|
192 | 192 | const popupRequest = new popupWindow.PaymentRequest(methods, details);
|
|
205 | 205 |
|
206 | 206 | await promise_rejects(
|
207 | 207 | t,
|
208 |
| - 'AbortError', |
| 208 | + "AbortError", |
209 | 209 | windowShowPromise,
|
210 | 210 | "Expected window's showPromise to reject, request is already showing",
|
211 | 211 | );
|
212 |
| - }, 'Using a popup window prevents the top-browsing context from showing a payment request'); |
| 212 | + }, "Using a popup window prevents the top-browsing context from showing a payment request"); |
213 | 213 |
|
214 | 214 | promise_test(async t => {
|
215 | 215 | const iframe = await attachIframe();
|
|
222 | 222 | // Open a popup window
|
223 | 223 | const [popupWindow, popupRequest] =
|
224 | 224 | await test_driver.bless(
|
225 |
| - 'open popup to test multiple context and window calls show() first', |
| 225 | + "open popup to test multiple context and window calls show() first", |
226 | 226 | async () => {
|
227 | 227 | const popupWindow = await loadPopupInsideUserGesture();
|
228 | 228 | const popupRequest = new popupWindow.PaymentRequest(methods, details);
|
|
238 | 238 | popupShowPromise,
|
239 | 239 | iframeShowPromise,
|
240 | 240 | ] = await test_driver.bless(
|
241 |
| - 'test multiple nested browsing context', |
| 241 | + "test multiple nested browsing context", |
242 | 242 | () => {
|
243 | 243 | return [
|
244 | 244 | windowRequest.show(),
|
|
250 | 250 | // popupRequest and iframeRequest will both reject
|
251 | 251 | await promise_rejects(
|
252 | 252 | t,
|
253 |
| - 'AbortError', |
| 253 | + "AbortError", |
254 | 254 | popupShowPromise,
|
255 |
| - 'Expected popupShowPromise to reject, request is already showing.', |
| 255 | + "Expected popupShowPromise to reject, request is already showing.", |
256 | 256 | );
|
257 | 257 |
|
258 | 258 | await promise_rejects(
|
259 | 259 | t,
|
260 |
| - 'AbortError', |
| 260 | + "AbortError", |
261 | 261 | iframeShowPromise,
|
262 |
| - 'Expected iframeShowPromise to reject, request is already showing.', |
| 262 | + "Expected iframeShowPromise to reject, request is already showing.", |
263 | 263 | );
|
264 | 264 |
|
265 | 265 | await windowRequest.abort();
|
|
283 | 283 | windowShowPromise,
|
284 | 284 | iframeShowPromise
|
285 | 285 | ] = await test_driver.bless(
|
286 |
| - 'test multiple browsing context and iframe calls show() first', |
| 286 | + "test multiple browsing context and iframe calls show() first", |
287 | 287 | async () => {
|
288 | 288 | const popupWindow = await loadPopupInsideUserGesture();
|
289 | 289 | const popupRequest = new popupWindow.PaymentRequest(methods, details);
|
|
300 | 300 | // windowShowPromise and iframeRequest will both reject
|
301 | 301 | await promise_rejects(
|
302 | 302 | t,
|
303 |
| - 'AbortError', |
| 303 | + "AbortError", |
304 | 304 | windowShowPromise,
|
305 |
| - 'Expected windowShowPromise to reject, the popup is showing a payment request.', |
| 305 | + "Expected windowShowPromise to reject, the popup is showing a payment request.", |
306 | 306 | );
|
307 | 307 |
|
308 | 308 | await promise_rejects(
|
309 | 309 | t,
|
310 |
| - 'AbortError', |
| 310 | + "AbortError", |
311 | 311 | iframeShowPromise,
|
312 |
| - 'Expected iframeShowPromise to reject, the popup is showing a payment request.', |
| 312 | + "Expected iframeShowPromise to reject, the popup is showing a payment request.", |
313 | 313 | );
|
314 | 314 |
|
315 | 315 | await popupRequest.abort();
|
|
326 | 326 | const iframeRequest = new iframeWindow.PaymentRequest(methods, details);
|
327 | 327 |
|
328 | 328 | const [popupWindow, popupRequest] = await test_driver.bless(
|
329 |
| - 'open popup to test multiple context and iframe calls show() first', |
| 329 | + "open popup to test multiple context and iframe calls show() first", |
330 | 330 | async () => {
|
331 | 331 | const w = await loadPopupInsideUserGesture();
|
332 | 332 | const r = new w.PaymentRequest(methods, details);
|
|
342 | 342 | popupShowPromise,
|
343 | 343 | windowShowPromise,
|
344 | 344 | ] = await test_driver.bless(
|
345 |
| - 'test multiple browsing context and iframe calls show() first', |
| 345 | + "test multiple browsing context and iframe calls show() first", |
346 | 346 | async () => {
|
347 | 347 | return [
|
348 | 348 | iframeRequest.show(),
|
|
355 | 355 | // windowShowPromise and iframeRequest will both reject
|
356 | 356 | await promise_rejects(
|
357 | 357 | t,
|
358 |
| - 'AbortError', |
| 358 | + "AbortError", |
359 | 359 | windowShowPromise,
|
360 |
| - 'Expected windowShowPromise to reject, the popup is showing a payment request.', |
| 360 | + "Expected windowShowPromise to reject, the popup is showing a payment request.", |
361 | 361 | );
|
362 | 362 |
|
363 | 363 | await promise_rejects(
|
364 | 364 | t,
|
365 |
| - 'AbortError', |
| 365 | + "AbortError", |
366 | 366 | popupShowPromise,
|
367 |
| - 'Expected popupShowPromise to reject, the popup is showing a payment request.', |
| 367 | + "Expected popupShowPromise to reject, the popup is showing a payment request.", |
368 | 368 | );
|
369 | 369 |
|
370 | 370 | await iframeRequest.abort();
|
|
377 | 377 | const iframeWindow = iframe.contentWindow;
|
378 | 378 | const iframeRequest = new iframeWindow.PaymentRequest(methods, details);
|
379 | 379 | const iframeShowPromise = test_driver.bless(
|
380 |
| - 'test navigating iframe after show()', |
| 380 | + "test navigating iframe after show()", |
381 | 381 | () => iframeRequest.show(),
|
382 | 382 | );
|
383 | 383 |
|
384 | 384 | // We navigate away, causing the payment sheet to close
|
385 | 385 | // and the request is showing boolean to become false.
|
386 |
| - iframe.src = 'blank.html?abc=123'; |
| 386 | + iframe.src = "blank.html?abc=123"; |
387 | 387 | await new Promise(resolve => (iframe.onload = resolve));
|
388 | 388 | await promise_rejects(
|
389 | 389 | t,
|
390 |
| - 'AbortError', |
| 390 | + "AbortError", |
391 | 391 | iframeShowPromise,
|
392 |
| - 'Navigating iframe away must cause the iframeShowPromise to reject.', |
| 392 | + "Navigating iframe away must cause the iframeShowPromise to reject.", |
393 | 393 | );
|
394 | 394 | iframe.remove();
|
395 | 395 |
|
|
402 | 402 | promise_test(async t => {
|
403 | 403 | const [popupWindow, popupRequest, popupShowPromise] =
|
404 | 404 | await test_driver.bless(
|
405 |
| - 'trigger payment in a popup window', |
| 405 | + "trigger payment in a popup window", |
406 | 406 | async () => {
|
407 | 407 | const popupWindow = await loadPopupInsideUserGesture();
|
408 | 408 | const popupRequest = new popupWindow.PaymentRequest(methods, details);
|
|
411 | 411 |
|
412 | 412 | // We navigate away, causing the payment sheet to close
|
413 | 413 | // and the request is showing boolean to become false.
|
414 |
| - popupWindow.location = 'blank.html?abc=123'; |
| 414 | + popupWindow.location = "blank.html?abc=123"; |
415 | 415 | await new Promise(resolve => (popupWindow.onload = resolve));
|
416 | 416 |
|
417 | 417 | // Don't wait for |popupShowPromise| to reject because it may never do
|
418 | 418 | // (see https://github.com/w3c/payment-request/issues/872). Instead, try
|
419 | 419 | // to spin up a new payment request and make sure it succeeds.
|
420 | 420 | const request = new window.PaymentRequest(methods, details);
|
421 | 421 | const [showPromise] = await test_driver.bless(
|
422 |
| - 'trigger payment in main window', |
| 422 | + "trigger payment in main window", |
423 | 423 | () => {
|
424 | 424 | return [request.show()];
|
425 | 425 | });
|
|
0 commit comments