OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: FetchEvent from image</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.js?pipe=sub"></script> |
| 6 <script> |
| 7 async_test(function(t) { |
| 8 var SCOPE = 'resources/fetch-request-image-iframe.html'; |
| 9 var SCRIPT = 'resources/fetch-request-image-worker.js'; |
| 10 var host_info = get_host_info(); |
| 11 var TEST_URL = |
| 12 host_info['HTTP_ORIGIN'] + base_path() + 'resources/dummy?test'; |
| 13 var worker; |
| 14 service_worker_unregister_and_register(t, SCRIPT, SCOPE) |
| 15 .then(function(registration) { |
| 16 return wait_for_update(t, registration); |
| 17 }) |
| 18 .then(function(sw) { |
| 19 worker = sw; |
| 20 return wait_for_state(t, sw, 'activated'); |
| 21 }) |
| 22 .then(function() { return with_iframe(SCOPE); }) |
| 23 .then(function(frame) { |
| 24 return new Promise(function(resolve) { |
| 25 var channel1 = new MessageChannel(); |
| 26 channel1.port1.onmessage = t.step_func(function(e) { |
| 27 assert_equals(e.data.results, 'finish'); |
| 28 unload_iframe(frame); |
| 29 var channel2 = new MessageChannel(); |
| 30 channel2.port1.onmessage = resolve; |
| 31 worker.postMessage( |
| 32 {port: channel2.port2}, [channel2.port2]); |
| 33 }); |
| 34 frame.contentWindow.postMessage({}, |
| 35 [channel1.port2], |
| 36 host_info['HTTP_ORIGIN']); |
| 37 }); |
| 38 }) |
| 39 .then(function(e) { |
| 40 var results = e.data; |
| 41 assert_equals(results[TEST_URL + '1'].mode, 'no-cors', |
| 42 'mode of normal image request must be no-cors.'); |
| 43 assert_equals(results[TEST_URL + '2'].mode, 'cors', |
| 44 'mode of anonymous crossOrigin image request must be ' + |
| 45 'cors.'); |
| 46 assert_equals(results[TEST_URL + '3'].mode, 'cors', |
| 47 'mode of use-credentials crossOrigin image request ' + |
| 48 'must be cors.'); |
| 49 service_worker_unregister_and_done(t, SCOPE); |
| 50 }) |
| 51 .catch(unreached_rejection(t)); |
| 52 }, 'Verify FetchEvent from image'); |
| 53 </script> |
OLD | NEW |