OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: Registration</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharness-helpers.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/test-helpers.js"></script> |
| 7 <script> |
| 8 |
| 9 promise_test(function(t) { |
| 10 var script = '../resources/no-such-worker.js'; |
| 11 var scope = '../resources/scope/no-such-worker'; |
| 12 return navigator.serviceWorker.register(script, {scope: scope}) |
| 13 .then( |
| 14 function() { assert_unreached('Registering non-existent script should
fail.'); }, |
| 15 function(error) { |
| 16 assert_equals(error.name, 'NetworkError'); |
| 17 assert_equals( |
| 18 error.message, |
| 19 'Failed to register a ServiceWorker: A bad HTTP response code wa
s received when fetching the script.'); |
| 20 t.done(); |
| 21 }); |
| 22 }, 'Registering non-existent script'); |
| 23 |
| 24 promise_test(function(t) { |
| 25 var script = '../resources/invalid-chunked-encoding.php'; |
| 26 var scope = '../resources/scope/invalid-chunked-encoding/'; |
| 27 return navigator.serviceWorker.register(script, {scope: scope}) |
| 28 .then( |
| 29 function() { assert_unreached('Registration of invalid chunked encodin
g script should fail'); }, |
| 30 function(error) { |
| 31 assert_equals(error.name, 'NetworkError'); |
| 32 assert_equals(error.message, 'Failed to register a ServiceWorker: An
unknown error occurred when fetching the script.'); |
| 33 t.done(); |
| 34 }); |
| 35 }, 'Registering invalid chunked encoding script'); |
| 36 |
| 37 promise_test(function(t) { |
| 38 var script = '../resources/invalid-chunked-encoding-with-flush.php'; |
| 39 var scope = '../resources/scope/invalid-chunked-encoding-with-flush/'; |
| 40 return navigator.serviceWorker.register(script, {scope: scope}) |
| 41 .then( |
| 42 function() { assert_unreached('Registration of invalid chunked encodin
g script with flush should fail.'); }, |
| 43 function(error) { |
| 44 assert_equals(error.name, 'NetworkError'); |
| 45 assert_equals(error.message, 'Failed to register a ServiceWorker: An
unknown error occurred when fetching the script.'); |
| 46 t.done(); |
| 47 }); |
| 48 }, 'Registering invalid chunked encoding script with flush'); |
| 49 |
| 50 promise_test(function(t) { |
| 51 var script = '../resources/plain-text-worker.php'; |
| 52 var scope = '../resources/scope/plain-text-worker/'; |
| 53 return navigator.serviceWorker.register(script, {scope: scope}) |
| 54 .then( |
| 55 function() { assert_unreached('Registration of plain text script shoul
d fail.'); }, |
| 56 function(error) { |
| 57 assert_equals(error.name, 'SecurityError'); |
| 58 assert_equals( |
| 59 error.message, |
| 60 'Failed to register a ServiceWorker: The script does not have a
supported MIME type.'); |
| 61 t.done(); |
| 62 }); |
| 63 }, 'Registering script without correct MIME type'); |
| 64 |
| 65 promise_test(function(t) { |
| 66 var script = '../resources/redirect.php?Redirect=' + |
| 67 encodeURIComponent('/resources/registration-worker.js'); |
| 68 var scope = '../resources/scope/redirect/'; |
| 69 return navigator.serviceWorker.register(script, {scope: scope}) |
| 70 .then( |
| 71 function() { assert_unreached('Registration of redirected script shoul
d fail.'); }, |
| 72 function(error) { |
| 73 assert_equals(error.name, 'SecurityError'); |
| 74 assert_equals( |
| 75 error.message, |
| 76 'Failed to register a ServiceWorker: The script resource is behi
nd a redirect, which is disallowed.'); |
| 77 t.done(); |
| 78 }); |
| 79 }, 'Registering redirected script'); |
| 80 |
| 81 promise_test(function(t) { |
| 82 var script = '../resources/malformed-worker.php?parse-error'; |
| 83 var scope = '../resources/scope/parse-error'; |
| 84 return navigator.serviceWorker.register(script, {scope: scope}) |
| 85 .then( |
| 86 function() { assert_unreached('Registration of script including parse
error should fail.'); }, |
| 87 function(error) { |
| 88 assert_equals(error.name, 'AbortError'); |
| 89 assert_equals( |
| 90 error.message, |
| 91 'Failed to register a ServiceWorker: ServiceWorker cannot be sta
rted'); |
| 92 t.done(); |
| 93 }); |
| 94 }, 'Registering script including parse error'); |
| 95 |
| 96 promise_test(function(t) { |
| 97 var script = '../resources/malformed-worker.php?undefined-error'; |
| 98 var scope = '../resources/scope/undefined-error'; |
| 99 return navigator.serviceWorker.register(script, {scope: scope}) |
| 100 .then( |
| 101 function() { assert_unreached('Registration of script including undefi
ned error should fail.'); }, |
| 102 function(error) { |
| 103 assert_equals(error.name, 'AbortError'); |
| 104 assert_equals( |
| 105 error.message, |
| 106 'Failed to register a ServiceWorker: ServiceWorker cannot be sta
rted'); |
| 107 t.done(); |
| 108 }); |
| 109 }, 'Registering script including undefined error'); |
| 110 |
| 111 promise_test(function(t) { |
| 112 var script = '../resources/malformed-worker.php?uncaught-exception'; |
| 113 var scope = '../resources/scope/uncaught-exception'; |
| 114 return navigator.serviceWorker.register(script, {scope: scope}) |
| 115 .then( |
| 116 function() { assert_unreached('Registration of script including uncaug
ht exception should fail.'); }, |
| 117 function(error) { |
| 118 assert_equals(error.name, 'AbortError'); |
| 119 assert_equals( |
| 120 error.message, |
| 121 'Failed to register a ServiceWorker: ServiceWorker cannot be sta
rted'); |
| 122 t.done(); |
| 123 }); |
| 124 }, 'Registering script including uncaught exception'); |
| 125 |
| 126 promise_test(function(t) { |
| 127 var script = '../resources/malformed-worker.php?import-malformed-script'; |
| 128 var scope = '../resources/scope/import-malformed-script'; |
| 129 return navigator.serviceWorker.register(script, {scope: scope}) |
| 130 .then( |
| 131 function() { assert_unreached('Registration of script importing malfor
med script should fail.'); }, |
| 132 function(error) { |
| 133 assert_equals(error.name, 'AbortError'); |
| 134 assert_equals( |
| 135 error.message, |
| 136 'Failed to register a ServiceWorker: ServiceWorker cannot be sta
rted'); |
| 137 t.done(); |
| 138 }); |
| 139 }, 'Registering script importing malformed script'); |
| 140 |
| 141 promise_test(function(t) { |
| 142 var script = '../resources/malformed-worker.php?import-no-such-script'; |
| 143 var scope = '../resources/scope/import-no-such-script'; |
| 144 return navigator.serviceWorker.register(script, {scope: scope}) |
| 145 .then( |
| 146 function() { assert_unreached('Registration of script importing non-ex
istent script should fail.'); }, |
| 147 function(error) { |
| 148 assert_equals(error.name, 'AbortError'); |
| 149 assert_equals( |
| 150 error.message, |
| 151 'Failed to register a ServiceWorker: ServiceWorker cannot be sta
rted'); |
| 152 t.done(); |
| 153 }); |
| 154 }, 'Registering script importing non-existent script'); |
| 155 </script> |
OLD | NEW |