diff options
Diffstat (limited to 'dom/workers/test/serviceworkers/file_blob_response_worker.js')
-rw-r--r-- | dom/workers/test/serviceworkers/file_blob_response_worker.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/dom/workers/test/serviceworkers/file_blob_response_worker.js b/dom/workers/test/serviceworkers/file_blob_response_worker.js new file mode 100644 index 000000000..4b4379d0b --- /dev/null +++ b/dom/workers/test/serviceworkers/file_blob_response_worker.js @@ -0,0 +1,38 @@ +function makeFileBlob(obj) { + return new Promise(function(resolve, reject) { + var request = indexedDB.open('file_blob_response_worker', 1); + request.onerror = reject; + request.onupgradeneeded = function(evt) { + var db = evt.target.result; + db.onerror = reject; + + var objectStore = db.createObjectStore('test', { autoIncrement: true }); + var index = objectStore.createIndex('test', 'index'); + }; + + request.onsuccess = function(evt) { + var db = evt.target.result; + db.onerror = reject; + + var blob = new Blob([JSON.stringify(obj)], + { type: 'application/json' }); + var data = { blob: blob, index: 5 }; + + objectStore = db.transaction('test', 'readwrite').objectStore('test'); + objectStore.add(data).onsuccess = function(evt) { + var key = evt.target.result; + objectStore = db.transaction('test').objectStore('test'); + objectStore.get(key).onsuccess = function(evt) { + resolve(evt.target.result.blob); + }; + }; + }; + }); +} + +self.addEventListener('fetch', function(evt) { + var result = { value: 'success' }; + evt.respondWith(makeFileBlob(result).then(function(blob) { + return new Response(blob) + })); +}); |