Index: LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js b/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
index 3d45c2270cce1988908fb58366f3f7d07a2635aa..646e08d9eae93f4a7874e1397046d42fbe4535b9 100644 |
--- a/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
+++ b/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
@@ -102,3 +102,25 @@ function assert_promise_throws(promise, code, description) { |
assert_throws(code, function() { throw e; }, description); |
}); |
} |
+ |
+(function() { |
+ var next_cache_index = 1; |
+ |
+ // Returns a promise that resolves to a newly created Cache object. The |
+ // returned Cache will be destroyed when |test| completes. |
+ function create_temporary_cache(test, base_name) { |
jsbell
2014/08/20 18:18:08
This is great!
asanka
2014/08/20 21:24:58
Thanks!
|
+ var uniquifier = base_name || String(++next_cache_index); |
+ var cache_name = self.location.pathname + '/' + uniquifier; |
+ |
+ test.add_cleanup(function() { |
+ self.caches.delete(cache_name); |
+ }); |
+ |
+ return self.caches.delete(cache_name) |
+ .then(function() { |
+ return self.caches.create(cache_name); |
+ }); |
+ } |
+ |
+ self.create_temporary_cache = create_temporary_cache; |
+})(); |