Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / getregistration.html
blob95abb5829a7c07b7846db35840b3fcb8fba950e0
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
5 <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');
12 t.done();
14 .catch(unreached_rejection(t));
15 }, 'getRegistration');
17 async_test(function(t) {
18 var scope = 'resources/scope/getregistration/normal';
19 var registration;
20 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
21 scope)
22 .then(function(r) {
23 registration = r;
24 return navigator.serviceWorker.getRegistration(scope);
26 .then(function(value) {
27 assert_registration_equals(value, registration);
28 assert_not_equals(
29 value, registration,
30 'getRegistration should resolve to a new registration object');
31 service_worker_unregister_and_done(t, scope);
33 .catch(unreached_rejection(t));
34 }, 'Register then getRegistration');
36 async_test(function(t) {
37 var scope = 'resources/scope/getregistration/url-with-fragment';
38 var documentURL = scope + '#ref';
39 var registration;
40 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
41 scope)
42 .then(function(r) {
43 registration = r;
44 return navigator.serviceWorker.getRegistration(documentURL);
46 .then(function(value) {
47 assert_registration_equals(value, registration);
48 service_worker_unregister_and_done(t, scope);
50 .catch(unreached_rejection(t));
51 }, 'Register then getRegistration with a URL having a fragment');
53 async_test(function(t) {
54 var documentURL = 'http://example.com/';
55 navigator.serviceWorker.getRegistration(documentURL)
56 .then(function() {
57 assert_unreached(
58 'getRegistration with an out of origin URL should fail');
59 }, function(reason) {
60 assert_equals(
61 reason.name, 'SecurityError',
62 'getRegistration with an out of origin URL should fail');
63 t.done();
65 .catch(unreached_rejection(t));
66 }, 'getRegistration with a cross origin URL');
68 async_test(function(t) {
69 var scope = 'resources/scope/getregistration/register-unregister';
70 service_worker_unregister_and_register(t, 'resources/empty-worker.js',
71 scope)
72 .then(function(registration) {
73 return registration.unregister();
75 .then(function() {
76 return navigator.serviceWorker.getRegistration(scope);
78 .then(function(value) {
79 assert_equals(value, undefined,
80 'getRegistration should resolve with undefined');
81 t.done();
83 .catch(unreached_rejection(t));
84 }, 'Register then Unregister then getRegistration');
86 </script>