tor-browser

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

worker-testharness.js (1768B)


      1 /*
      2 * worker-test-harness should be considered a temporary polyfill around
      3 * testharness.js for supporting Service Worker based tests. It should not be
      4 * necessary once the test harness is able to drive worker based tests natively.
      5 * See https://github.com/w3c/testharness.js/pull/82 for status of effort to
      6 * update upstream testharness.js. Once the upstreaming is complete, tests that
      7 * reference worker-test-harness should be updated to directly import
      8 * testharness.js.
      9 */
     10 
     11 importScripts('/resources/testharness.js');
     12 
     13 (function() {
     14  var next_cache_index = 1;
     15 
     16  // Returns a promise that resolves to a newly created Cache object. The
     17  // returned Cache will be destroyed when |test| completes.
     18  function create_temporary_cache(test) {
     19    var uniquifier = String(++next_cache_index);
     20    var cache_name = self.location.pathname + '/' + uniquifier;
     21 
     22    test.add_cleanup(function() {
     23        return self.caches.delete(cache_name);
     24      });
     25 
     26    return self.caches.delete(cache_name)
     27      .then(function() {
     28          return self.caches.open(cache_name);
     29        });
     30  }
     31 
     32  self.create_temporary_cache = create_temporary_cache;
     33 })();
     34 
     35 // Runs |test_function| with a temporary unique Cache passed in as the only
     36 // argument. The function is run as a part of Promise chain owned by
     37 // promise_test(). As such, it is expected to behave in a manner identical (with
     38 // the exception of the argument) to a function passed into promise_test().
     39 //
     40 // E.g.:
     41 //    cache_test(function(cache) {
     42 //      // Do something with |cache|, which is a Cache object.
     43 //    }, "Some Cache test");
     44 function cache_test(test_function, description) {
     45  promise_test(function(test) {
     46      return create_temporary_cache(test)
     47        .then(test_function);
     48    }, description);
     49 }