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 var trans = db.transaction(store_name, 'readwrite'); | |
jsbell
2015/03/03 22:38:07
It's probably personal preference, but WDYT about
cmumford
2015/03/03 23:01:35
I think I see what you're talking about. Let me kn
| |
35 trans.onabort = unexpectedAbortCallback; | |
36 trans.oncomplete = function () { | |
37 var trans = db.transaction(store_name); | |
38 trans.onabort = unexpectedAbortCallback; | |
39 trans.oncomplete = writeFile; | |
40 | |
41 var request = trans.objectStore(store_name).get(blob_key); | |
42 request.onerror = unexpectedErrorCallback; | |
43 request.onsuccess = function(evt) { | |
44 get_blob = evt.target.result; | |
45 resultType = typeof get_blob; | |
46 shouldBe('resultType', '"object"'); | |
47 shouldBe('get_blob.size', '0'); | |
48 }; | |
49 }; | |
50 | |
51 put_blob = new Blob(); | |
52 var request = trans.objectStore(store_name).put(put_blob, blob_key); | |
53 request.onerror = unexpectedErrorCallback; | |
54 } | |
55 | |
56 function writeFile() { | |
57 file = new File([''], 'somefile', { | |
58 type: 'application/x-special-snowflake', | |
59 lastModified: new Date('1999-12-31T23:59:59Z') | |
jsbell
2015/03/03 22:38:07
Party like it's...
cmumford
2015/03/03 23:01:35
1999
| |
60 }); | |
61 var put_tx = db.transaction(store_name, 'readwrite'); | |
62 put_tx.objectStore(store_name).put(file, file_key); | |
63 put_tx.onabort = unexpectedAbortCallback; | |
64 put_tx.oncomplete = function() { | |
65 var get_tx = db.transaction(store_name); | |
66 get_tx.onabort = unexpectedAbortCallback; | |
67 get_tx.oncomplete = deleteFile; | |
68 get_tx.objectStore(store_name).get(file_key).onsuccess = function(e) { | |
69 result = e.target.result; | |
jsbell
2015/03/03 22:38:07
Just a consistency nit: in the blob case you have
cmumford
2015/03/03 23:01:35
Done.
| |
70 | |
71 shouldBe('result.name', 'file.name'); | |
72 shouldBe('result.size', 'file.size'); | |
73 shouldBe('result.type', 'file.type'); | |
74 shouldBe('result.lastModified', 'file.lastModified'); | |
75 shouldBe('String(result.lastModifiedDate)', 'String(file.lastModifiedDate) '); | |
76 }; | |
77 }; | |
78 } | |
79 | |
80 function deleteFile() { | |
jsbell
2015/03/03 22:38:07
Should we have a case for deleting blob as well?
cmumford
2015/03/03 23:01:35
Done.
| |
81 var put_tx = db.transaction(store_name, 'readwrite'); | |
82 put_tx.objectStore(store_name).delete(file_key); | |
83 put_tx.onabort = unexpectedAbortCallback; | |
84 put_tx.oncomplete = function() { | |
jsbell
2015/03/03 22:38:07
could just say: oncomplete = done;
cmumford
2015/03/03 23:01:35
Done.
| |
85 done(); | |
86 }; | |
87 } | |
88 | |
89 </script> | |
90 </head> | |
91 <body onLoad="test()"> | |
92 <input type="file" id="emptyFileInput"></input> | |
93 <div id="status">Starting...</div> | |
94 </body> | |
95 </html> | |
OLD | NEW |