| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Adds an iframe to the document and returns a promise that resolves to the | 46 // Adds an iframe to the document and returns a promise that resolves to the |
| 47 // iframe when it finishes loading. When |options.auto_remove| is set to | 47 // iframe when it finishes loading. When |options.auto_remove| is set to |
| 48 // |false|, the caller is responsible for removing the iframe | 48 // |false|, the caller is responsible for removing the iframe |
| 49 // later. Otherwise, the frame will be removed after all tests are finished. | 49 // later. Otherwise, the frame will be removed after all tests are finished. |
| 50 function with_iframe(url, options) { | 50 function with_iframe(url, options) { |
| 51 return new Promise(function(resolve) { | 51 return new Promise(function(resolve) { |
| 52 var frame = document.createElement('iframe'); | 52 var frame = document.createElement('iframe'); |
| 53 frame.src = url; | 53 frame.src = url; |
| 54 // Make sure the iframe stays in the viewport even if the test creates |
| 55 // many of them. Otherwise some iframes may end up being throttled. |
| 56 frame.style.position = 'absolute'; |
| 54 frame.onload = function() { resolve(frame); }; | 57 frame.onload = function() { resolve(frame); }; |
| 55 document.body.appendChild(frame); | 58 document.body.appendChild(frame); |
| 56 if (typeof options === 'undefined') | 59 if (typeof options === 'undefined') |
| 57 options = {}; | 60 options = {}; |
| 58 if (typeof options.auto_remove === 'undefined') | 61 if (typeof options.auto_remove === 'undefined') |
| 59 options.auto_remove = true; | 62 options.auto_remove = true; |
| 60 if (options.auto_remove) | 63 if (options.auto_remove) |
| 61 add_completion_callback(function() { frame.remove(); }); | 64 add_completion_callback(function() { frame.remove(); }); |
| 62 }); | 65 }); |
| 63 } | 66 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 202 |
| 200 function login(test, local, remote) { | 203 function login(test, local, remote) { |
| 201 var suffix = (local.indexOf("https") != -1) ? "s": ""; | 204 var suffix = (local.indexOf("https") != -1) ? "s": ""; |
| 202 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, | 205 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, |
| 203 'cookie1') | 206 'cookie1') |
| 204 .then(function() { | 207 .then(function() { |
| 205 return test_login(test, remote, 'username2' + suffix, | 208 return test_login(test, remote, 'username2' + suffix, |
| 206 'password2' + suffix, 'cookie2'); | 209 'password2' + suffix, 'cookie2'); |
| 207 }); | 210 }); |
| 208 } | 211 } |
| OLD | NEW |