| 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_unregister_and_register(test, url, scope) { | 3 function service_worker_unregister_and_register(test, url, scope) { |
| 4 if (!scope || scope.length == 0) | 4 if (!scope || scope.length == 0) |
| 5 return Promise.reject(new Error('tests must define a scope')); | 5 return Promise.reject(new Error('tests must define a scope')); |
| 6 | 6 |
| 7 var options = { scope: scope }; | 7 var options = { scope: scope }; |
| 8 return service_worker_unregister(test, scope) | 8 return service_worker_unregister(test, scope) |
| 9 .then(function() { | 9 .then(function() { |
| 10 return navigator.serviceWorker.register(url, options); | 10 return navigator.serviceWorker.register(url, options); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 assert_unreached(error_prefix + ': ' + reason); | 45 assert_unreached(error_prefix + ': ' + reason); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Adds an iframe to the document and returns a promise that resolves to the | 49 // Adds an iframe to the document and returns a promise that resolves to the |
| 50 // iframe when it finishes loading. The caller is responsible for removing the | 50 // iframe when it finishes loading. The caller is responsible for removing the |
| 51 // iframe later if needed. | 51 // iframe later if needed. |
| 52 function with_iframe(url) { | 52 function with_iframe(url) { |
| 53 return new Promise(function(resolve) { | 53 return new Promise(function(resolve) { |
| 54 var frame = document.createElement('iframe'); | 54 var frame = document.createElement('iframe'); |
| 55 frame.className = 'test-iframe'; |
| 55 frame.src = url; | 56 frame.src = url; |
| 56 frame.onload = function() { resolve(frame); }; | 57 frame.onload = function() { resolve(frame); }; |
| 57 document.body.appendChild(frame); | 58 document.body.appendChild(frame); |
| 58 }); | 59 }); |
| 59 } | 60 } |
| 60 | 61 |
| 61 function normalizeURL(url) { | 62 function normalizeURL(url) { |
| 62 return new URL(url, self.location).toString().replace(/#.*$/, ''); | 63 return new URL(url, self.location).toString().replace(/#.*$/, ''); |
| 63 } | 64 } |
| 64 | 65 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 }); | 219 }); |
| 219 } | 220 } |
| 220 | 221 |
| 221 function websocket(test, frame) { | 222 function websocket(test, frame) { |
| 222 return test_websocket(test, frame, get_websocket_url()); | 223 return test_websocket(test, frame, get_websocket_url()); |
| 223 } | 224 } |
| 224 | 225 |
| 225 function get_websocket_url() { | 226 function get_websocket_url() { |
| 226 return 'wss://{{host}}:{{ports[wss][0]}}/echo'; | 227 return 'wss://{{host}}:{{ports[wss][0]}}/echo'; |
| 227 } | 228 } |
| OLD | NEW |