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
11 importScripts('/resources/testharness.js');
14 var next_cache_index = 1;
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;
22 test.add_cleanup(function() {
23 self.caches.delete(cache_name);
26 return self.caches.delete(cache_name)
28 return self.caches.open(cache_name);
32 self.create_temporary_cache = create_temporary_cache;
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().
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)