tor-browser

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

registration-tests-script.js (5282B)


      1 // Registration tests that mostly exercise the service worker script contents or
      2 // response.
      3 function registration_tests_script(register_method, type) {
      4  promise_test(function(t) {
      5      var script = 'resources/invalid-chunked-encoding.py';
      6      var scope = 'resources/scope/invalid-chunked-encoding/';
      7      return promise_rejects_js(t,
      8          TypeError,
      9          register_method(script, {scope: scope}),
     10          'Registration of invalid chunked encoding script should fail.');
     11    }, 'Registering invalid chunked encoding script');
     12 
     13  promise_test(function(t) {
     14      var script = 'resources/invalid-chunked-encoding-with-flush.py';
     15      var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';
     16      return promise_rejects_js(t,
     17          TypeError,
     18          register_method(script, {scope: scope}),
     19          'Registration of invalid chunked encoding script should fail.');
     20    }, 'Registering invalid chunked encoding script with flush');
     21 
     22  promise_test(function(t) {
     23      var script = 'resources/malformed-worker.py?parse-error';
     24      var scope = 'resources/scope/parse-error';
     25      return promise_rejects_js(t,
     26          TypeError,
     27          register_method(script, {scope: scope}),
     28          'Registration of script including parse error should fail.');
     29    }, 'Registering script including parse error');
     30 
     31  promise_test(function(t) {
     32      var script = 'resources/malformed-worker.py?undefined-error';
     33      var scope = `resources/scope/undefined-error/${type}`;
     34      return promise_rejects_js(t,
     35          TypeError,
     36          register_method(script, {scope: scope}),
     37          'Registration of script including undefined error should fail.');
     38    }, `Registering script including undefined error: ${type}`);
     39 
     40  promise_test(function(t) {
     41      var script = 'resources/malformed-worker.py?uncaught-exception';
     42      var scope = `resources/scope/uncaught-exception/${type}`;
     43      return promise_rejects_js(t,
     44          TypeError,
     45          register_method(script, {scope: scope}),
     46          'Registration of script including uncaught exception should fail.');
     47    }, `Registering script including uncaught exception: ${type}`);
     48 
     49  if (type === 'classic') {
     50    promise_test(function(t) {
     51        var script = 'resources/malformed-worker.py?import-malformed-script';
     52        var scope = 'resources/scope/import-malformed-script';
     53        return promise_rejects_js(t,
     54            TypeError,
     55            register_method(script, {scope: scope}),
     56            'Registration of script importing malformed script should fail.');
     57      }, 'Registering script importing malformed script');
     58  }
     59 
     60  if (type === 'module') {
     61    promise_test(function(t) {
     62        var script = 'resources/malformed-worker.py?top-level-await';
     63        var scope = 'resources/scope/top-level-await';
     64        return promise_rejects_js(t,
     65            TypeError,
     66            register_method(script, {scope: scope}),
     67            'Registration of script with top-level await should fail.');
     68      }, 'Registering script with top-level await');
     69 
     70    promise_test(function(t) {
     71        var script = 'resources/malformed-worker.py?instantiation-error';
     72        var scope = 'resources/scope/instantiation-error';
     73        return promise_rejects_js(t,
     74            TypeError,
     75            register_method(script, {scope: scope}),
     76            'Registration of script with module instantiation error should fail.');
     77      }, 'Registering script with module instantiation error');
     78 
     79    promise_test(function(t) {
     80        var script = 'resources/malformed-worker.py?instantiation-error-and-top-level-await';
     81        var scope = 'resources/scope/instantiation-error-and-top-level-await';
     82        return promise_rejects_js(t,
     83            TypeError,
     84            register_method(script, {scope: scope}),
     85            'Registration of script with module instantiation error and top-level await should fail.');
     86      }, 'Registering script with module instantiation error and top-level await');
     87  }
     88 
     89  promise_test(function(t) {
     90      var script = 'resources/no-such-worker.js';
     91      var scope = 'resources/scope/no-such-worker';
     92      return promise_rejects_js(t,
     93          TypeError,
     94          register_method(script, {scope: scope}),
     95          'Registration of non-existent script should fail.');
     96    }, 'Registering non-existent script');
     97 
     98  if (type === 'classic') {
     99    promise_test(function(t) {
    100        var script = 'resources/malformed-worker.py?import-no-such-script';
    101        var scope = 'resources/scope/import-no-such-script';
    102        return promise_rejects_js(t,
    103            TypeError,
    104            register_method(script, {scope: scope}),
    105            'Registration of script importing non-existent script should fail.');
    106      }, 'Registering script importing non-existent script');
    107  }
    108 
    109  promise_test(function(t) {
    110      var script = 'resources/malformed-worker.py?caught-exception';
    111      var scope = 'resources/scope/caught-exception';
    112      return register_method(script, {scope: scope})
    113        .then(function(registration) {
    114            assert_true(
    115              registration instanceof ServiceWorkerRegistration,
    116              'Successfully registered.');
    117            return registration.unregister();
    118          });
    119    }, 'Registering script including caught exception');
    120 
    121 }