OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <!-- |
| 4 Copyright 2015 The Chromium Authors. All rights reserved. |
| 5 Use of this source code is governed by a BSD-style license that can be |
| 6 found in the LICENSE file. |
| 7 --> |
| 8 <head> |
| 9 <title>IDB Test that we can store and retrieve an empty blob</title> |
| 10 <script src="common.js"></script> |
| 11 <script> |
| 12 |
| 13 // Constants. |
| 14 var store_name = 'empty_blob'; |
| 15 var blob_key = 'blob_key'; |
| 16 var file_key = 'file_key'; |
| 17 |
| 18 // Shared variables. |
| 19 var db; |
| 20 var emptyFileInput; |
| 21 |
| 22 function test() { |
| 23 indexedDBTest(prepareDatabase, writeBlob); |
| 24 } |
| 25 |
| 26 function prepareDatabase() { |
| 27 db = event.target.result; |
| 28 db.createObjectStore(store_name); |
| 29 } |
| 30 |
| 31 function writeBlob() { |
| 32 debug("Writing blob."); |
| 33 |
| 34 put_blob = new Blob(); |
| 35 |
| 36 var put_tx = db.transaction(store_name, 'readwrite'); |
| 37 put_tx.onabort = unexpectedAbortCallback; |
| 38 var put_request = put_tx.objectStore(store_name).put(put_blob, blob_key); |
| 39 put_request.onerror = unexpectedErrorCallback; |
| 40 put_tx.oncomplete = function () { |
| 41 var get_tx = db.transaction(store_name); |
| 42 |
| 43 var get_request1 = get_tx.objectStore(store_name).get(blob_key); |
| 44 get_request1.onerror = unexpectedErrorCallback; |
| 45 get_request1.onsuccess = function(evt) { |
| 46 get_blob1 = evt.target.result; |
| 47 resultType = typeof get_blob1; |
| 48 shouldBe('resultType', '"object"'); |
| 49 shouldBe('get_blob1.size', 'put_blob.size'); |
| 50 }; |
| 51 |
| 52 var get_request2 = get_tx.objectStore(store_name).get(blob_key); |
| 53 get_request2.onerror = unexpectedErrorCallback; |
| 54 get_request2.onsuccess = function(evt) { |
| 55 get_blob2 = evt.target.result; |
| 56 resultType = typeof get_blob2; |
| 57 shouldBe('resultType', '"object"'); |
| 58 shouldBe('get_blob2.size', 'put_blob.size'); |
| 59 }; |
| 60 |
| 61 get_tx.onabort = unexpectedAbortCallback; |
| 62 get_tx.oncomplete = writeFile; |
| 63 }; |
| 64 } |
| 65 |
| 66 function writeFile() { |
| 67 put_file = new File([''], 'somefile', { |
| 68 type: 'application/x-special-snowflake', |
| 69 lastModified: new Date('1999-12-31T23:59:59Z') |
| 70 }); |
| 71 var put_tx = db.transaction(store_name, 'readwrite'); |
| 72 put_tx.objectStore(store_name).put(put_file, file_key); |
| 73 put_tx.onabort = unexpectedAbortCallback; |
| 74 put_tx.oncomplete = function() { |
| 75 var get_tx = db.transaction(store_name); |
| 76 get_tx.objectStore(store_name).get(file_key).onsuccess = function(e) { |
| 77 get_file = e.target.result; |
| 78 |
| 79 shouldBe('get_file.name', 'put_file.name'); |
| 80 shouldBe('get_file.size', 'put_file.size'); |
| 81 shouldBe('get_file.type', 'put_file.type'); |
| 82 shouldBe('get_file.lastModified', 'put_file.lastModified'); |
| 83 shouldBe('String(get_file.lastModifiedDate)', 'String(put_file.lastModifie
dDate)'); |
| 84 }; |
| 85 get_tx.onabort = unexpectedAbortCallback; |
| 86 get_tx.oncomplete = deleteFile; |
| 87 }; |
| 88 } |
| 89 |
| 90 function deleteFile() { |
| 91 var tx = db.transaction(store_name, 'readwrite'); |
| 92 tx.objectStore(store_name).delete(file_key); |
| 93 tx.onabort = unexpectedAbortCallback; |
| 94 tx.oncomplete = deleteBlob; |
| 95 } |
| 96 |
| 97 function deleteBlob() { |
| 98 var tx = db.transaction(store_name, 'readwrite'); |
| 99 tx.objectStore(store_name).delete(blob_key); |
| 100 tx.onabort = unexpectedAbortCallback; |
| 101 tx.oncomplete = done; |
| 102 } |
| 103 |
| 104 </script> |
| 105 </head> |
| 106 <body onLoad="test()"> |
| 107 <div id="status">Starting...</div> |
| 108 </body> |
| 109 </html> |
OLD | NEW |