| OLD | NEW |
| 1 <html> | 1 <!DOCTYPE html> |
| 2 <head> | 2 <title>Service Worker: Registration</title> |
| 3 <script src="/js-test-resources/js-test.js"></script> | 3 <script src="../resources/testharness.js"></script> |
| 4 </head> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <body> | |
| 6 <script> | 5 <script> |
| 7 description("Tests if ServiceWorker registration is working") | 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: '/*'} |
| 12 ).then( |
| 13 t.step_func(function(worker) { |
| 14 assert_true(!!worker, 'Successfully registered.'); |
| 15 t.done(); |
| 16 }), |
| 17 t.step_func(function(reason) { |
| 18 assert_unreached('Registration should succeed, but failed: ' + r
eason.name); |
| 19 }) |
| 20 ); |
| 21 }); |
| 22 }()); |
| 8 | 23 |
| 9 function test_registerBasics() { | 24 (function() { |
| 10 debug("Registering normal pattern"); | 25 var t = async_test('Registering scope outside domain'); |
| 11 return navigator.serviceWorker.register("serviceworker.js", {scope:"/*
"}).then( | 26 t.step(function() { |
| 12 function(worker) { | 27 navigator.serviceWorker.register( |
| 13 debug("Successfully registered"); | 28 'resources/registration-worker.js', |
| 14 return worker; | 29 {scope: 'http://example.com/*'} |
| 15 }, | 30 ).then( |
| 16 function(e) { | 31 t.step_func(function(worker) { |
| 17 regError = e; | 32 assert_unreached('Registration scope outside domain should fail.
'); |
| 18 shouldBe("'DisabledError'", "regError.name"); | 33 }), |
| 19 }); | 34 t.step_func(function(reason) { |
| 20 } | 35 assert_equals(reason.name, 'SecurityError', |
| 21 function test_registerPatternOutsideDomain() { | 36 'Registration scope outside domain should fail wit
h SecurityError.'); |
| 22 debug("Registering pattern outside domain"); | 37 t.done(); |
| 23 return navigator.serviceWorker.register("serviceworker.js", {scope:"ht
tp://foo.com/*"}) | 38 }) |
| 24 .catch(function(e) { | 39 ); |
| 25 regError = e; | 40 }); |
| 26 shouldBe("'SecurityError'", "regError.name"); | 41 }()); |
| 27 }); | 42 |
| 28 } | 43 (function() { |
| 29 function test_registerScriptOutsideDomain() { | 44 var t = async_test('Registering script outside domain'); |
| 30 debug("Registering pattern outside domain"); | 45 t.step(function() { |
| 31 return navigator.serviceWorker.register("http://foo.com/serviceworker.
js") | 46 navigator.serviceWorker.register( |
| 32 .catch(function(e) { | 47 'http://example.com/worker.js' |
| 33 regError = e; | 48 ).then( |
| 34 shouldBe("'SecurityError'", "regError.name"); | 49 t.step_func(function(worker) { |
| 35 }); | 50 assert_unreached('Registration script outside domain should fail
.'); |
| 36 } | 51 }), |
| 37 var jsTestIsAsync = true; | 52 t.step_func(function(reason) { |
| 38 test_registerBasics() | 53 assert_equals(reason.name, 'SecurityError', |
| 39 .then(test_registerPatternOutsideDomain) | 54 'Registration script outside domain should fail wit
h SecurityError.'); |
| 40 .then(test_registerScriptOutsideDomain) | 55 t.done(); |
| 41 .then(finishJSTest, function(e) { | 56 }) |
| 42 testFailed("Tests failed, exited with error:" + e.name + ": " + e.mess
age); | 57 ); |
| 43 finishJSTest(); | 58 }); |
| 44 }); | 59 }()); |
| 60 |
| 45 </script> | 61 </script> |
| 46 <script src="/js-test-resources/js-test-post.js"></script> | |
| 47 </body> | |
| 48 </html> | |
| OLD | NEW |