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.
9 <title>IDB Test that we can store and retrieve an empty blob
</title>
10 <script src=
"common.js"></script>
14 var store_name
= 'empty_blob';
15 var blob_key
= 'blob_key';
16 var file_key
= 'file_key';
21 var testTimes
= false;
24 param
= location
.hash
.substring(1);
25 if (param
== 'ignoreTimes') {
28 indexedDBTest(prepareDatabase
, writeBlob
);
31 function prepareDatabase() {
32 db
= event
.target
.result
;
33 db
.createObjectStore(store_name
);
36 function writeBlob() {
37 debug("Writing blob.");
39 put_blob
= new Blob();
41 var put_tx
= db
.transaction(store_name
, 'readwrite');
42 put_tx
.onabort
= unexpectedAbortCallback
;
43 var put_request
= put_tx
.objectStore(store_name
).put(put_blob
, blob_key
);
44 put_request
.onerror
= unexpectedErrorCallback
;
45 put_tx
.oncomplete = function () {
46 var get_tx
= db
.transaction(store_name
);
48 var get_request1
= get_tx
.objectStore(store_name
).get(blob_key
);
49 get_request1
.onerror
= unexpectedErrorCallback
;
50 get_request1
.onsuccess = function(evt
) {
51 get_blob1
= evt
.target
.result
;
52 resultType
= typeof get_blob1
;
53 shouldBe('resultType', '"object"');
54 shouldBe('get_blob1.size', 'put_blob.size');
57 var get_request2
= get_tx
.objectStore(store_name
).get(blob_key
);
58 get_request2
.onerror
= unexpectedErrorCallback
;
59 get_request2
.onsuccess = function(evt
) {
60 get_blob2
= evt
.target
.result
;
61 resultType
= typeof get_blob2
;
62 shouldBe('resultType', '"object"');
63 shouldBe('get_blob2.size', 'put_blob.size');
66 get_tx
.onabort
= unexpectedAbortCallback
;
67 get_tx
.oncomplete
= writeFile
;
71 function writeFile() {
72 put_file
= new File([''], 'somefile', {
73 type
: 'application/x-special-snowflake',
74 lastModified
: new Date('1999-12-31T23:59:59Z')
76 var put_tx
= db
.transaction(store_name
, 'readwrite');
77 put_tx
.objectStore(store_name
).put(put_file
, file_key
);
78 put_tx
.onabort
= unexpectedAbortCallback
;
79 put_tx
.oncomplete = function() {
80 var get_tx
= db
.transaction(store_name
);
81 get_tx
.objectStore(store_name
).get(file_key
).onsuccess = function(e
) {
82 get_file
= e
.target
.result
;
84 shouldBe('get_file.name', 'put_file.name');
85 shouldBe('get_file.size', 'put_file.size');
86 shouldBe('get_file.type', 'put_file.type');
88 shouldBe('get_file.lastModified', 'put_file.lastModified');
89 shouldBe('String(get_file.lastModifiedDate)', 'String(put_file.lastModifiedDate)');
92 get_tx
.onabort
= unexpectedAbortCallback
;
93 get_tx
.oncomplete
= deleteFile
;
97 function deleteFile() {
98 var tx
= db
.transaction(store_name
, 'readwrite');
99 tx
.objectStore(store_name
).delete(file_key
);
100 tx
.onabort
= unexpectedAbortCallback
;
101 tx
.oncomplete
= deleteBlob
;
104 function deleteBlob() {
105 var tx
= db
.transaction(store_name
, 'readwrite');
106 tx
.objectStore(store_name
).delete(blob_key
);
107 tx
.onabort
= unexpectedAbortCallback
;
108 tx
.oncomplete
= done
;
113 <body onLoad=
"test()">
114 <div id=
"status">Starting...
</div>