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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..706bf802cc5a32b719c8acd3add38f30ba3986f7 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/getregistrations.html |
| @@ -0,0 +1,129 @@ |
| +<!DOCTYPE html> |
| +<title>Service Worker: getRegistrations()</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script src="../resources/get-host-info.js"></script> |
| +<script src="../fetch/resources/fetch-test-helpers.js"></script> |
| +<script> |
| +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 = []; |
| + 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( |
|
falken
2015/06/12 06:16:36
Actually does the spec guarantee object equality?
jungkees
2015/06/12 07:37:31
It should guarantee returning the same object. I t
|
| + value, |
| + registrations, |
| + 'getRegistrations should resolve with array of registrations.'); |
| + service_worker_unregister(t, scope); |
|
falken
2015/06/12 06:16:36
return service_worker_unregister
jungkees
2015/06/12 07:37:31
Done. Thanks for spotting.
|
| + }); |
| + }, 'Register then getRegistrations'); |
| + |
| +sequential_promise_test(function(t) { |
| + var scope1 = 'resources/scope/getregistrations/scope1'; |
| + var scope2 = 'resources/scope/getregistrations/scope2'; |
| + var script = 'resources/empty-worker.js'; |
| + var registrations = []; |
| + return service_worker_unregister_and_register(t, script, scope1) |
| + .then(function(r) { |
| + registrations.push(r); |
| + return service_worker_unregister_and_register(t, script, scope2); |
| + }) |
| + .then(function(r) { |
| + registrations.push(r); |
| + return navigator.serviceWorker.getRegistrations(); |
| + }) |
| + .then(function(value) { |
| + assert_array_equals( |
| + value, |
| + registrations, |
| + 'getRegistrations should resolve with array of registrations.'); |
| + return service_worker_unregister(t, scope1); |
| + }) |
| + .then(function() { |
| + return service_worker_unregister(t, scope2); |
| + }); |
| + }, 'Register multiple times then getRegistrations'); |
| + |
| +sequential_promise_test(function(t) { |
| + var scope = 'resources/scope/getregistrations/register-unregister'; |
| + var script = 'resources/empty-worker.js'; |
| + return service_worker_unregister_and_register(t, script, scope) |
| + .then(function(registration) { |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + return navigator.serviceWorker.getRegistrations(); |
| + }) |
| + .then(function(value) { |
| + assert_array_equals( |
| + value, |
| + [], |
| + 'getRegistrations should resolve with an empty array.'); |
| + }); |
| + }, '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 |
| + var host_info = get_host_info(); |
| + var frame_url = host_info['HTTP_REMOTE_ORIGIN'] + |
| + '/serviceworker/resources/frame-for-getregistrations.html'; |
| + var scope = 'resources/scope-for-getregistrations'; |
| + var script = 'resources/empty-worker.js'; |
| + var frame; |
| + var registrations = []; |
| + |
| + 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; }); |
| + |
| + channel.port1.onmessage = function(e) { |
| + if (e.data == 'unregistered') |
| + resolve(); |
| + }; |
| + frame.contentWindow.postMessage('unregister', '*', [channel.port2]); |
| + return p; |
| + }) |
| + .then(function() { |
|
falken
2015/06/12 06:16:36
remove the iframe here (per style guide https://ww
jungkees
2015/06/12 07:37:31
Done. Thanks.
|
| + return service_worker_unregister(t, scope); |
| + }); |
| + }, 'getRegistrations promise resolves only with same origin registrations.'); |
| + |
| +sequential_promise_test_done(); |
| +done(); |
| +</script> |