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

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

Issue 773153002: ServiceWorker: remove get_newest_worker() helper (cleanup) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove get_newest_worker() Created 6 years 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
« no previous file with comments | « LayoutTests/http/tests/serviceworker/postmessage.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 }); 59 });
60 iframe.src = ''; 60 iframe.src = '';
61 iframe.remove(); 61 iframe.remove();
62 return saw_unload; 62 return saw_unload;
63 } 63 }
64 64
65 function normalizeURL(url) { 65 function normalizeURL(url) {
66 return new URL(url, document.location).toString().replace(/#.*$/, ''); 66 return new URL(url, document.location).toString().replace(/#.*$/, '');
67 } 67 }
68 68
69 function get_newest_worker(registration) {
70 if (!registration) {
71 return Promise.reject(new Error(
72 'get_newest_worker must be passed a ServiceWorkerRegistration'));
73 }
74 if (registration.installing)
75 return Promise.resolve(registration.installing);
76 if (registration.waiting)
77 return Promise.resolve(registration.waiting);
78 if (registration.active)
79 return Promise.resolve(registration.active);
80 return Promise.reject(new Error(
81 'registration must have at least one version'));
82 }
83
84 function wait_for_update(test, registration) { 69 function wait_for_update(test, registration) {
85 if (!registration || registration.unregister == undefined) { 70 if (!registration || registration.unregister == undefined) {
86 return Promise.reject(new Error( 71 return Promise.reject(new Error(
87 'wait_for_update must be passed a ServiceWorkerRegistration')); 72 'wait_for_update must be passed a ServiceWorkerRegistration'));
88 } 73 }
89 74
90 return new Promise(test.step_func(function(resolve) { 75 return new Promise(test.step_func(function(resolve) {
91 registration.addEventListener('updatefound', test.step_func(function() { 76 registration.addEventListener('updatefound', test.step_func(function() {
92 resolve(registration.installing); 77 resolve(registration.installing);
93 })); 78 }));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 channel.port1.onmessage = test.step_func(function() { 242 channel.port1.onmessage = test.step_func(function() {
258 unload_iframe(frame).catch(function() {}); 243 unload_iframe(frame).catch(function() {});
259 resolve(); 244 resolve();
260 }); 245 });
261 frame.contentWindow.postMessage( 246 frame.contentWindow.postMessage(
262 {username: username, password: password, cookie: cookie}, 247 {username: username, password: password, cookie: cookie},
263 [channel.port2], origin); 248 [channel.port2], origin);
264 })); 249 }));
265 }); 250 });
266 } 251 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/postmessage.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698