OLD | NEW |
1 /* | 1 /* |
2 * worker-test-harness should be considered a temporary polyfill around | 2 * worker-test-harness should be considered a temporary polyfill around |
3 * testharness.js for supporting Service Worker based tests. It should not be | 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. | 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 | 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 | 6 * update upstream testharness.js. Once the upstreaming is complete, tests that |
7 * reference worker-test-harness should be updated to directly import | 7 * reference worker-test-harness should be updated to directly import |
8 * testharness.js. | 8 * testharness.js. |
9 */ | 9 */ |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 var message = { | 65 var message = { |
66 type: 'complete', | 66 type: 'complete', |
67 tests: results.tests, | 67 tests: results.tests, |
68 status: results.status | 68 status: results.status |
69 }; | 69 }; |
70 port.postMessage(message); | 70 port.postMessage(message); |
71 }); | 71 }); |
72 } | 72 } |
73 }); | 73 }); |
74 })(); | 74 })(); |
| 75 |
| 76 (function() { |
| 77 var next_cache_index = 1; |
| 78 |
| 79 // Returns a promise that resolves to a newly created Cache object. The |
| 80 // returned Cache will be destroyed when |test| completes. |
| 81 function create_temporary_cache(test) { |
| 82 var uniquifier = String(++next_cache_index); |
| 83 var cache_name = self.location.pathname + '/' + uniquifier; |
| 84 |
| 85 test.add_cleanup(function() { |
| 86 self.caches.delete(cache_name); |
| 87 }); |
| 88 |
| 89 return self.caches.delete(cache_name) |
| 90 .then(function() { |
| 91 return self.caches.open(cache_name); |
| 92 }); |
| 93 } |
| 94 |
| 95 self.create_temporary_cache = create_temporary_cache; |
| 96 })(); |
| 97 |
| 98 // Runs |test_function| with a temporary unique Cache passed in as the only |
| 99 // argument. The function is run as a part of Promise chain owned by |
| 100 // promise_test(). As such, it is expected to behave in a manner identical (with |
| 101 // the exception of the argument) to a function passed into promise_test(). |
| 102 // |
| 103 // E.g.: |
| 104 // cache_test(function(cache) { |
| 105 // // Do something with |cache|, which is a Cache object. |
| 106 // }, "Some Cache test"); |
| 107 function cache_test(test_function, description) { |
| 108 promise_test(function(test) { |
| 109 return create_temporary_cache(test) |
| 110 .then(test_function); |
| 111 }, description); |
| 112 } |
OLD | NEW |