Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/getregistration.html |
| diff --git a/LayoutTests/http/tests/serviceworker/getregistration.html b/LayoutTests/http/tests/serviceworker/getregistration.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64a26ffc93a0b103f044420aa613d6689e9f9790 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/getregistration.html |
| @@ -0,0 +1,81 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script> |
| +async_test(function(t) { |
| + var documentURL = 'no-such-worker'; |
| + navigator.serviceWorker.getRegistration(documentURL) |
| + .then(function(value) { |
| + assert_equals(value, undefined, |
| + 'getRegistration should resolve with undefined'); |
| + t.done(); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'getRegistration'); |
| + |
| +async_test(function(t) { |
| + var scope = 'scope/worker/'; |
| + var registration; |
| + navigator.serviceWorker.register('resources/empty-worker.js', |
|
nhiroki
2014/09/11 11:30:34
Can you use service_worker_unregister_and_register
Kunihiko Sakamoto
2014/09/12 01:32:13
Done.
|
| + {scope: scope}) |
| + .then(function(r) { |
| + registration = r; |
| + return navigator.serviceWorker.getRegistration(scope); |
| + }) |
| + .then(function(value) { |
| + assert_equals(value, registration, |
| + 'getRegistration should resolve with registration'); |
| + t.done(); |
|
nhiroki
2014/09/11 11:30:34
To unregister the registration before finishing th
Kunihiko Sakamoto
2014/09/12 01:32:13
Done.
|
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Register then getRegistration'); |
| + |
| +async_test(function(t) { |
| + var documentURL = 'http://example.com/'; |
| + navigator.serviceWorker.getRegistration(documentURL) |
| + .then(function() { |
| + assert_unreached('getRegistration with an out of origin URL should fail'); |
|
nhiroki
2014/09/11 11:30:34
nit: +2-space indents
nit: please wrap this at 80-
Kunihiko Sakamoto
2014/09/12 01:32:13
Done.
|
| + }, function(reason) { |
| + assert_equals(reason.name, 'SecurityError', |
| + 'getRegistration with an out of origin URL should fail'); |
| + t.done(); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'getRegistration with a cross origin URL'); |
| + |
| +async_test(function(t) { |
| + var registration; |
| + navigator.serviceWorker.register('resources/empty-worker.js', |
| + {scope: location.href}) |
|
nhiroki
2014/09/11 11:30:34
Why do you use |location.href|?
We'd prefer to av
Kunihiko Sakamoto
2014/09/12 01:32:13
Wanted to test that getRegistration() gets a regis
nhiroki
2014/09/12 02:23:26
I see. Probably you can make an iframe for |scope|
|
| + .then(function(r) { |
| + registration = r; |
| + return navigator.serviceWorker.getRegistration(); |
| + }) |
| + .then(function(value) { |
| + assert_equals(value, registration, |
| + 'getRegistration should resolve with registration'); |
| + t.done(); |
|
nhiroki
2014/09/11 11:30:34
ditto (service_worker_unregister_and_done)
|
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'getRegistration without argument'); |
| + |
| +async_test(function(t) { |
| + var scope = 'scope/worker/'; |
| + navigator.serviceWorker.register('resources/empty-worker.js', |
| + {scope: scope}) |
| + .then(function(registration) { |
| + return registration.unregister(); |
| + }) |
| + .then(function() { |
| + return navigator.serviceWorker.getRegistration(scope); |
| + }) |
| + .then(function(value) { |
| + assert_equals(value, undefined, |
| + 'getRegistration should resolve with undefined'); |
| + t.done(); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Register then Unregister then getRegistration'); |
| + |
| +</script> |