tor-browser

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

registration-tests-scope.js (5053B)


      1 // Registration tests that mostly exercise the scope option.
      2 function registration_tests_scope(register_method) {
      3  promise_test(function(t) {
      4      var script = 'resources/empty-worker.js';
      5      var scope = 'resources/scope%2fencoded-slash-in-scope';
      6      return promise_rejects_js(t,
      7          TypeError,
      8          register_method(script, {scope: scope}),
      9          'URL-encoded slash in the scope should be rejected.');
     10    }, 'Scope including URL-encoded slash');
     11 
     12  promise_test(function(t) {
     13      var script = 'resources/empty-worker.js';
     14      var scope = 'resources/scope%5cencoded-slash-in-scope';
     15      return promise_rejects_js(t,
     16          TypeError,
     17          register_method(script, {scope: scope}),
     18          'URL-encoded backslash in the scope should be rejected.');
     19    }, 'Scope including URL-encoded backslash');
     20 
     21  promise_test(function(t) {
     22      var script = 'resources/empty-worker.js';
     23      var scope = 'data:text/html,';
     24      return promise_rejects_js(t,
     25          TypeError,
     26          register_method(script, {scope: scope}),
     27          'scope URL scheme is not "http" or "https"');
     28    }, 'Scope URL scheme is a data: URL');
     29 
     30  promise_test(function(t) {
     31      var script = 'resources/empty-worker.js';
     32      var scope = new URL('resources', location).href.replace('https:', 'ftp:');
     33      return promise_rejects_js(t,
     34          TypeError,
     35          register_method(script, {scope: scope}),
     36          'scope URL scheme is not "http" or "https"');
     37    }, 'Scope URL scheme is an ftp: URL');
     38 
     39  promise_test(function(t) {
     40      // URL-encoded full-width 'scope'.
     41      var name = '%ef%bd%93%ef%bd%83%ef%bd%8f%ef%bd%90%ef%bd%85';
     42      var script = 'resources/empty-worker.js';
     43      var scope = 'resources/' + name + '/escaped-multibyte-character-scope';
     44      return register_method(script, {scope: scope})
     45        .then(function(registration) {
     46            assert_equals(
     47              registration.scope,
     48              normalizeURL(scope),
     49              'URL-encoded multibyte characters should be available.');
     50            return registration.unregister();
     51          });
     52    }, 'Scope including URL-encoded multibyte characters');
     53 
     54  promise_test(function(t) {
     55      // Non-URL-encoded full-width "scope".
     56      var name = String.fromCodePoint(0xff53, 0xff43, 0xff4f, 0xff50, 0xff45);
     57      var script = 'resources/empty-worker.js';
     58      var scope = 'resources/' + name  + '/non-escaped-multibyte-character-scope';
     59      return register_method(script, {scope: scope})
     60        .then(function(registration) {
     61            assert_equals(
     62              registration.scope,
     63              normalizeURL(scope),
     64              'Non-URL-encoded multibyte characters should be available.');
     65            return registration.unregister();
     66          });
     67    }, 'Scope including non-escaped multibyte characters');
     68 
     69  promise_test(function(t) {
     70      var script = 'resources/empty-worker.js';
     71      var scope = 'resources/././scope/self-reference-in-scope';
     72      return register_method(script, {scope: scope})
     73        .then(function(registration) {
     74            assert_equals(
     75              registration.scope,
     76              normalizeURL('resources/scope/self-reference-in-scope'),
     77              'Scope including self-reference should be normalized.');
     78            return registration.unregister();
     79          });
     80    }, 'Scope including self-reference');
     81 
     82  promise_test(function(t) {
     83      var script = 'resources/empty-worker.js';
     84      var scope = 'resources/../resources/scope/parent-reference-in-scope';
     85      return register_method(script, {scope: scope})
     86        .then(function(registration) {
     87            assert_equals(
     88              registration.scope,
     89              normalizeURL('resources/scope/parent-reference-in-scope'),
     90              'Scope including parent-reference should be normalized.');
     91            return registration.unregister();
     92          });
     93    }, 'Scope including parent-reference');
     94 
     95  promise_test(function(t) {
     96      var script = 'resources/empty-worker.js';
     97      var scope = 'resources/scope////consecutive-slashes-in-scope';
     98      return register_method(script, {scope: scope})
     99        .then(function(registration) {
    100            // Although consecutive slashes in the scope are not unified, the
    101            // scope is under the script directory and registration should
    102            // succeed.
    103            assert_equals(
    104              registration.scope,
    105              normalizeURL(scope),
    106              'Should successfully be registered.');
    107            return registration.unregister();
    108          })
    109    }, 'Scope including consecutive slashes');
    110 
    111  promise_test(function(t) {
    112      var script = 'resources/empty-worker.js';
    113      var scope = 'filesystem:' + normalizeURL('resources/scope/filesystem-scope-url');
    114      return promise_rejects_js(t,
    115          TypeError,
    116          register_method(script, {scope: scope}),
    117          'Registering with the scope that has same-origin filesystem: URL ' +
    118              'should fail with TypeError.');
    119    }, 'Scope URL is same-origin filesystem: URL');
    120 }