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 26 matching lines...) Expand all Loading... |
37 // Rejection-specific helper that provides more details | 37 // Rejection-specific helper that provides more details |
38 function unreached_rejection(test, prefix) { | 38 function unreached_rejection(test, prefix) { |
39 return test.step_func(function(error) { | 39 return test.step_func(function(error) { |
40 var reason = error.message || error.name || error; | 40 var reason = error.message || error.name || error; |
41 var error_prefix = prefix || 'unexpected rejection'; | 41 var error_prefix = prefix || 'unexpected rejection'; |
42 assert_unreached(error_prefix + ': ' + reason); | 42 assert_unreached(error_prefix + ': ' + reason); |
43 }); | 43 }); |
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. The caller is responsible for removing the | 47 // iframe when it finishes loading. When |options.auto_remove| is set to |
48 // iframe later if needed. | 48 // |false|, the caller is responsible for removing the iframe |
49 function with_iframe(url) { | 49 // later. Otherwise, the frame will be removed after all tests are finished. |
| 50 function with_iframe(url, options) { |
50 return new Promise(function(resolve) { | 51 return new Promise(function(resolve) { |
51 var frame = document.createElement('iframe'); | 52 var frame = document.createElement('iframe'); |
52 frame.src = url; | 53 frame.src = url; |
53 frame.onload = function() { resolve(frame); }; | 54 frame.onload = function() { resolve(frame); }; |
54 document.body.appendChild(frame); | 55 document.body.appendChild(frame); |
| 56 if (typeof options === 'undefined') |
| 57 options = {}; |
| 58 if (typeof options.auto_remove === 'undefined') |
| 59 options.auto_remove = true; |
| 60 if (options.auto_remove) |
| 61 add_completion_callback(function() { frame.remove(); }); |
55 }); | 62 }); |
56 } | 63 } |
57 | 64 |
58 function with_sandboxed_iframe(url, sandbox) { | 65 function with_sandboxed_iframe(url, sandbox) { |
59 return new Promise(function(resolve) { | 66 return new Promise(function(resolve) { |
60 var frame = document.createElement('iframe'); | 67 var frame = document.createElement('iframe'); |
61 frame.sandbox = sandbox; | 68 frame.sandbox = sandbox; |
62 frame.src = url; | 69 frame.src = url; |
63 frame.onload = function() { resolve(frame); }; | 70 frame.onload = function() { resolve(frame); }; |
64 document.body.appendChild(frame); | 71 document.body.appendChild(frame); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 197 |
191 function login(test, local, remote) { | 198 function login(test, local, remote) { |
192 var suffix = (local.indexOf("https") != -1) ? "s": ""; | 199 var suffix = (local.indexOf("https") != -1) ? "s": ""; |
193 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, | 200 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, |
194 'cookie1') | 201 'cookie1') |
195 .then(function() { | 202 .then(function() { |
196 return test_login(test, remote, 'username2' + suffix, | 203 return test_login(test, remote, 'username2' + suffix, |
197 'password2' + suffix, 'cookie2'); | 204 'password2' + suffix, 'cookie2'); |
198 }); | 205 }); |
199 } | 206 } |
OLD | NEW |