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

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: 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. By default, the caller is responsible for
nhiroki 2016/04/06 07:46:35 "By default" sounds a bit unclear. Can you elabora
falken 2016/04/06 07:49:05 Drive-by comment: How about making reclaim_after_c
shimazu (google) 2016/04/07 04:17:59 Done.
48 // iframe later if needed. 48 // removing the iframe later if needed.
49 function with_iframe(url) { 49 function with_iframe(url, reclaim_after_completion) {
50 return new Promise(function(resolve) { 50 return new Promise(function(resolve) {
51 var frame = document.createElement('iframe'); 51 var frame = document.createElement('iframe');
52 frame.src = url; 52 frame.src = url;
53 frame.onload = function() { resolve(frame); }; 53 frame.onload = function() { resolve(frame); };
54 document.body.appendChild(frame); 54 document.body.appendChild(frame);
55 if (reclaim_after_completion)
nhiroki 2016/04/06 07:46:35 if (reclaim_after_compleation === true) ... could
shimazu (google) 2016/04/07 04:17:59 Done.
56 add_completion_callback(function() { frame.remove(); });
55 }); 57 });
56 } 58 }
57 59
58 function with_sandboxed_iframe(url, sandbox) { 60 function with_sandboxed_iframe(url, sandbox) {
59 return new Promise(function(resolve) { 61 return new Promise(function(resolve) {
60 var frame = document.createElement('iframe'); 62 var frame = document.createElement('iframe');
61 frame.sandbox = sandbox; 63 frame.sandbox = sandbox;
62 frame.src = url; 64 frame.src = url;
63 frame.onload = function() { resolve(frame); }; 65 frame.onload = function() { resolve(frame); };
64 document.body.appendChild(frame); 66 document.body.appendChild(frame);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 192
191 function login(test, local, remote) { 193 function login(test, local, remote) {
192 var suffix = (local.indexOf("https") != -1) ? "s": ""; 194 var suffix = (local.indexOf("https") != -1) ? "s": "";
193 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, 195 return test_login(test, local, 'username1' + suffix, 'password1' + suffix,
194 'cookie1') 196 'cookie1')
195 .then(function() { 197 .then(function() {
196 return test_login(test, remote, 'username2' + suffix, 198 return test_login(test, remote, 'username2' + suffix,
197 'password2' + suffix, 'cookie2'); 199 'password2' + suffix, 'cookie2');
198 }); 200 });
199 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698