2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
6 async_test(function(t) {
7 var documentURL = 'no-such-worker';
8 navigator.serviceWorker.getRegistration(documentURL)
9 .then(function(value) {
10 assert_equals(value, undefined,
11 'getRegistration should resolve with undefined');
14 .catch(unreached_rejection(t));
15 }, 'getRegistration');
17 async_test(function(t) {
18 var scope = 'resources/scope/getregistration/normal';
20 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
24 return navigator.serviceWorker.getRegistration(scope);
26 .then(function(value) {
27 assert_equals(value, registration,
28 'getRegistration should resolve with registration');
29 service_worker_unregister_and_done(t, scope);
31 .catch(unreached_rejection(t));
32 }, 'Register then getRegistration');
34 async_test(function(t) {
35 var scope = 'resources/scope/getregistration/url-with-fragment';
36 var documentURL = scope + '#ref';
38 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
42 return navigator.serviceWorker.getRegistration(documentURL);
44 .then(function(value) {
45 assert_equals(value, registration,
46 'getRegistration should resolve with registration');
47 service_worker_unregister_and_done(t, scope);
49 .catch(unreached_rejection(t));
50 }, 'Register then getRegistration with a URL having a fragment');
52 async_test(function(t) {
53 var documentURL = 'http://example.com/';
54 navigator.serviceWorker.getRegistration(documentURL)
57 'getRegistration with an out of origin URL should fail');
60 reason.name, 'SecurityError',
61 'getRegistration with an out of origin URL should fail');
64 .catch(unreached_rejection(t));
65 }, 'getRegistration with a cross origin URL');
67 async_test(function(t) {
68 var scope = 'resources/scope/getregistration/register-unregister';
69 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
71 .then(function(registration) {
72 return registration.unregister();
75 return navigator.serviceWorker.getRegistration(scope);
77 .then(function(value) {
78 assert_equals(value, undefined,
79 'getRegistration should resolve with undefined');
82 .catch(unreached_rejection(t));
83 }, 'Register then Unregister then getRegistration');