fdd83b3e448ec3b426115d52ed368f717af74b44
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / registration.html
1 <!DOCTYPE html>
2 <title>Service Worker: Registration</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script>
6 (function() {
7     var t = async_test('Registering normal pattern');
8     t.step(function() {
9         navigator.serviceWorker.register(
10             'resources/registration-worker.js',
11             {scope: '/registration/*'}
12         ).then(
13             t.step_func(function(worker) {
14                 assert_true(worker instanceof ServiceWorker,
15                             'Successfully registered.');
16                 t.done();
17             }),
18             t.step_func(function(reason) {
19                 assert_unreached('Registration should succeed, but failed: ' + reason.name);
20             })
21         );
22     });
23 }());
24
25 (function() {
26     var t = async_test('Registering scope outside domain');
27     t.step(function() {
28         navigator.serviceWorker.register(
29             'resources/registration-worker.js',
30             {scope: 'http://example.com/*'}
31         ).then(
32             t.step_func(function(worker) {
33                 assert_unreached('Registration scope outside domain should fail.');
34             }),
35             t.step_func(function(reason) {
36                 assert_equals(reason.name, 'SecurityError',
37                               'Registration scope outside domain should fail with SecurityError.');
38                 t.done();
39             })
40         );
41     });
42 }());
43
44 (function() {
45     var t = async_test('Registering script outside domain');
46     t.step(function() {
47         navigator.serviceWorker.register(
48             'http://example.com/worker.js'
49         ).then(
50             t.step_func(function(worker) {
51                 assert_unreached('Registration script outside domain should fail.');
52             }),
53             t.step_func(function(reason) {
54                 assert_equals(reason.name, 'SecurityError',
55                              'Registration script outside domain should fail with SecurityError.');
56                 t.done();
57             })
58         );
59     });
60 }());
61
62 (function() {
63     var t = async_test('Registering non-existent script');
64     t.step(function() {
65         navigator.serviceWorker.register(
66             'resources/no-such-worker.js'
67         ).then(
68             t.step_func(function(worker) {
69                 assert_unreached('Registration of non-existent script should fail.');
70             }),
71             t.step_func(function(reason) {
72                 assert_equals(reason.name, 'AbortError',
73                              'Registration of non-existent script should fail.');
74                 t.done();
75             })
76         );
77     });
78 }());
79
80 </script>