Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/getregistrations.html |
| diff --git a/LayoutTests/http/tests/serviceworker/getregistrations.html b/LayoutTests/http/tests/serviceworker/getregistrations.html |
| index 028ee9c4181f785a461dab903724f159398eed7f..e2eed6bf84e8a50f05edff0124f1d54a7b5391b8 100644 |
| --- a/LayoutTests/http/tests/serviceworker/getregistrations.html |
| +++ b/LayoutTests/http/tests/serviceworker/getregistrations.html |
| @@ -10,27 +10,28 @@ |
| // getRegistrations() is used in order to avoid adding additional complexity |
| // e.g. adding an internal function. |
| sequential_promise_test(function(t) { |
| - return navigator.serviceWorker.getRegistrations() |
| - .then(function(registrations) { |
| - return registrations.reduce(function(sequence, registration) { |
| - return sequence.then(function() { |
| - return registration.unregister(); |
| - }); |
| - }, Promise.resolve()); |
| + var resolve; |
| + var timer; |
| + var p = new Promise(function(r) { resolve = r; }); |
| + navigator.serviceWorker.getRegistrations() |
| + .then(function(regs) { |
| + return Promise.all(regs.map(function(r) { r.unregister(); })); |
| + }) |
| + .then(function() { |
| + timer = setInterval(function() { |
|
falken
2015/06/26 07:10:14
please comment why we need this
jungkees
2015/06/26 07:42:37
Added the comment.
|
| + navigator.serviceWorker.getRegistrations() |
| + .then(function(regs) { |
| + if (regs.length == 0) { |
| + clearInterval(timer); |
| + resolve(); |
| + } |
| + }); |
| + }, 100); |
| }); |
| + return p; |
| }, 'Purge the existing registrations.'); |
| sequential_promise_test(function(t) { |
| - return navigator.serviceWorker.getRegistrations() |
| - .then(function(value) { |
| - assert_array_equals( |
| - value, |
| - [], |
| - 'getRegistrations should resolve with an empty array.'); |
| - }); |
| - }, 'getRegistrations'); |
| - |
| -sequential_promise_test(function(t) { |
| var scope = 'resources/scope/getregistrations/normal'; |
| var script = 'resources/empty-worker.js'; |
| var registrations = []; |
| @@ -93,8 +94,8 @@ sequential_promise_test(function(t) { |
| }, 'Register then Unregister then getRegistrations'); |
| sequential_promise_test(function(t) { |
| - // Top-level window's origin is http://127.0.0.1:8000 |
| - // Set frame's origin to http://localhost:8000 |
| + // Top-level window's origin: http://127.0.0.1:8000. |
| + // Frame's origin: http://localhost:8000. |
| var host_info = get_host_info(); |
| var frame_url = host_info['HTTP_REMOTE_ORIGIN'] + |
| '/serviceworker/resources/frame-for-getregistrations.html'; |
| @@ -105,32 +106,34 @@ sequential_promise_test(function(t) { |
| return with_iframe(frame_url) |
| .then(function(f) { |
| - // frame registered its registration scoped |
| - // http://localhost:8000/serviceworker/resources/scope-for-getregistrations |
| frame = f; |
| - // Top-level window registers its registration scoped |
| - // http://127.0.0.1:8000/serviceworker/resources/scope-for-getregistrations |
| - return service_worker_unregister_and_register(t, script, scope); |
| - }) |
| - .then(function(r) { |
| - registrations.push(r); |
| - return navigator.serviceWorker.getRegistrations(); |
| - }) |
| - .then(function(value) { |
| - assert_array_equals( |
| - value, |
| - registrations, |
| - 'getRegistrations should only return same origin registrations.'); |
| - var channel = new MessageChannel(); |
| var resolve; |
| var p = new Promise(function(r) { resolve = r; }); |
| + var channel = new MessageChannel(); |
| + |
| channel.port1.onmessage = function(e) { |
| - if (e.data == 'unregistered') |
| + // Frame's registration is registered. |
| + if (e.data == 'registered') { |
| + // Top-level window registers a registration scoped |
| + // http://127.0.0.1:8000/serviceworker/resources/scope-for-getregistrations. |
| + service_worker_unregister_and_register(t, script, scope) |
| + .then(function(r) { |
| + registrations.push(r); |
| + return navigator.serviceWorker.getRegistrations(); |
| + }) |
| + .then(function(value) { |
| + assert_array_equals(value, registrations, |
| + 'getRegistrations should return only the same origin ' + |
| + 'registrations.'); |
| + channel.port1.postMessage('unregister'); |
| + }); |
| + } else if (e.data == 'unregistered') { |
| resolve(); |
| + } |
| }; |
| - frame.contentWindow.postMessage('unregister', '*', [channel.port2]); |
| + frame.contentWindow.postMessage('register', '*', [channel.port2]); |
| return p; |
| }) |
| .then(function() { |