tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

registration-tests-script-url.js (3565B)


      1 // Registration tests that mostly exercise the scriptURL parameter.
      2 function registration_tests_script_url(register_method) {
      3  promise_test(function(t) {
      4        var script = 'resources%2fempty-worker.js';
      5        var scope = 'resources/scope/encoded-slash-in-script-url';
      6        return promise_rejects_js(t,
      7            TypeError,
      8            register_method(script, {scope: scope}),
      9            'URL-encoded slash in the script URL should be rejected.');
     10      }, 'Script URL including URL-encoded slash');
     11 
     12  promise_test(function(t) {
     13      var script = 'resources%2Fempty-worker.js';
     14      var scope = 'resources/scope/encoded-slash-in-script-url';
     15      return promise_rejects_js(t,
     16          TypeError,
     17          register_method(script, {scope: scope}),
     18          'URL-encoded slash in the script URL should be rejected.');
     19    }, 'Script URL including uppercase URL-encoded slash');
     20 
     21  promise_test(function(t) {
     22      var script = 'resources%5cempty-worker.js';
     23      var scope = 'resources/scope/encoded-slash-in-script-url';
     24      return promise_rejects_js(t,
     25          TypeError,
     26          register_method(script, {scope: scope}),
     27          'URL-encoded backslash in the script URL should be rejected.');
     28    }, 'Script URL including URL-encoded backslash');
     29 
     30  promise_test(function(t) {
     31      var script = 'resources%5Cempty-worker.js';
     32      var scope = 'resources/scope/encoded-slash-in-script-url';
     33      return promise_rejects_js(t,
     34          TypeError,
     35          register_method(script, {scope: scope}),
     36          'URL-encoded backslash in the script URL should be rejected.');
     37    }, 'Script URL including uppercase URL-encoded backslash');
     38 
     39  promise_test(function(t) {
     40      var script = 'data:application/javascript,';
     41      var scope = 'resources/scope/data-url-in-script-url';
     42      return promise_rejects_js(t,
     43          TypeError,
     44          register_method(script, {scope: scope}),
     45          'Data URLs should not be registered as service workers.');
     46    }, 'Script URL is a data URL');
     47 
     48  promise_test(function(t) {
     49      var script = 'data:application/javascript,';
     50      var scope = new URL('resources/scope/data-url-in-script-url', location);
     51      return promise_rejects_js(t,
     52          TypeError,
     53          register_method(script, {scope: scope}),
     54          'Data URLs should not be registered as service workers.');
     55    }, 'Script URL is a data URL and scope URL is not relative');
     56 
     57  promise_test(function(t) {
     58      var script = 'resources/././empty-worker.js';
     59      var scope = 'resources/scope/parent-reference-in-script-url';
     60      return register_method(script, {scope: scope})
     61        .then(function(registration) {
     62            assert_equals(
     63              get_newest_worker(registration).scriptURL,
     64              normalizeURL('resources/empty-worker.js'),
     65              'Script URL including self-reference should be normalized.');
     66            return registration.unregister();
     67          });
     68    }, 'Script URL including self-reference');
     69 
     70  promise_test(function(t) {
     71      var script = 'resources/../resources/empty-worker.js';
     72      var scope = 'resources/scope/parent-reference-in-script-url';
     73      return register_method(script, {scope: scope})
     74        .then(function(registration) {
     75            assert_equals(
     76              get_newest_worker(registration).scriptURL,
     77              normalizeURL('resources/empty-worker.js'),
     78              'Script URL including parent-reference should be normalized.');
     79            return registration.unregister();
     80          });
     81    }, 'Script URL including parent-reference');
     82 }