fetch-response-xhr.https.html (1770B)
1 <!DOCTYPE html> 2 <title>Service Worker: the response of FetchEvent using XMLHttpRequest</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 promise_test(function(t) { 9 var SCOPE = 'resources/fetch-response-xhr-iframe.https.html'; 10 var SCRIPT = 'resources/fetch-response-xhr-worker.js'; 11 var host_info = get_host_info(); 12 13 window.addEventListener('message', t.step_func(on_message), false); 14 function on_message(e) { 15 assert_equals(e.data.results, 'foo, bar'); 16 e.source.postMessage('ACK', host_info['HTTPS_ORIGIN']); 17 } 18 19 return service_worker_unregister_and_register(t, SCRIPT, SCOPE) 20 .then(function(registration) { 21 t.add_cleanup(function() { 22 return service_worker_unregister(t, SCOPE); 23 }); 24 25 return wait_for_state(t, registration.installing, 'activated'); 26 }) 27 .then(function() { return with_iframe(SCOPE); }) 28 .then(function(frame) { 29 var channel; 30 31 t.add_cleanup(function() { 32 frame.remove(); 33 }); 34 35 channel = new MessageChannel(); 36 var onPortMsg = new Promise(function(resolve) { 37 channel.port1.onmessage = resolve; 38 }); 39 40 frame.contentWindow.postMessage('START', 41 host_info['HTTPS_ORIGIN'], 42 [channel.port2]); 43 44 return onPortMsg; 45 }) 46 .then(function(e) { 47 assert_equals(e.data.results, 'finish'); 48 }); 49 }, 'Verify the response of FetchEvent using XMLHttpRequest'); 50 </script>