data-transfer-files.https.html (1583B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Post a file in a navigation controlled by a service worker</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <body> 8 <iframe id=testframe name=testframe></iframe> 9 <form id=testform method=post action="/html/semantics/forms/form-submission-0/resources/file-submission.py" target=testframe enctype="multipart/form-data"> 10 <input name=testinput id=testinput type=file> 11 </form> 12 <script> 13 // Test that DataTransfer with a File entry works when posted to a 14 // service worker that falls back to network. Regression test for 15 // https://crbug.com/944145. 16 promise_test(async (t) => { 17 const scope = '/html/semantics/forms/form-submission-0/resources/'; 18 const header = `pipe=header(Service-Worker-Allowed,${scope})`; 19 const script = `resources/fetch-event-network-fallback-worker.js?${header}`; 20 21 const registration = await service_worker_unregister_and_register( 22 t, script, scope); 23 await wait_for_state(t, registration.installing, 'activated'); 24 25 const dataTransfer = new DataTransfer(); 26 dataTransfer.items.add(new File(['foobar'], 'name')); 27 assert_equals(1, dataTransfer.files.length); 28 29 testinput.files = dataTransfer.files; 30 testform.submit(); 31 32 const data = await new Promise(resolve => { 33 onmessage = e => { 34 if (e.source !== testframe) return; 35 resolve(e.data); 36 }; 37 }); 38 assert_equals(data, "foobar"); 39 }, 'Posting a File in a navigation handled by a service worker'); 40 </script> 41 </body>