OLD | NEW |
---|---|
1 <html> | 1 <!DOCTYPE html> |
dominicc (has gone to gerrit)
2014/04/09 20:09:08
My favorite file, this is a nice set of sweet litt
jsbell
2014/04/09 23:04:40
Originally written by kinuko, obviously. :)
| |
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 var test_registerBasics = async_test('Registering normal pattern'); |
7 test_registerBasics.step(function() { | |
8 navigator.serviceWorker.register('resources/registration-worker.js', | |
9 {scope: '/*'}).then( | |
10 test_registerBasics.step_func(function(worker) { | |
dominicc (has gone to gerrit)
2014/04/09 20:09:08
BTW, inside step/step_func I think you can use 'th
jsbell
2014/04/09 23:04:40
Having tried both, I think I like your `var t` sty
| |
11 assert_true(!!worker, 'Successfully registered'); | |
dominicc (has gone to gerrit)
2014/04/09 20:09:08
Can we make this more useful, eg !!worker -> worke
jsbell
2014/04/09 23:04:40
I had the 'instanceof' test, actually, but the IDL
| |
12 test_registerBasics.done(); | |
13 }), | |
14 test_registerBasics.step_func(function(reason) { | |
15 assert_equals(reason.name, 'DisabledError'); | |
16 test_registerBasics.done(); | |
17 })); | |
18 }); | |
8 | 19 |
9 function test_registerBasics() { | 20 var test_registerPatternOutsideDomain = async_test('Registering pattern outside domain'); |
10 debug("Registering normal pattern"); | 21 test_registerPatternOutsideDomain.step(function() { |
11 return navigator.serviceWorker.register("serviceworker.js", {scope:"/* "}).then( | 22 navigator.serviceWorker.register('resources/registration-worker.js', |
12 function(worker) { | 23 {scope: 'http://example.com/*'}).then( |
13 debug("Successfully registered"); | 24 test_registerPatternOutsideDomain.step_func(function(worker) { |
14 return worker; | 25 assert_unreached('Registration outside domain should fail'); |
15 }, | 26 }), |
16 function(e) { | 27 test_registerPatternOutsideDomain.step_func(function(reason) { |
17 regError = e; | 28 assert_equals(reason.name, 'SecurityError'); |
18 shouldBe("'DisabledError'", "regError.name"); | 29 test_registerPatternOutsideDomain.done(); |
19 }); | 30 })); |
20 } | 31 }); |
21 function test_registerPatternOutsideDomain() { | 32 |
22 debug("Registering pattern outside domain"); | 33 var test_registerScriptOutsideDomain = async_test('Registering script outside do main'); |
23 return navigator.serviceWorker.register("serviceworker.js", {scope:"ht tp://foo.com/*"}) | 34 test_registerScriptOutsideDomain.step(function() { |
24 .catch(function(e) { | 35 navigator.serviceWorker.register('http://example.com/worker.js').then( |
25 regError = e; | 36 test_registerScriptOutsideDomain.step_func(function(worker) { |
26 shouldBe("'SecurityError'", "regError.name"); | 37 assert_unreached('Registration outside domain should fail'); |
27 }); | 38 }), |
28 } | 39 test_registerScriptOutsideDomain.step_func(function(reason) { |
29 function test_registerScriptOutsideDomain() { | 40 assert_equals(reason.name, 'SecurityError'); |
30 debug("Registering pattern outside domain"); | 41 test_registerScriptOutsideDomain.done(); |
31 return navigator.serviceWorker.register("http://foo.com/serviceworker. js") | 42 })); |
32 .catch(function(e) { | 43 }); |
33 regError = e; | 44 |
34 shouldBe("'SecurityError'", "regError.name"); | |
35 }); | |
36 } | |
37 var jsTestIsAsync = true; | |
38 test_registerBasics() | |
39 .then(test_registerPatternOutsideDomain) | |
40 .then(test_registerScriptOutsideDomain) | |
41 .then(finishJSTest, function(e) { | |
42 testFailed("Tests failed, exited with error:" + e.name + ": " + e.mess age); | |
43 finishJSTest(); | |
44 }); | |
45 </script> | 45 </script> |
46 <script src="/js-test-resources/js-test-post.js"></script> | |
47 </body> | |
48 </html> | |
OLD | NEW |