| OLD | NEW |
| 1 // Adapter for testharness.js-style tests with Service Workers | 1 // Adapter for testharness.js-style tests with Service Workers |
| 2 | 2 |
| 3 function service_worker_test(url, description) { | 3 function service_worker_test(url, description) { |
| 4 var t = async_test(description); | 4 var t = async_test(description); |
| 5 t.step(function() { | 5 t.step(function() { |
| 6 var scope = 'nonexistent'; | 6 var scope = 'nonexistent'; |
| 7 service_worker_unregister_and_register(t, url, scope).then(t.step_func(o
nRegistered)); | 7 service_worker_unregister_and_register(t, url, scope).then(t.step_func(o
nRegistered)); |
| 8 | 8 |
| 9 function onRegistered(worker) { | 9 function onRegistered(worker) { |
| 10 var messageChannel = new MessageChannel(); | 10 var messageChannel = new MessageChannel(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 frame.onload = function() { | 56 frame.onload = function() { |
| 57 if (f) { | 57 if (f) { |
| 58 f(frame); | 58 f(frame); |
| 59 } | 59 } |
| 60 resolve(frame); | 60 resolve(frame); |
| 61 }; | 61 }; |
| 62 document.body.appendChild(frame); | 62 document.body.appendChild(frame); |
| 63 }); | 63 }); |
| 64 } | 64 } |
| 65 | 65 |
| 66 function unload_iframe(iframe) { |
| 67 var saw_unload = new Promise(function(resolve) { |
| 68 iframe.contentWindow.addEventListener('unload', function() { |
| 69 resolve(); |
| 70 }); |
| 71 }); |
| 72 iframe.src = ''; |
| 73 iframe.remove(); |
| 74 iframe = null; |
| 75 return saw_unload; |
| 76 } |
| 77 |
| 66 function normalizeURL(url) { | 78 function normalizeURL(url) { |
| 67 return new URL(url, document.location).toString().replace(/#.*$/, ''); | 79 return new URL(url, document.location).toString().replace(/#.*$/, ''); |
| 68 } | 80 } |
| 69 | 81 |
| 70 function wait_for_state(test, worker, state) { | 82 function wait_for_state(test, worker, state) { |
| 71 return new Promise(test.step_func(function(resolve, reject) { | 83 return new Promise(test.step_func(function(resolve, reject) { |
| 72 worker.addEventListener('statechange', test.step_func(function() { | 84 worker.addEventListener('statechange', test.step_func(function() { |
| 73 if (worker.state === state) | 85 if (worker.state === state) |
| 74 resolve(state); | 86 resolve(state); |
| 75 })); | 87 })); |
| 76 })); | 88 })); |
| 77 } | 89 } |
| OLD | NEW |