| Index: content/test/data/service_worker/fetch_event_response_via_cache.js
|
| diff --git a/content/test/data/service_worker/fetch_event_response_via_cache.js b/content/test/data/service_worker/fetch_event_response_via_cache.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4fd03db73db61b856b703dddd006eb3ab70b9095
|
| --- /dev/null
|
| +++ b/content/test/data/service_worker/fetch_event_response_via_cache.js
|
| @@ -0,0 +1,28 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +this.onfetch = function(event) {
|
| + var CACHE_NAME = 'cache_name';
|
| + var cache = undefined;
|
| + var url = event.request.url;
|
| + event.respondWith(
|
| + caches.open(CACHE_NAME)
|
| + .then(function(c) {
|
| + cache = c;
|
| + return cache.match(url);
|
| + })
|
| + .then(function(response) {
|
| + if (response)
|
| + return response;
|
| + var cloned_response = undefined;
|
| + return fetch(url)
|
| + .then(function(res) {
|
| + cloned_response = res.clone();
|
| + return cache.put(url, res);
|
| + })
|
| + .then(function() {
|
| + return cloned_response;
|
| + });
|
| + }));
|
| + };
|
|
|