How to use service_worker_unregister_and_done method in wpt

Best JavaScript code snippet using wpt

registration-tests.js

Source:registration-tests.js Github

copy

Full Screen

...20 .then(function(registration) {21 assert_equals(registration.constructor.name,22 'ServiceWorkerRegistration',23 'Successfully registered.');24 service_worker_unregister_and_done(t, scope);25 })26 }, 'Registering normal scope');27 promise_test(function(t) {28 var script = 'resources/registration-worker.js';29 var scope = 'resources/registration/scope-with-fragment#ref';30 return register_method(script, {scope: scope})31 .then(function(registration) {32 assert_equals(registration.constructor.name,33 'ServiceWorkerRegistration',34 'Successfully registered.');35 assert_equals(36 registration.scope,37 normalizeURL('resources/registration/scope-with-fragment'),38 'A fragment should be removed from scope')39 service_worker_unregister_and_done(t, scope);40 })41 }, 'Registering scope with fragment');42 promise_test(function(t) {43 var script = 'resources/registration-worker.js';44 var scope = 'resources/';45 return register_method(script, {scope: scope})46 .then(function(registration) {47 assert_equals(registration.constructor.name,48 'ServiceWorkerRegistration',49 'Successfully registered.');50 service_worker_unregister_and_done(t, scope);51 })52 }, 'Registering same scope as the script directory');53 promise_test(function(t) {54 var script = 'resources/registration-worker.js';55 var scope = 'resources';56 return promise_rejects(t,57 check_error_types ? 'SecurityError' : null,58 register_method(script, {scope: scope}),59 'Registering same scope as the script directory without the last ' +60 'slash should fail with SecurityError.');61 }, 'Registering same scope as the script directory without the last slash');62 promise_test(function(t) {63 var script = 'resources/registration-worker.js';64 var scope = 'different-directory/';65 return promise_rejects(t,66 check_error_types ? 'SecurityError' : null,67 register_method(script, {scope: scope}),68 'Registration scope outside the script directory should fail ' +69 'with SecurityError.');70 }, 'Registration scope outside the script directory');71 promise_test(function(t) {72 var script = 'resources/registration-worker.js';73 var scope = 'http://example.com/';74 return promise_rejects(t,75 check_error_types ? 'SecurityError' : null,76 register_method(script, {scope: scope}),77 'Registration scope outside domain should fail with SecurityError.');78 }, 'Registering scope outside domain');79 promise_test(function(t) {80 var script = 'http://example.com/worker.js';81 var scope = 'http://example.com/scope/';82 return promise_rejects(t,83 check_error_types ? 'SecurityError' : null,84 register_method(script, {scope: scope}),85 'Registration script outside domain should fail with SecurityError.');86 }, 'Registering script outside domain');87 promise_test(function(t) {88 var script = 'resources/no-such-worker.js';89 var scope = 'resources/scope/no-such-worker';90 return promise_rejects(t,91 check_error_types ? new TypeError : null,92 register_method(script, {scope: scope}),93 navigator.serviceWorker.register(script, {scope: scope}),94 'Registration of non-existent script should fail.');95 }, 'Registering non-existent script');96 promise_test(function(t) {97 var script = 'resources/invalid-chunked-encoding.php';98 var scope = 'resources/scope/invalid-chunked-encoding/';99 return promise_rejects(t,100 check_error_types ? new TypeError : null,101 register_method(script, {scope: scope}),102 'Registration of invalid chunked encoding script should fail.');103 }, 'Registering invalid chunked encoding script');104 promise_test(function(t) {105 var script = 'resources/invalid-chunked-encoding-with-flush.php';106 var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';107 return promise_rejects(t,108 check_error_types ? new TypeError : null,109 register_method(script, {scope: scope}),110 'Registration of invalid chunked encoding script should fail.');111 }, 'Registering invalid chunked encoding script with flush');112 promise_test(function(t) {113 var script = 'resources/mime-type-worker.php';114 var scope = 'resources/scope/no-mime-type-worker/';115 return promise_rejects(t,116 check_error_types ? 'SecurityError' : null,117 register_method(script, {scope: scope}),118 'Registration of no MIME type script should fail.');119 }, 'Registering script with no MIME type');120 promise_test(function(t) {121 var script = 'resources/mime-type-worker.php?mime=text/plain';122 var scope = 'resources/scope/bad-mime-type-worker/';123 return promise_rejects(t,124 check_error_types ? 'SecurityError' : null,125 register_method(script, {scope: scope}),126 'Registration of plain text script should fail.');127 }, 'Registering script with bad MIME type');128 promise_test(function(t) {129 var script = 'resources/redirect.php?Redirect=' +130 encodeURIComponent('/resources/registration-worker.js');131 var scope = 'resources/scope/redirect/';132 return promise_rejects(t,133 check_error_types ? 'SecurityError' : null,134 register_method(script, {scope: scope}),135 'Registration of redirected script should fail.');136 }, 'Registering redirected script');137 promise_test(function(t) {138 var script = 'resources/malformed-worker.php?parse-error';139 var scope = 'resources/scope/parse-error';140 return promise_rejects(t,141 check_error_types ? new TypeError : null,142 register_method(script, {scope: scope}),143 'Registration of script including parse error should fail.');144 }, 'Registering script including parse error');145 promise_test(function(t) {146 var script = 'resources/malformed-worker.php?undefined-error';147 var scope = 'resources/scope/undefined-error';148 return promise_rejects(t,149 check_error_types ? new TypeError : null,150 register_method(script, {scope: scope}),151 'Registration of script including undefined error should fail.');152 }, 'Registering script including undefined error');153 promise_test(function(t) {154 var script = 'resources/malformed-worker.php?uncaught-exception';155 var scope = 'resources/scope/uncaught-exception';156 return promise_rejects(t,157 check_error_types ? new TypeError : null,158 register_method(script, {scope: scope}),159 'Registration of script including uncaught exception should fail.');160 }, 'Registering script including uncaught exception');161 promise_test(function(t) {162 var script = 'resources/malformed-worker.php?caught-exception';163 var scope = 'resources/scope/caught-exception';164 return register_method(script, {scope: scope})165 .then(function(registration) {166 assert_equals(registration.constructor.name,167 'ServiceWorkerRegistration',168 'Successfully registered.');169 service_worker_unregister_and_done(t, scope);170 })171 }, 'Registering script including caught exception');172 promise_test(function(t) {173 var script = 'resources/malformed-worker.php?import-malformed-script';174 var scope = 'resources/scope/import-malformed-script';175 return promise_rejects(t,176 check_error_types ? new TypeError : null,177 register_method(script, {scope: scope}),178 'Registration of script importing malformed script should fail.');179 }, 'Registering script importing malformed script');180 promise_test(function(t) {181 var script = 'resources/malformed-worker.php?import-no-such-script';182 var scope = 'resources/scope/import-no-such-script';183 return promise_rejects(t,184 check_error_types ? new TypeError : null,185 register_method(script, {scope: scope}),186 'Registration of script importing non-existent script should fail.');187 }, 'Registering script importing non-existent script');188 promise_test(function(t) {189 // URL-encoded full-width 'scope'.190 var name = '%ef%bd%93%ef%bd%83%ef%bd%8f%ef%bd%90%ef%bd%85';191 var script = 'resources/empty-worker.js';192 var scope = 'resources/' + name + '/escaped-multibyte-character-scope';193 return register_method(script, {scope: scope})194 .then(function(registration) {195 assert_equals(196 registration.scope,197 normalizeURL(scope),198 'URL-encoded multibyte characters should be available.');199 service_worker_unregister_and_done(t, scope);200 });201 }, 'Scope including URL-encoded multibyte characters');202 promise_test(function(t) {203 // Non-URL-encoded full-width "scope".204 var name = String.fromCodePoint(0xff53, 0xff43, 0xff4f, 0xff50, 0xff45);205 var script = 'resources/empty-worker.js';206 var scope = 'resources/' + name + '/non-escaped-multibyte-character-scope';207 return register_method(script, {scope: scope})208 .then(function(registration) {209 assert_equals(210 registration.scope,211 normalizeURL(scope),212 'Non-URL-encoded multibyte characters should be available.');213 service_worker_unregister_and_done(t, scope);214 });215 }, 'Scope including non-escaped multibyte characters');216 promise_test(function(t) {217 var script = 'resources%2fempty-worker.js';218 var scope = 'resources/scope/encoded-slash-in-script-url';219 return promise_rejects(t,220 check_error_types ? new TypeError : null,221 register_method(script, {scope: scope}),222 'URL-encoded slash in the script URL should be rejected.');223 }, 'Script URL including URL-encoded slash');224 promise_test(function(t) {225 var script = 'resources%2Fempty-worker.js';226 var scope = 'resources/scope/encoded-slash-in-script-url';227 return promise_rejects(t,228 check_error_types ? new TypeError : null,229 register_method(script, {scope: scope}),230 'URL-encoded slash in the script URL should be rejected.');231 }, 'Script URL including uppercase URL-encoded slash');232 promise_test(function(t) {233 var script = 'resources/empty-worker.js';234 var scope = 'resources/scope%2fencoded-slash-in-scope';235 return promise_rejects(t,236 check_error_types ? new TypeError : null,237 register_method(script, {scope: scope}),238 'URL-encoded slash in the scope should be rejected.');239 }, 'Scope including URL-encoded slash');240 promise_test(function(t) {241 var script = 'resources%5cempty-worker.js';242 var scope = 'resources/scope/encoded-slash-in-script-url';243 return promise_rejects(t,244 check_error_types ? new TypeError : null,245 register_method(script, {scope: scope}),246 'URL-encoded backslash in the script URL should be rejected.');247 }, 'Script URL including URL-encoded backslash');248 promise_test(function(t) {249 var script = 'resources%5Cempty-worker.js';250 var scope = 'resources/scope/encoded-slash-in-script-url';251 return promise_rejects(t,252 check_error_types ? new TypeError : null,253 register_method(script, {scope: scope}),254 'URL-encoded backslash in the script URL should be rejected.');255 }, 'Script URL including uppercase URL-encoded backslash');256 promise_test(function(t) {257 var script = 'resources/empty-worker.js';258 var scope = 'resources/scope%5cencoded-slash-in-scope';259 return promise_rejects(t,260 check_error_types ? new TypeError : null,261 register_method(script, {scope: scope}),262 'URL-encoded backslash in the scope should be rejected.');263 }, 'Scope including URL-encoded backslash');264 promise_test(function(t) {265 var script = 'resources/././empty-worker.js';266 var scope = 'resources/scope/parent-reference-in-script-url';267 return register_method(script, {scope: scope})268 .then(function(registration) {269 assert_equals(270 get_newest_worker(registration).scriptURL,271 normalizeURL('resources/empty-worker.js'),272 'Script URL including self-reference should be normalized.');273 service_worker_unregister_and_done(t, scope);274 });275 }, 'Script URL including self-reference');276 promise_test(function(t) {277 var script = 'resources/empty-worker.js';278 var scope = 'resources/././scope/self-reference-in-scope';279 return register_method(script, {scope: scope})280 .then(function(registration) {281 assert_equals(282 registration.scope,283 normalizeURL('resources/scope/self-reference-in-scope'),284 'Scope including self-reference should be normalized.');285 service_worker_unregister_and_done(t, scope);286 });287 }, 'Scope including self-reference');288 promise_test(function(t) {289 var script = 'resources/../resources/empty-worker.js';290 var scope = 'resources/scope/parent-reference-in-script-url';291 return register_method(script, {scope: scope})292 .then(function(registration) {293 assert_equals(294 get_newest_worker(registration).scriptURL,295 normalizeURL('resources/empty-worker.js'),296 'Script URL including parent-reference should be normalized.');297 service_worker_unregister_and_done(t, scope);298 });299 }, 'Script URL including parent-reference');300 promise_test(function(t) {301 var script = 'resources/empty-worker.js';302 var scope = 'resources/../resources/scope/parent-reference-in-scope';303 return register_method(script, {scope: scope})304 .then(function(registration) {305 assert_equals(306 registration.scope,307 normalizeURL('resources/scope/parent-reference-in-scope'),308 'Scope including parent-reference should be normalized.');309 service_worker_unregister_and_done(t, scope);310 });311 }, 'Scope including parent-reference');312 promise_test(function(t) {313 var script = 'resources/empty-worker.js';314 var scope = 'resources/../scope/parent-reference-in-scope';315 return promise_rejects(t,316 check_error_types ? 'SecurityError' : null,317 register_method(script, {scope: scope}),318 'Scope not under the script directory should be rejected.');319 }, 'Scope including parent-reference and not under the script directory');320 promise_test(function(t) {321 var script = 'resources////empty-worker.js';322 var scope = 'resources/scope/consecutive-slashes-in-script-url';323 return promise_rejects(t,324 check_error_types ? 'SecurityError' : null,325 register_method(script, {scope: scope}),326 'Consecutive slashes in the script url should not be unified.');327 }, 'Script URL including consecutive slashes');328 promise_test(function(t) {329 var script = 'resources/empty-worker.js';330 var scope = 'resources/scope////consecutive-slashes-in-scope';331 return register_method(script, {scope: scope})332 .then(function(registration) {333 // Although consecutive slashes in the scope are not unified, the334 // scope is under the script directory and registration should335 // succeed.336 assert_equals(337 registration.scope,338 normalizeURL(scope),339 'Should successfully be registered.');340 service_worker_unregister_and_done(t, scope);341 })342 }, 'Scope including consecutive slashes');343 promise_test(function(t) {344 var script = 'filesystem:' + normalizeURL('resources/empty-worker.js');345 var scope = 'resources/scope/filesystem-script-url';346 return promise_rejects(t,347 check_error_types ? 'SecurityError' : null,348 register_method(script, {scope: scope}),349 'Registering a script which has same-origin filesystem: URL should ' +350 'fail with SecurityError.');351 }, 'Script URL is same-origin filesystem: URL');352 promise_test(function(t) {353 var script = 'resources/empty-worker.js';354 var scope = 'filesystem:' + normalizeURL('resources/scope/filesystem-scope-url');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1if (self.importScripts) {2 importScripts('/resources/testharness.js');3}4promise_test(function(t) {5 return service_worker_unregister_and_done(t);6}, 'Test service_worker_unregister_and_done method of wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1self.importScripts('/resources/testharness.js');2importScripts('resources/test-helpers.js');3importScripts('resources/test-helpers-sub.js');4importScripts('resources/sw-testharness-helpers.js');5promise_test(function(t) {6 return service_worker_unregister_and_done(t);7 }, 'Unregister the service worker.');

Full Screen

Using AI Code Generation

copy

Full Screen

1importScripts('/resources/testharness.js');2importScripts('/resources/testharnessreport.js');3test(function() {4 assert_true(self.registration.unregister());5}, 'Unregistering a ServiceWorkerRegistration');6done();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful