Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/test-helpers.js

Issue 1859343002: ServiceWorker: Remove iframes explicitly after a test is finished (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove a comment line Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 |reclaim_after_completion| is set to
48 // iframe later if needed. 48 // |IFRAME_RECLAMATION.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 var IFRAME_RECLAMATION = Object.freeze({TRUE: true, FALSE: false});
nhiroki 2016/04/07 05:37:18 How about using 'const' keyword instead? const
falken 2016/04/07 05:47:26 Sorry for more drive-bys, just thought of this. Pa
shimazu (google) 2016/04/07 06:53:55 I think so, and fixed it.
51 function with_iframe(url, reclaim_after_completion) {
50 return new Promise(function(resolve) { 52 return new Promise(function(resolve) {
51 var frame = document.createElement('iframe'); 53 var frame = document.createElement('iframe');
52 frame.src = url; 54 frame.src = url;
53 frame.onload = function() { resolve(frame); }; 55 frame.onload = function() { resolve(frame); };
54 document.body.appendChild(frame); 56 document.body.appendChild(frame);
57 if (typeof reclaim_after_completion === 'undefined' ||
58 reclaim_after_completion === IFRAME_RECLAMATION.TRUE)
59 add_completion_callback(function() { frame.remove(); });
55 }); 60 });
56 } 61 }
57 62
58 function with_sandboxed_iframe(url, sandbox) { 63 function with_sandboxed_iframe(url, sandbox) {
59 return new Promise(function(resolve) { 64 return new Promise(function(resolve) {
60 var frame = document.createElement('iframe'); 65 var frame = document.createElement('iframe');
61 frame.sandbox = sandbox; 66 frame.sandbox = sandbox;
62 frame.src = url; 67 frame.src = url;
63 frame.onload = function() { resolve(frame); }; 68 frame.onload = function() { resolve(frame); };
64 document.body.appendChild(frame); 69 document.body.appendChild(frame);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 195
191 function login(test, local, remote) { 196 function login(test, local, remote) {
192 var suffix = (local.indexOf("https") != -1) ? "s": ""; 197 var suffix = (local.indexOf("https") != -1) ? "s": "";
193 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, 198 return test_login(test, local, 'username1' + suffix, 'password1' + suffix,
194 'cookie1') 199 'cookie1')
195 .then(function() { 200 .then(function() {
196 return test_login(test, remote, 'username2' + suffix, 201 return test_login(test, remote, 'username2' + suffix,
197 'password2' + suffix, 'cookie2'); 202 'password2' + suffix, 'cookie2');
198 }); 203 });
199 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698