fetch-request-xhr-sync-on-worker.https.html (1636B)
1 <!DOCTYPE html> 2 <title>Service Worker: Synchronous XHR on Worker is intercepted</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="resources/test-helpers.sub.js"></script> 6 <script> 7 'use strict'; 8 9 promise_test((t) => { 10 const url = 'resources/fetch-request-xhr-sync-on-worker-worker.js'; 11 const scope = 'resources/fetch-request-xhr-sync-on-worker-scope/'; 12 const non_existent_file = 'non-existent-file.txt'; 13 14 // In Chromium, the service worker scope matching for workers is based on 15 // the URL of the parent HTML. So this test creates an iframe which is 16 // controlled by the service worker first, and creates a worker from the 17 // iframe. 18 return service_worker_unregister_and_register(t, url, scope) 19 .then((registration) => { 20 t.add_cleanup(() => registration.unregister()); 21 return wait_for_state(t, registration.installing, 'activated'); 22 }) 23 .then(() => { return with_iframe(scope + 'iframe_page'); }) 24 .then((frame) => { 25 t.add_cleanup(() => frame.remove()); 26 return frame.contentWindow.performSyncXHROnWorker(non_existent_file); 27 }) 28 .then((result) => { 29 assert_equals( 30 result.status, 31 200, 32 'HTTP response status code for intercepted request' 33 ); 34 assert_equals( 35 result.responseText, 36 'Response from service worker', 37 'HTTP response text for intercepted request' 38 ); 39 }); 40 }, 'Verify SyncXHR on Worker is intercepted'); 41 </script>