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